@promptbook/cli 0.114.0-50 → 0.114.0-51

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 (44) hide show
  1. package/apps/agents-server/README.md +2 -0
  2. package/apps/agents-server/src/app/AddAgentButton.tsx +4 -1
  3. package/apps/agents-server/src/app/dashboard/page.tsx +1 -0
  4. package/apps/agents-server/src/app/page.tsx +6 -7
  5. package/apps/agents-server/src/components/Header/Header.tsx +1 -0
  6. package/apps/agents-server/src/components/Header/useHeaderAgentMenus.tsx +5 -7
  7. package/apps/agents-server/src/components/Homepage/AgentsList.tsx +4 -1
  8. package/apps/agents-server/src/components/Homepage/AgentsListListView.tsx +4 -1
  9. package/apps/agents-server/src/components/Homepage/HomepagePrimarySections.tsx +4 -0
  10. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/ManGoNewAgentWizard.tsx +15 -7
  11. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/README.md +36 -0
  12. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/EmailTestRun.tsx +25 -53
  13. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/TestChat.tsx +23 -6
  14. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/BookStep.tsx +16 -36
  15. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/DoneStep.tsx +16 -55
  16. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/KnowledgeStep.tsx +19 -48
  17. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/TestStep.tsx +23 -88
  18. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/components/steps/ZadaniStep.tsx +11 -2
  19. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/agentEvalService.ts +9 -6
  20. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/agentTestService.ts +11 -7
  21. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/bookService.ts +15 -8
  22. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/postManGoOnboardingJson.ts +2 -0
  23. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/services/uploadService.ts +2 -2
  24. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/OnboardingProvider.tsx +24 -97
  25. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/createInitialOnboardingState.ts +28 -0
  26. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/createOnboardingActions.ts +262 -0
  27. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/createOnboardingSession.ts +168 -0
  28. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/retireLegacyOnboardingSnapshot.ts +14 -0
  29. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/state/runOnboardingOperation.ts +29 -0
  30. package/apps/agents-server/src/components/NewAgentDialog/ManGoNewAgentWizard/types.ts +27 -2
  31. package/apps/agents-server/src/components/NewAgentDialog/useNewAgentDialog.tsx +178 -58
  32. package/apps/agents-server/tests/e2e/e2eEnvironment.cjs +3 -0
  33. package/esm/index.es.js +36 -11
  34. package/esm/index.es.js.map +1 -1
  35. package/esm/scripts/verify-prompts/verify-prompts.d.ts +5 -0
  36. package/esm/src/version.d.ts +1 -1
  37. package/package.json +1 -1
  38. package/src/other/templates/getTemplatesPipelineCollection.ts +1133 -1530
  39. package/src/version.ts +2 -2
  40. package/src/versions.txt +1 -0
  41. package/umd/index.umd.js +36 -11
  42. package/umd/index.umd.js.map +1 -1
  43. package/umd/scripts/verify-prompts/verify-prompts.d.ts +5 -0
  44. package/umd/src/version.d.ts +1 -1
@@ -1,11 +1,10 @@
1
1
  'use client';
2
2
 
3
3
  import type { ReactNode } from 'react';
4
- import { useEffect, useRef } from 'react';
5
- import { useState } from 'react';
4
+ import { useEffect } from 'react';
6
5
 
7
6
  import type { AgentVisibility } from '../../../../../utils/agentVisibility';
8
- import { ONBOARDING_ENTRY_PATH, ONBOARDING_STEPS } from '../../config/steps';
7
+ import { ONBOARDING_STEPS } from '../../config/steps';
9
8
  import { useManGoOnboardingNavigation } from '../../ManGoOnboardingNavigation';
10
9
  import { createManGoAgentSource } from '../../services/createManGoAgentSource';
11
10
  import { useOnboarding } from '../../state/OnboardingProvider';
@@ -53,6 +52,7 @@ type DoneStepProps = {
53
52
  readonly onOpenCreatedAgent: (targetPath: string) => void;
54
53
  };
55
54
 
55
+ /** Displays one completion summary value. */
56
56
  function SummaryRow({ label, value }: { readonly label: string; readonly value: ReactNode }) {
57
57
  return (
58
58
  <div className="flex items-center justify-between gap-4 border-b border-zinc-100 py-2.5 last:border-b-0">
@@ -62,65 +62,22 @@ function SummaryRow({ label, value }: { readonly label: string; readonly value:
62
62
  );
63
63
  }
64
64
 
65
+ /** Saves and displays the identity retained by this creation session alone. */
65
66
  export function DoneStep(props: DoneStepProps) {
66
67
  const { defaultVisibility, onCreate, onOpenCreatedAgent } = props;
67
68
  const { navigateToPath } = useManGoOnboardingNavigation();
68
- const { state, isHydrated, update, reset } = useOnboarding();
69
- const savedRef = useRef(false);
70
- const [isCreatingAgent, setIsCreatingAgent] = useState(false);
71
- const [creationError, setCreationError] = useState<string | null>(null);
72
- const [creationAttempt, setCreationAttempt] = useState(0);
69
+ const { state, actions, reset } = useOnboarding();
70
+ const { isCreatingAgent, creationError } = state;
73
71
 
74
72
  const knowledgeCount = state.knowledge.length;
75
73
  const isTested = state.testMessages.some((message) => message.role === 'user');
76
74
  const isBookAvailable = state.bookSource.trim().length > 0;
77
75
  const isCreated = Boolean(state.savedAgentId && state.savedAgentTargetPath);
78
76
 
79
- // Create the real agent once. Guarded by both a ref (single run) and the session's
80
- // saved permanent id (don't re-create on revisit).
77
+ // Duplicate submission protection belongs to the session, including effect replay/remounts.
81
78
  useEffect(() => {
82
- if (!isHydrated || savedRef.current) {
83
- return;
84
- }
85
- savedRef.current = true;
86
-
87
- if (state.agentName.trim().length === 0 && state.bookSource.trim().length === 0) {
88
- return;
89
- }
90
-
91
- if (state.savedAgentId && state.savedAgentTargetPath) {
92
- return;
93
- }
94
-
95
- const agentSource = createManGoAgentSource(state);
96
- const readyKnowledgeCount = state.knowledge.filter((item) => item.status === 'ready').length;
97
-
98
- setIsCreatingAgent(true);
99
- setCreationError(null);
100
- void onCreate({
101
- agentSource,
102
- visibility: defaultVisibility,
103
- knowledgeCount: readyKnowledgeCount,
104
- })
105
- .then((agent) => {
106
- update({
107
- savedAgentId: agent.permanentId,
108
- savedAgentTargetPath: agent.targetPath,
109
- });
110
- })
111
- .catch((error) => {
112
- savedRef.current = false;
113
- setCreationError(error instanceof Error ? error.message : 'Vytvoření agenta selhalo.');
114
- })
115
- .finally(() => {
116
- setIsCreatingAgent(false);
117
- });
118
- }, [creationAttempt, defaultVisibility, isHydrated, onCreate, state, update]);
119
-
120
- function startOver() {
121
- reset();
122
- navigateToPath(ONBOARDING_ENTRY_PATH);
123
- }
79
+ void actions.createAgent(onCreate, defaultVisibility);
80
+ }, [actions, defaultVisibility, onCreate]);
124
81
 
125
82
  return (
126
83
  <div className="mx-auto max-w-xl text-center">
@@ -192,7 +149,7 @@ export function DoneStep(props: DoneStepProps) {
192
149
  disabled={(!state.savedAgentTargetPath && !creationError) || isCreatingAgent}
193
150
  onClick={() => {
194
151
  if (creationError) {
195
- setCreationAttempt((previousAttempt) => previousAttempt + 1);
152
+ void actions.createAgent(onCreate, defaultVisibility, true);
196
153
  return;
197
154
  }
198
155
 
@@ -203,10 +160,14 @@ export function DoneStep(props: DoneStepProps) {
203
160
  >
204
161
  {creationError ? 'Zkusit uložit znovu' : 'Přejít na chat agenta'}
205
162
  </Button>
206
- <Button variant="outline" disabled={isCreatingAgent} onClick={() => navigateToPath(ONBOARDING_STEPS[0].path)}>
163
+ <Button
164
+ variant="outline"
165
+ disabled={isCreatingAgent}
166
+ onClick={() => navigateToPath(ONBOARDING_STEPS[0].path)}
167
+ >
207
168
  Upravit agenta
208
169
  </Button>
209
- <Button variant="ghost" disabled={isCreatingAgent} onClick={startOver}>
170
+ <Button variant="ghost" disabled={isCreatingAgent} onClick={reset}>
210
171
  Začít nový onboarding
211
172
  </Button>
212
173
  </div>
@@ -1,13 +1,9 @@
1
1
  'use client';
2
2
 
3
- import { useState } from 'react';
4
-
5
3
  import { ONBOARDING_STEPS } from '../../config/steps';
6
4
  import { createId } from '../../lib/id';
7
- import { uploadKnowledgeFile } from '../../services/uploadService';
8
5
  import { useManGoOnboardingNavigation } from '../../ManGoOnboardingNavigation';
9
6
  import { useOnboarding } from '../../state/OnboardingProvider';
10
- import type { KnowledgeFileItem } from '../../types';
11
7
  import { cn } from '../../lib/cn';
12
8
  import { DropZone } from '../DropZone';
13
9
  import { KnowledgeList } from '../KnowledgeList';
@@ -15,8 +11,10 @@ import { StepCard, StepFooter, StepHeader } from '../StepFrame';
15
11
  import { Button } from '../ui/Button';
16
12
  import { CONTROL, CONTROL_ERROR } from '../ui/Field';
17
13
 
14
+ /** Maximum size accepted by the knowledge uploader. */
18
15
  const MAX_FILE_SIZE_BYTES = 25 * 1024 * 1024;
19
16
 
17
+ /** Normalizes one deliberately supplied URL. */
20
18
  function normalizeUrl(raw: string): string | null {
21
19
  const trimmed = raw.trim();
22
20
  if (!trimmed) {
@@ -30,63 +28,32 @@ function normalizeUrl(raw: string): string | null {
30
28
  }
31
29
  }
32
30
 
31
+ /** Collects knowledge associations belonging only to the active session. */
33
32
  export function KnowledgeStep() {
34
33
  const { navigateToPath } = useManGoOnboardingNavigation();
35
- const { state, update } = useOnboarding();
36
- const [urlInput, setUrlInput] = useState('');
37
- const [urlError, setUrlError] = useState<string | null>(null);
38
-
39
- function uploadOne(file: File) {
40
- const id = createId();
41
- const item: KnowledgeFileItem = {
42
- kind: 'file',
43
- id,
44
- name: file.name,
45
- size: file.size,
46
- publicUrl: '',
47
- objectKey: '',
48
- status: 'uploading',
49
- };
50
- update((prev) => ({ knowledge: [...prev.knowledge, item] }));
51
-
52
- uploadKnowledgeFile(file)
53
- .then(({ publicUrl, objectKey }) => {
54
- update((prev) => ({
55
- knowledge: prev.knowledge.map((entry) =>
56
- entry.id === id ? { ...entry, publicUrl, objectKey, status: 'ready' } : entry,
57
- ),
58
- }));
59
- })
60
- .catch(() => {
61
- update((prev) => ({
62
- knowledge: prev.knowledge.map((entry) =>
63
- entry.id === id ? { ...entry, status: 'error' } : entry,
64
- ),
65
- }));
66
- });
67
- }
34
+ const { state, update, actions } = useOnboarding();
35
+ const urlInput = state.knowledgeUrlInput;
36
+ const urlError = state.knowledgeUrlError;
68
37
 
38
+ /** Starts valid uploads without superseding other files in this draft. */
69
39
  function handleFiles(files: readonly File[]) {
70
- files.filter((file) => file.size <= MAX_FILE_SIZE_BYTES).forEach(uploadOne);
40
+ files.filter((file) => file.size <= MAX_FILE_SIZE_BYTES).forEach((file) => void actions.uploadFile(file));
71
41
  }
72
42
 
43
+ /** Adds one deliberately supplied URL to this draft. */
73
44
  function handleAddUrl() {
74
45
  const normalized = normalizeUrl(urlInput);
75
46
  if (!normalized) {
76
- setUrlError('Zadejte platnou adresu, např. https://firma.cz/napoveda');
47
+ update({ knowledgeUrlError: 'Zadejte platnou adresu, např. https://firma.cz/napoveda' });
77
48
  return;
78
49
  }
79
- setUrlError(null);
80
- setUrlInput('');
81
50
  update((prev) => ({
82
51
  knowledge: [...prev.knowledge, { kind: 'url', id: createId(), url: normalized, status: 'ready' }],
52
+ knowledgeUrlInput: '',
53
+ knowledgeUrlError: null,
83
54
  }));
84
55
  }
85
56
 
86
- function handleRemove(id: string) {
87
- update((prev) => ({ knowledge: prev.knowledge.filter((entry) => entry.id !== id) }));
88
- }
89
-
90
57
  return (
91
58
  <div className="mx-auto max-w-2xl">
92
59
  <StepHeader
@@ -98,7 +65,7 @@ export function KnowledgeStep() {
98
65
  <StepCard className="space-y-6">
99
66
  <DropZone onFiles={handleFiles} hint="PDF, DOCX, TXT, XLSX · max. 25 MB na soubor" />
100
67
 
101
- <KnowledgeList items={state.knowledge} onRemove={handleRemove} />
68
+ <KnowledgeList items={state.knowledge} onRemove={actions.removeKnowledge} />
102
69
 
103
70
  <div className="border-t border-zinc-100 pt-6">
104
71
  <label htmlFor="knowledge-url" className="mb-1.5 block text-[13px] font-semibold text-zinc-700">
@@ -111,7 +78,9 @@ export function KnowledgeStep() {
111
78
  value={urlInput}
112
79
  placeholder="https://firma.cz/napoveda"
113
80
  aria-invalid={urlError ? true : undefined}
114
- onChange={(event) => setUrlInput(event.target.value)}
81
+ onChange={(event) =>
82
+ update({ knowledgeUrlInput: event.target.value, knowledgeUrlError: null })
83
+ }
115
84
  onKeyDown={(event) => event.key === 'Enter' && handleAddUrl()}
116
85
  className={cn(CONTROL, urlError && CONTROL_ERROR)}
117
86
  />
@@ -127,7 +96,9 @@ export function KnowledgeStep() {
127
96
  {urlError ? (
128
97
  <p className="mt-1 text-xs text-red-600">{urlError}</p>
129
98
  ) : (
130
- <p className="mt-1 text-xs text-zinc-400">Agent si stránku přečte a zahrne do znalostní báze.</p>
99
+ <p className="mt-1 text-xs text-zinc-400">
100
+ Agent si stránku přečte a zahrne do znalostní báze.
101
+ </p>
131
102
  )}
132
103
  </div>
133
104
  </StepCard>
@@ -1,15 +1,10 @@
1
1
  'use client';
2
2
 
3
- import { useRef, useState } from 'react';
4
-
5
3
  import { EMAIL_SCENARIOS } from '../../config/emailScenarios';
6
4
  import { ONBOARDING_STEPS } from '../../config/steps';
7
- import { createId } from '../../lib/id';
8
5
  import { cn } from '../../lib/cn';
9
- import { agentTestService } from '../../services/agentTestService';
10
6
  import { useManGoOnboardingNavigation } from '../../ManGoOnboardingNavigation';
11
7
  import { useOnboarding } from '../../state/OnboardingProvider';
12
- import type { ChatMessage } from '../../types';
13
8
  import { EmailTestRun } from '../EmailTestRun';
14
9
  import { SectionLabel, StepFooter, StepHeader } from '../StepFrame';
15
10
  import { TestChat } from '../TestChat';
@@ -24,82 +19,13 @@ const SAMPLE_PROMPTS = [
24
19
  'Zákazník se ptá, proč mu nedorazilo zboží objednané před 3 dny.',
25
20
  ];
26
21
 
22
+ /** Tests only the active draft, retaining its conversation and results during navigation. */
27
23
  export function TestStep() {
28
24
  const { navigateToPath } = useManGoOnboardingNavigation();
29
- const { state, update } = useOnboarding();
30
-
31
- const [mode, setMode] = useState<TestMode>('email');
32
- const [email, setEmail] = useState(EMAIL_SCENARIOS[1].email);
33
-
34
- const [isSending, setIsSending] = useState(false);
35
- const requestRef = useRef(0);
36
-
37
- async function runAgent(history: readonly ChatMessage[]) {
38
- const requestId = (requestRef.current += 1);
39
- setIsSending(true);
40
- try {
41
- const reply = await agentTestService.send({
42
- bookSource: state.bookSource,
43
- knowledge: state.knowledge,
44
- messages: history,
45
- });
46
- if (requestRef.current !== requestId) {
47
- return;
48
- }
49
- update((prev) => ({
50
- testMessages: [...prev.testMessages, { id: createId(), role: 'agent', content: reply.content }],
51
- }));
52
- } catch {
53
- if (requestRef.current !== requestId) {
54
- return;
55
- }
56
- update((prev) => ({
57
- testMessages: [
58
- ...prev.testMessages,
59
- { id: createId(), role: 'agent', content: 'Omlouvám se, něco se pokazilo. Zkuste to prosím znovu.' },
60
- ],
61
- }));
62
- } finally {
63
- if (requestRef.current === requestId) {
64
- setIsSending(false);
65
- }
66
- }
67
- }
68
-
69
- function send(text: string) {
70
- const trimmed = text.trim();
71
- if (!trimmed || isSending) {
72
- return;
73
- }
74
- const history = [...state.testMessages, { id: createId(), role: 'user' as const, content: trimmed }];
75
- update(() => ({ testMessages: history }));
76
- void runAgent(history);
77
- }
78
-
79
- function retry() {
80
- if (isSending) {
81
- return;
82
- }
83
- const messages = state.testMessages;
84
- let lastUser = -1;
85
- for (let index = messages.length - 1; index >= 0; index -= 1) {
86
- if (messages[index].role === 'user') {
87
- lastUser = index;
88
- break;
89
- }
90
- }
91
- if (lastUser < 0) {
92
- return;
93
- }
94
- const history = messages.slice(0, lastUser + 1);
95
- update(() => ({ testMessages: history }));
96
- void runAgent(history);
97
- }
98
-
99
- function stop() {
100
- requestRef.current += 1;
101
- setIsSending(false);
102
- }
25
+ const { state, update, actions } = useOnboarding();
26
+ const mode = state.testMode;
27
+ const email = state.testEmail;
28
+ const isSending = state.isSendingTestMessage;
103
29
 
104
30
  const agentName = state.agentName.trim() || 'Nepojmenovaný agent';
105
31
  const readyKnowledge = state.knowledge.filter((item) => item.status === 'ready').length;
@@ -114,7 +40,7 @@ export function TestStep() {
114
40
  />
115
41
 
116
42
  <div className="mb-6">
117
- <ModeToggle mode={mode} onChange={setMode} />
43
+ <ModeToggle mode={mode} onChange={(testMode) => update({ testMode })} />
118
44
  </div>
119
45
 
120
46
  <div className="grid items-start gap-6 md:grid-cols-[1fr_1.4fr]">
@@ -150,7 +76,7 @@ export function TestStep() {
150
76
  <button
151
77
  key={scenario.id}
152
78
  type="button"
153
- onClick={() => setEmail(scenario.email)}
79
+ onClick={() => update({ testEmail: scenario.email })}
154
80
  className="flex w-full items-start gap-2.5 rounded-xl border border-zinc-200 bg-white px-3.5 py-2.5 text-left shadow-[var(--ob-shadow-xs)] transition-all hover:-translate-y-px hover:border-[color:var(--ob-accent-300)] hover:shadow-[var(--ob-shadow-sm)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--ob-ring)]"
155
81
  >
156
82
  <span className="text-base" aria-hidden>
@@ -177,7 +103,7 @@ export function TestStep() {
177
103
  key={prompt}
178
104
  type="button"
179
105
  disabled={isSending}
180
- onClick={() => send(prompt)}
106
+ onClick={() => actions.sendTestMessage(prompt)}
181
107
  className="group flex w-full items-start gap-2 rounded-xl border border-zinc-200 bg-white px-3.5 py-2.5 text-left text-[13px] leading-relaxed text-zinc-600 shadow-[var(--ob-shadow-xs)] transition-all hover:-translate-y-px hover:border-[color:var(--ob-accent-300)] hover:text-zinc-900 hover:shadow-[var(--ob-shadow-sm)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--ob-ring)] disabled:cursor-not-allowed disabled:opacity-60"
182
108
  >
183
109
  <span
@@ -197,18 +123,20 @@ export function TestStep() {
197
123
  {mode === 'email' ? (
198
124
  <EmailTestRun
199
125
  email={email}
200
- onEmailChange={setEmail}
126
+ onEmailChange={(testEmail) => update({ testEmail })}
201
127
  bookSource={state.bookSource}
202
128
  knowledge={state.knowledge}
203
129
  onEditBook={() => navigateToPath(ONBOARDING_STEPS[0].path)}
204
130
  />
205
131
  ) : (
206
132
  <TestChat
133
+ inputValue={state.testChatInput}
134
+ onInputChange={(testChatInput) => update({ testChatInput })}
207
135
  messages={state.testMessages}
208
136
  isSending={isSending}
209
- onSend={send}
210
- onStop={stop}
211
- onRetry={isRetryAvailable ? retry : undefined}
137
+ onSend={actions.sendTestMessage}
138
+ onStop={actions.stopTestMessage}
139
+ onRetry={isRetryAvailable ? actions.retryTestMessage : undefined}
212
140
  />
213
141
  )}
214
142
  </div>
@@ -220,7 +148,10 @@ export function TestStep() {
220
148
  </Button>
221
149
  }
222
150
  right={
223
- <Button trailingIcon={<span aria-hidden>→</span>} onClick={() => navigateToPath(ONBOARDING_STEPS[3].path)}>
151
+ <Button
152
+ trailingIcon={<span aria-hidden>→</span>}
153
+ onClick={() => navigateToPath(ONBOARDING_STEPS[3].path)}
154
+ >
224
155
  Uložit první verzi
225
156
  </Button>
226
157
  }
@@ -235,7 +166,11 @@ function ModeToggle({ mode, onChange }: { readonly mode: TestMode; readonly onCh
235
166
  { id: 'chat', label: 'Konverzace', icon: '💬' },
236
167
  ];
237
168
  return (
238
- <div className="inline-flex rounded-xl border border-zinc-200 bg-white p-0.5 shadow-[var(--ob-shadow-xs)]" role="tablist" aria-label="Režim testu">
169
+ <div
170
+ className="inline-flex rounded-xl border border-zinc-200 bg-white p-0.5 shadow-[var(--ob-shadow-xs)]"
171
+ role="tablist"
172
+ aria-label="Režim testu"
173
+ >
239
174
  {options.map((option) => {
240
175
  const isActive = option.id === mode;
241
176
  return (
@@ -13,7 +13,7 @@ import { InputField, TextareaField } from '../ui/Field';
13
13
  */
14
14
  export function ZadaniStep() {
15
15
  const { navigateToPath } = useManGoOnboardingNavigation();
16
- const { state, update } = useOnboarding();
16
+ const { state, update, actions } = useOnboarding();
17
17
  const isContinueEnabled = state.agentName.trim().length > 0 && state.agentBrief.trim().length > 0;
18
18
 
19
19
  return (
@@ -52,7 +52,16 @@ export function ZadaniStep() {
52
52
  disabled={!isContinueEnabled}
53
53
  leadingIcon={<span aria-hidden>✨</span>}
54
54
  trailingIcon={<span aria-hidden>→</span>}
55
- onClick={() => navigateToPath(ONBOARDING_STEPS[0].path)}
55
+ onClick={() => {
56
+ const isAssignmentChanged =
57
+ !state.bookAssignment ||
58
+ state.bookAssignment.agentName !== state.agentName ||
59
+ state.bookAssignment.agentBrief !== state.agentBrief;
60
+ if (!state.bookSource.trim() || isAssignmentChanged) {
61
+ void actions.generate();
62
+ }
63
+ navigateToPath(ONBOARDING_STEPS[0].path);
64
+ }}
56
65
  >
57
66
  Vygenerovat book
58
67
  </Button>
@@ -23,12 +23,15 @@ type EvaluateReplyResponse = {
23
23
  * @param input - Current Book source, customer input, and generated preview reply.
24
24
  * @returns AI-generated checks for the preview result.
25
25
  */
26
- export async function evaluateReply(input: {
27
- readonly bookSource: string;
28
- readonly customerEmail: string;
29
- readonly reply: string;
30
- }): Promise<ReplyCheck[]> {
31
- const response = await postManGoOnboardingJson<EvaluateReplyResponse>('/api/onboarding/evaluate', input);
26
+ export async function evaluateReply(
27
+ input: {
28
+ readonly bookSource: string;
29
+ readonly customerEmail: string;
30
+ readonly reply: string;
31
+ },
32
+ signal?: AbortSignal,
33
+ ): Promise<ReplyCheck[]> {
34
+ const response = await postManGoOnboardingJson<EvaluateReplyResponse>('/api/onboarding/evaluate', input, signal);
32
35
 
33
36
  return response.checks;
34
37
  }
@@ -22,7 +22,7 @@ export type AgentTestReply = {
22
22
  * Boundary for "run the agent against a test message".
23
23
  */
24
24
  export type AgentTestService = {
25
- send(request: AgentTestRequest): Promise<AgentTestReply>;
25
+ send(request: AgentTestRequest, signal?: AbortSignal): Promise<AgentTestReply>;
26
26
  };
27
27
 
28
28
  /**
@@ -55,11 +55,15 @@ type AgentTestApiRequest = {
55
55
  * Endpoint-backed service used by the step 4 test UI.
56
56
  */
57
57
  export const agentTestService: AgentTestService = {
58
- async send(request) {
59
- return postManGoOnboardingJson<AgentTestReply>('/api/onboarding/test', {
60
- bookSource: request.bookSource,
61
- knowledge: knowledgeUrls(request.knowledge),
62
- messages: request.messages.map((message) => ({ role: message.role, content: message.content })),
63
- } satisfies AgentTestApiRequest);
58
+ async send(request, signal) {
59
+ return postManGoOnboardingJson<AgentTestReply>(
60
+ '/api/onboarding/test',
61
+ {
62
+ bookSource: request.bookSource,
63
+ knowledge: knowledgeUrls(request.knowledge),
64
+ messages: request.messages.map((message) => ({ role: message.role, content: message.content })),
65
+ } satisfies AgentTestApiRequest,
66
+ signal,
67
+ );
64
68
  },
65
69
  };
@@ -15,14 +15,21 @@ type GenerateBookResponse = {
15
15
  * @param input - Agent name and brief captured by the entry step.
16
16
  * @returns Editable Book source used by the following wizard steps.
17
17
  */
18
- export async function generateBook(input: {
19
- readonly agentName: string;
20
- readonly agentBrief: string;
21
- }): Promise<string> {
22
- const response = await postManGoOnboardingJson<GenerateBookResponse>('/api/onboarding/book', {
23
- agentName: input.agentName,
24
- agentBrief: input.agentBrief,
25
- });
18
+ export async function generateBook(
19
+ input: {
20
+ readonly agentName: string;
21
+ readonly agentBrief: string;
22
+ },
23
+ signal?: AbortSignal,
24
+ ): Promise<string> {
25
+ const response = await postManGoOnboardingJson<GenerateBookResponse>(
26
+ '/api/onboarding/book',
27
+ {
28
+ agentName: input.agentName,
29
+ agentBrief: input.agentBrief,
30
+ },
31
+ signal,
32
+ );
26
33
 
27
34
  return response.book;
28
35
  }
@@ -33,11 +33,13 @@ type ManGoOnboardingApiErrorPayload = {
33
33
  export async function postManGoOnboardingJson<ResponsePayload>(
34
34
  path: string,
35
35
  body: unknown,
36
+ signal?: AbortSignal,
36
37
  ): Promise<ResponsePayload> {
37
38
  const response = await fetch(path, {
38
39
  method: 'POST',
39
40
  headers: MAN_GO_ONBOARDING_JSON_HEADERS,
40
41
  body: JSON.stringify(body),
42
+ signal,
41
43
  });
42
44
  const payload = await readManGoOnboardingJson(response);
43
45
 
@@ -21,7 +21,7 @@ export type UploadedFile = {
21
21
  * @param file - Browser file selected in the knowledge step.
22
22
  * @returns Public URL consumed by `KNOWLEDGE` commitments.
23
23
  */
24
- export async function uploadKnowledgeFile(file: File): Promise<UploadedFile> {
25
- const publicUrl = await bookEditorUploadHandler(file);
24
+ export async function uploadKnowledgeFile(file: File, signal?: AbortSignal): Promise<UploadedFile> {
25
+ const publicUrl = await bookEditorUploadHandler(file, { abortSignal: signal });
26
26
  return { publicUrl, objectKey: '' };
27
27
  }