@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
@@ -36,8 +36,8 @@ export type ChatMessage = {
36
36
  };
37
37
 
38
38
  /**
39
- * The full in-memory state of one onboarding session. Persisted to `sessionStorage`
40
- * so a refresh does not throw away work-in-progress. No server-side persistence in v1.
39
+ * Content owned by one explicitly opened onboarding session.
40
+ * Closing or reloading abandons the in-memory draft; a new opening never resumes it.
41
41
  */
42
42
  export type OnboardingState = {
43
43
  readonly agentName: string;
@@ -50,3 +50,28 @@ export type OnboardingState = {
50
50
  /** Route opened by the final CTA after the agent is created. */
51
51
  readonly savedAgentTargetPath: string | null;
52
52
  };
53
+
54
+ /** Draft content and transient UI state that survive navigation within one creation session. */
55
+ export type OnboardingDraftState = OnboardingState & {
56
+ readonly currentPath: string;
57
+ readonly bookAssignment: Pick<OnboardingState, 'agentName' | 'agentBrief'> | null;
58
+ readonly bookGeneration: {
59
+ readonly phase: 'init' | 'generating' | 'ready' | 'error';
60
+ readonly error: string | null;
61
+ };
62
+ readonly knowledgeUrlInput: string;
63
+ readonly knowledgeUrlError: string | null;
64
+ readonly testMode: 'email' | 'chat';
65
+ readonly testEmail: string;
66
+ readonly testChatInput: string;
67
+ readonly isSendingTestMessage: boolean;
68
+ readonly emailTest: {
69
+ readonly phase: 'idle' | 'running' | 'done' | 'error';
70
+ readonly reply: string;
71
+ readonly error: string | null;
72
+ readonly checks: ReadonlyArray<{ readonly status: 'ok' | 'warn'; readonly text: string }> | null;
73
+ readonly isEvaluating: boolean;
74
+ };
75
+ readonly isCreatingAgent: boolean;
76
+ readonly creationError: string | null;
77
+ };
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type { string_book } from '@promptbook-local/types';
4
4
  import type { ReactElement } from 'react';
5
- import { useCallback, useState } from 'react';
5
+ import { useCallback, useEffect, useRef, useState } from 'react';
6
6
  import { NotAllowed } from '../../../../../src/errors/NotAllowed';
7
7
  import { appendHeadlessParam, useIsHeadless } from '../_utils/headlessParam';
8
8
  import type { AgentVisibility } from '../../utils/agentVisibility';
@@ -17,11 +17,10 @@ import { NewAgentDialog } from './NewAgentDialog';
17
17
  import type { NewAgentWizardCreateRequest } from './NewAgentWizard';
18
18
  import { NewAgentWizard } from './NewAgentWizard';
19
19
  import type { NewAgentOpenEditorRequest } from './NewAgentOpenEditorRequest';
20
- import {
21
- ManGoNewAgentWizard,
22
- type ManGoNewAgentWizardCreateRequest,
23
- } from './ManGoNewAgentWizard/ManGoNewAgentWizard';
20
+ import { ManGoNewAgentWizard, type ManGoNewAgentWizardCreateRequest } from './ManGoNewAgentWizard/ManGoNewAgentWizard';
24
21
  import { trackNewAgentCreationEvent } from './trackNewAgentCreationEvent';
22
+ import { createOnboardingSession, type OnboardingSession } from './ManGoNewAgentWizard/state/createOnboardingSession';
23
+ import { retireLegacyOnboardingSnapshot } from './ManGoNewAgentWizard/state/retireLegacyOnboardingSnapshot';
25
24
 
26
25
  /**
27
26
  * Options for opening the new-agent dialog.
@@ -55,6 +54,8 @@ type CreatedAgentPayload = {
55
54
  * Configuration for the reusable new-agent dialog controller.
56
55
  */
57
56
  type UseNewAgentDialogOptions = {
57
+ /** Host account/server scope; changing it abandons only an active manGo draft or handoff. */
58
+ readonly creationScope?: string;
58
59
  /**
59
60
  * Optional callback invoked after the new agent payload is prepared and before navigation starts.
60
61
  */
@@ -97,6 +98,7 @@ type UseNewAgentDialogResult = {
97
98
  type NewAgentDialogState =
98
99
  | {
99
100
  readonly surface: 'editor';
101
+ readonly manGoSession?: OnboardingSession;
100
102
  readonly mode: NewAgentWizardMode;
101
103
  readonly initialAgentSource: string_book;
102
104
  readonly targetFolderId: number | null | undefined;
@@ -111,6 +113,7 @@ type NewAgentDialogState =
111
113
  }
112
114
  | {
113
115
  readonly surface: 'mango-wizard';
116
+ readonly session: OnboardingSession;
114
117
  readonly mode: NewAgentWizardMode;
115
118
  readonly defaultVisibility: AgentVisibility;
116
119
  readonly targetFolderId: number | null | undefined;
@@ -150,15 +153,44 @@ function createCreatedAgentPayload(agentName: string, permanentId: string): Crea
150
153
  * Provides a shared "create new agent" workflow with boilerplate loading and a book-editing dialog.
151
154
  */
152
155
  export function useNewAgentDialog(options: UseNewAgentDialogOptions): UseNewAgentDialogResult {
153
- const { onCreated, onCreateFailed, onPrepareFailed } = options;
156
+ const { creationScope, onCreated, onCreateFailed, onPrepareFailed } = options;
154
157
  const isHeadless = useIsHeadless();
155
158
  const [isPreparingDialog, setIsPreparingDialog] = useState(false);
156
159
  const [dialogState, setDialogState] = useState<NewAgentDialogState | null>(null);
160
+ const openingRevisionRef = useRef(0);
161
+ const manGoSessionRef = useRef<OnboardingSession | null>(null);
162
+ const creationScopeRef = useRef(creationScope);
163
+ creationScopeRef.current = creationScope;
164
+
165
+ /** Ownership includes the current host scope, independently of the random creation identity. */
166
+ const isCurrentManGoSession = useCallback((session: OnboardingSession) => {
167
+ return manGoSessionRef.current === session && creationScopeRef.current === session.scope;
168
+ }, []);
169
+
170
+ // The controller owns exits. Provider/step remounts are not new creation requests.
171
+ useEffect(
172
+ () => () => {
173
+ openingRevisionRef.current += 1;
174
+ manGoSessionRef.current?.end();
175
+ manGoSessionRef.current = null;
176
+ },
177
+ [],
178
+ );
157
179
 
158
180
  const closeNewAgentDialog = useCallback(() => {
181
+ openingRevisionRef.current += 1;
182
+ manGoSessionRef.current?.end();
183
+ manGoSessionRef.current = null;
184
+ setIsPreparingDialog(false);
159
185
  setDialogState(null);
160
186
  }, []);
161
187
 
188
+ useEffect(() => {
189
+ if (manGoSessionRef.current && manGoSessionRef.current.scope !== creationScope) {
190
+ closeNewAgentDialog();
191
+ }
192
+ }, [closeNewAgentDialog, creationScope]);
193
+
162
194
  /**
163
195
  * Finalizes one successful creation by hard-navigating to the new chat route.
164
196
  *
@@ -166,19 +198,35 @@ export function useNewAgentDialog(options: UseNewAgentDialogOptions): UseNewAgen
166
198
  * state, so new-agent creation intentionally uses a full navigation once the route is ready.
167
199
  */
168
200
  const handleCreatedAgent = useCallback(
169
- async (agent: CreatedAgentPayload) => {
170
- await onCreated?.(agent);
171
- setDialogState(null);
201
+ async (
202
+ agent: CreatedAgentPayload,
203
+ isCurrent: () => boolean = () => true,
204
+ isNotificationFailureIgnored = false,
205
+ ) => {
206
+ if (!isCurrent()) return;
207
+ try {
208
+ await onCreated?.(agent);
209
+ } catch (error) {
210
+ if (!isNotificationFailureIgnored) throw error;
211
+ console.error('Created manGo agent notification failed:', error);
212
+ }
213
+ if (!isCurrent()) return;
214
+ closeNewAgentDialog();
172
215
  window.location.assign(appendHeadlessParam(agent.targetPath, isHeadless));
173
216
  },
174
- [isHeadless, onCreated],
217
+ [closeNewAgentDialog, isHeadless, onCreated],
175
218
  );
176
219
 
177
220
  const openNewAgentDialog = useCallback(
178
221
  async (openOptions?: OpenNewAgentDialogOptions) => {
222
+ // Every explicit opening replaces the previous lifetime before awaiting host settings.
223
+ closeNewAgentDialog();
224
+ const openingRevision = openingRevisionRef.current;
179
225
  setIsPreparingDialog(true);
180
226
  try {
181
227
  const settings = await $getNewAgentCreationSettingsAction();
228
+ if (openingRevisionRef.current !== openingRevision || creationScopeRef.current !== creationScope)
229
+ return;
182
230
 
183
231
  trackNewAgentCreationEvent('new_agent_flow_assigned', {
184
232
  mode: settings.mode,
@@ -186,7 +234,11 @@ export function useNewAgentDialog(options: UseNewAgentDialogOptions): UseNewAgen
186
234
  });
187
235
 
188
236
  if (settings.mode === 'MANGO_WIZARD') {
237
+ const session = createOnboardingSession(creationScope);
238
+ manGoSessionRef.current = session;
239
+ retireLegacyOnboardingSnapshot();
189
240
  setDialogState({
241
+ session,
190
242
  surface: 'mango-wizard',
191
243
  mode: settings.mode,
192
244
  defaultVisibility: settings.defaultVisibility,
@@ -209,6 +261,7 @@ export function useNewAgentDialog(options: UseNewAgentDialogOptions): UseNewAgen
209
261
  // Keep wizard opening even when boilerplate name prefill is unavailable.
210
262
  }
211
263
 
264
+ if (openingRevisionRef.current !== openingRevision) return;
212
265
  setDialogState({
213
266
  surface: 'wizard',
214
267
  mode: settings.mode,
@@ -225,6 +278,7 @@ export function useNewAgentDialog(options: UseNewAgentDialogOptions): UseNewAgen
225
278
  }
226
279
 
227
280
  const boilerplate = await $generateAgentBoilerplateAction();
281
+ if (openingRevisionRef.current !== openingRevision) return;
228
282
  setDialogState({
229
283
  surface: 'editor',
230
284
  mode: settings.mode,
@@ -232,37 +286,58 @@ export function useNewAgentDialog(options: UseNewAgentDialogOptions): UseNewAgen
232
286
  targetFolderId: openOptions?.folderId,
233
287
  });
234
288
  } catch (error) {
235
- await onPrepareFailed?.(error);
289
+ if (openingRevisionRef.current === openingRevision && creationScopeRef.current === creationScope) {
290
+ await onPrepareFailed?.(error);
291
+ }
236
292
  } finally {
237
- setIsPreparingDialog(false);
293
+ if (openingRevisionRef.current === openingRevision) setIsPreparingDialog(false);
238
294
  }
239
295
  },
240
- [onPrepareFailed],
296
+ [closeNewAgentDialog, creationScope, onPrepareFailed],
241
297
  );
242
298
 
243
299
  const handleCreateFromEditor = useCallback(
244
300
  async (agentSource: string_book) => {
245
- if (!dialogState || dialogState.surface !== 'editor') {
301
+ if (
302
+ !dialogState ||
303
+ dialogState.surface !== 'editor' ||
304
+ (dialogState.manGoSession && !isCurrentManGoSession(dialogState.manGoSession))
305
+ ) {
246
306
  return;
247
307
  }
248
-
308
+ const session = dialogState.manGoSession;
309
+ const isCurrent = () => !session || (isCurrentManGoSession(session) && session.isActive());
310
+ if (!isCurrent()) return;
311
+ const savedTargetPath = session?.getState().savedAgentTargetPath;
312
+ if (savedTargetPath) {
313
+ closeNewAgentDialog();
314
+ window.location.assign(appendHeadlessParam(savedTargetPath, isHeadless));
315
+ return;
316
+ }
317
+ if (session?.isOperationPending('creation')) return;
318
+ const operation = session?.beginOperation('creation');
319
+ if (session && !operation) return;
249
320
  try {
250
321
  const { agentName, permanentId } = await $createAgentFromBookAction(
251
322
  agentSource,
252
323
  dialogState.targetFolderId,
253
324
  dialogState.visibilityOverride,
254
325
  );
326
+ const createdAgent = createCreatedAgentPayload(agentName, permanentId);
327
+ session?.complete({ permanentId, targetPath: createdAgent.targetPath });
255
328
  trackNewAgentCreationEvent('new_agent_created', {
256
329
  mode: dialogState.mode,
257
330
  surface: 'editor',
258
331
  folderId: dialogState.targetFolderId,
259
332
  });
260
- await handleCreatedAgent(createCreatedAgentPayload(agentName, permanentId));
333
+ await handleCreatedAgent(createdAgent, isCurrent, Boolean(session));
261
334
  } catch (error) {
262
- await onCreateFailed?.(error);
335
+ if (isCurrent()) await onCreateFailed?.(error);
336
+ } finally {
337
+ operation?.finish();
263
338
  }
264
339
  },
265
- [dialogState, handleCreatedAgent, onCreateFailed],
340
+ [closeNewAgentDialog, dialogState, handleCreatedAgent, isCurrentManGoSession, isHeadless, onCreateFailed],
266
341
  );
267
342
 
268
343
  const handleCreateFromWizard = useCallback(
@@ -294,72 +369,114 @@ export function useNewAgentDialog(options: UseNewAgentDialogOptions): UseNewAgen
294
369
 
295
370
  const handleCreateFromManGoWizard = useCallback(
296
371
  async (request: ManGoNewAgentWizardCreateRequest) => {
297
- if (!dialogState || dialogState.surface !== 'mango-wizard') {
298
- throw new NotAllowed('The manGo wizard is not currently open.');
372
+ if (
373
+ !dialogState ||
374
+ dialogState.surface !== 'mango-wizard' ||
375
+ !isCurrentManGoSession(dialogState.session) ||
376
+ !dialogState.session.isActive()
377
+ ) {
378
+ throw new NotAllowed('The manGo creation session is no longer open.');
299
379
  }
300
-
380
+ const session = dialogState.session;
381
+ const isCurrent = () => isCurrentManGoSession(session) && session.isActive();
382
+ let persistedAgent: Awaited<ReturnType<typeof $createAgentFromBookAction>>;
301
383
  try {
302
- const { agentName, permanentId } = await $createAgentFromBookAction(
384
+ persistedAgent = await $createAgentFromBookAction(
303
385
  request.agentSource,
304
386
  dialogState.targetFolderId,
305
387
  request.visibility,
306
388
  );
307
- const createdAgent = createCreatedAgentPayload(agentName, permanentId);
308
- trackNewAgentCreationEvent('new_agent_created', {
309
- mode: dialogState.mode,
310
- surface: 'mango-wizard',
311
- folderId: dialogState.targetFolderId,
312
- knowledgeCount: request.knowledgeCount,
313
- });
314
- await onCreated?.(createdAgent);
315
-
316
- return {
317
- permanentId,
318
- targetPath: createdAgent.targetPath,
319
- };
320
389
  } catch (error) {
321
- await onCreateFailed?.(error);
390
+ if (isCurrent()) await onCreateFailed?.(error);
322
391
  throw error;
323
392
  }
393
+ const createdAgent = createCreatedAgentPayload(persistedAgent.agentName, persistedAgent.permanentId);
394
+ const result = { permanentId: persistedAgent.permanentId, targetPath: createdAgent.targetPath };
395
+ // A cancellation cannot undo a server save. Record success on its original draft first,
396
+ // and never turn a notification failure into a retry of an already created agent.
397
+ session.complete(result);
398
+ trackNewAgentCreationEvent('new_agent_created', {
399
+ mode: dialogState.mode,
400
+ surface: 'mango-wizard',
401
+ folderId: dialogState.targetFolderId,
402
+ knowledgeCount: request.knowledgeCount,
403
+ });
404
+ if (isCurrent()) {
405
+ try {
406
+ await onCreated?.(createdAgent);
407
+ } catch (error) {
408
+ console.error('Created manGo agent notification failed:', error);
409
+ }
410
+ }
411
+ return result;
324
412
  },
325
- [dialogState, onCreateFailed, onCreated],
413
+ [dialogState, isCurrentManGoSession, onCreateFailed, onCreated],
326
414
  );
327
415
 
416
+ const handleCloseManGoWizard = useCallback(() => {
417
+ if (dialogState?.surface === 'mango-wizard' && isCurrentManGoSession(dialogState.session)) {
418
+ closeNewAgentDialog();
419
+ }
420
+ }, [closeNewAgentDialog, dialogState, isCurrentManGoSession]);
421
+
422
+ /** A delayed dirty-editor close confirmation belongs only to the original handoff. */
423
+ const handleCloseEditor = useCallback(() => {
424
+ if (dialogState?.surface !== 'editor') return;
425
+ if (dialogState.manGoSession && !isCurrentManGoSession(dialogState.manGoSession)) return;
426
+ closeNewAgentDialog();
427
+ }, [closeNewAgentDialog, dialogState, isCurrentManGoSession]);
428
+
429
+ const handleRestartManGoWizard = useCallback(() => {
430
+ if (dialogState?.surface !== 'mango-wizard' || !isCurrentManGoSession(dialogState.session)) return;
431
+ dialogState.session.end();
432
+ const session = createOnboardingSession(creationScope);
433
+ manGoSessionRef.current = session;
434
+ // Folder, visibility and flow assignment are host configuration, not draft content.
435
+ setDialogState({ ...dialogState, session });
436
+ }, [creationScope, dialogState, isCurrentManGoSession]);
437
+
328
438
  const handleOpenCreatedManGoAgent = useCallback(
329
439
  (targetPath: string) => {
330
- setDialogState(null);
440
+ if (
441
+ dialogState?.surface !== 'mango-wizard' ||
442
+ !isCurrentManGoSession(dialogState.session) ||
443
+ targetPath !== dialogState.session.getState().savedAgentTargetPath
444
+ )
445
+ return;
446
+ closeNewAgentDialog();
331
447
  window.location.assign(appendHeadlessParam(targetPath, isHeadless));
332
448
  },
333
- [isHeadless],
449
+ [closeNewAgentDialog, dialogState, isCurrentManGoSession, isHeadless],
334
450
  );
335
451
 
336
- const handleOpenEditorFromGuidedSurface = useCallback((request: NewAgentOpenEditorRequest) => {
337
- setDialogState((currentDialogState) => {
338
- if (
339
- !currentDialogState ||
340
- (currentDialogState.surface !== 'wizard' && currentDialogState.surface !== 'mango-wizard')
341
- ) {
342
- return currentDialogState;
343
- }
344
-
345
- return {
452
+ const handleOpenEditorFromGuidedSurface = useCallback(
453
+ (request: NewAgentOpenEditorRequest) => {
454
+ if (!dialogState || (dialogState.surface !== 'wizard' && dialogState.surface !== 'mango-wizard')) return;
455
+ const session = dialogState.surface === 'mango-wizard' ? dialogState.session : undefined;
456
+ if (session && !isCurrentManGoSession(session)) return;
457
+ session?.handoff();
458
+ setDialogState({
346
459
  surface: 'editor',
347
- mode: currentDialogState.mode,
460
+ mode: dialogState.mode,
461
+ manGoSession: session,
348
462
  initialAgentSource: request.agentSource,
349
- targetFolderId: currentDialogState.targetFolderId,
463
+ targetFolderId: dialogState.targetFolderId,
350
464
  visibilityOverride: request.visibility,
351
- };
352
- });
353
- }, []);
465
+ });
466
+ },
467
+ [dialogState, isCurrentManGoSession],
468
+ );
354
469
 
355
470
  return {
356
471
  isPreparingDialog,
357
472
  openNewAgentDialog,
358
473
  closeNewAgentDialog,
359
474
  dialog:
360
- dialogState?.surface === 'editor' ? (
475
+ dialogState?.surface === 'editor' &&
476
+ (!dialogState.manGoSession || dialogState.manGoSession.scope === creationScope) ? (
361
477
  <NewAgentDialog
362
- onClose={closeNewAgentDialog}
478
+ key={dialogState.manGoSession?.id}
479
+ onClose={handleCloseEditor}
363
480
  initialAgentSource={dialogState.initialAgentSource}
364
481
  onCreate={handleCreateFromEditor}
365
482
  />
@@ -373,12 +490,15 @@ export function useNewAgentDialog(options: UseNewAgentDialogOptions): UseNewAgen
373
490
  onCreate={handleCreateFromWizard}
374
491
  onOpenEditor={handleOpenEditorFromGuidedSurface}
375
492
  />
376
- ) : dialogState?.surface === 'mango-wizard' ? (
493
+ ) : dialogState?.surface === 'mango-wizard' && dialogState.session.scope === creationScope ? (
377
494
  <ManGoNewAgentWizard
495
+ key={dialogState.session.id}
496
+ session={dialogState.session}
497
+ onRestart={handleRestartManGoWizard}
378
498
  mode={dialogState.mode}
379
499
  defaultVisibility={dialogState.defaultVisibility}
380
500
  folderId={dialogState.targetFolderId}
381
- onClose={closeNewAgentDialog}
501
+ onClose={handleCloseManGoWizard}
382
502
  onCreate={handleCreateFromManGoWizard}
383
503
  onOpenCreatedAgent={handleOpenCreatedManGoAgent}
384
504
  onOpenEditor={handleOpenEditorFromGuidedSurface}
@@ -35,6 +35,9 @@ const APP_E2E_ENV = Object.freeze({
35
35
  SUPABASE_TABLE_PREFIX: '',
36
36
  POSTGRES_URL: '',
37
37
  DATABASE_URL: '',
38
+ // Background preparation must never inherit a developer's paid OpenAI credentials.
39
+ OPENAI_API_KEY: 'e2e-unused-api-key',
40
+ OPENAI_BASE_URL: `${MOCK_SUPABASE_URL}/v1`,
38
41
  NEXT_PUBLIC_SUPABASE_URL: MOCK_SUPABASE_URL,
39
42
  NEXT_PUBLIC_SUPABASE_ANON_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiJ9.e2e-signature',
40
43
  SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6InNlcnZpY2Vfcm9sZSJ9.e2e-signature',
package/esm/index.es.js CHANGED
@@ -53,7 +53,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
53
53
  * @generated
54
54
  * @see https://github.com/webgptorg/promptbook
55
55
  */
56
- const PROMPTBOOK_ENGINE_VERSION = '0.114.0-50';
56
+ const PROMPTBOOK_ENGINE_VERSION = '0.114.0-51';
57
57
  /**
58
58
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
59
59
  * Note: [šŸ’ž] Ignore a discrepancy between file name and entity name
@@ -50197,7 +50197,7 @@ function normalizeCheckCommandOption(value) {
50197
50197
  }
50198
50198
  // Note: [šŸ’ž] Ignore a discrepancy between file name and exported helper names
50199
50199
 
50200
- /** Shared repository mutation lease, outside the working tree and therefore outside every commit scope. */
50200
+ /** Shared repository mutation lease kept in Promptbook-owned temporary storage. */
50201
50201
  const CODER_WORKSPACE_LOCK_FILENAME = 'ptbk-coder-workspace.lock';
50202
50202
  /** Nested common lifecycle services reuse only the lease owned by this asynchronous job. */
50203
50203
  const WORKSPACE_OWNERSHIP = new AsyncLocalStorage();
@@ -50208,11 +50208,13 @@ const WORKSPACE_OWNERSHIP = new AsyncLocalStorage();
50208
50208
  */
50209
50209
  async function withCoderWorkspaceLock(project, operation, options) {
50210
50210
  const workspace = typeof project === 'string' ? await $resolveWorkspaceRepository(project) : project;
50211
- if (!workspace.gitDirectory) {
50211
+ if (!workspace.repositoryRoot) {
50212
50212
  // Direct-script callers retain their existing Git validation; CLI mutation preflight always supplies Git.
50213
50213
  return operation();
50214
50214
  }
50215
- const lockPath = join(workspace.gitDirectory, CODER_WORKSPACE_LOCK_FILENAME);
50215
+ // Projects in the same checkout share ownership; linked worktrees have their own checkout root.
50216
+ const lockDirectory = resolvePromptbookTemporaryPath(workspace.repositoryRoot, 'ptbk-coder');
50217
+ const lockPath = join(lockDirectory, CODER_WORKSPACE_LOCK_FILENAME);
50216
50218
  const ownedLocks = WORKSPACE_OWNERSHIP.getStore();
50217
50219
  const ownedLock = ownedLocks === null || ownedLocks === void 0 ? void 0 : ownedLocks.get(lockPath);
50218
50220
  if ((options === null || options === void 0 ? void 0 : options.isNestedOwnershipAllowed) && ownedLock) {
@@ -50228,6 +50230,7 @@ async function withCoderWorkspaceLock(project, operation, options) {
50228
50230
  }
50229
50231
  const token = randomBytes(16).toString('hex');
50230
50232
  let handle;
50233
+ await mkdir(lockDirectory, { recursive: true });
50231
50234
  try {
50232
50235
  handle = await open(lockPath, 'wx');
50233
50236
  }
@@ -50246,6 +50249,13 @@ async function withCoderWorkspaceLock(project, operation, options) {
50246
50249
  }
50247
50250
  try {
50248
50251
  await handle.writeFile(JSON.stringify({ token, processId: process.pid, projectPath: workspace.projectPath }));
50252
+ // Keep the lock out of clean-tree checks and commit scopes even without project-level ignore rules.
50253
+ // Initialize these rules only while owning the lease, so competing workers cannot rewrite them.
50254
+ await ensureProjectGitignoreFile({
50255
+ projectPath: lockDirectory,
50256
+ blockHeader: '# Promptbook Coder workspace lock',
50257
+ rules: [`/${CODER_WORKSPACE_LOCK_FILENAME}`, '/.gitignore'],
50258
+ });
50249
50259
  return await WORKSPACE_OWNERSHIP.run(new Map([...(ownedLocks !== null && ownedLocks !== void 0 ? ownedLocks : []), [lockPath, { isNestedActivityActive: false }]]), operation);
50250
50260
  }
50251
50261
  finally {
@@ -91228,12 +91238,17 @@ async function verifyPrompts(options = DEFAULT_VERIFY_PROMPTS_OPTIONS) {
91228
91238
  continue;
91229
91239
  }
91230
91240
  // Second priority: process todo prompts
91231
- const nextPrompt = findNextTodoPrompt(promptFiles);
91241
+ const nextPrompt = findNextTodoPromptToVerify(promptFiles, skippedFiles);
91232
91242
  if (!nextPrompt) {
91233
- console.info(colors.green('\nāœ… All prompts have been verified.'));
91243
+ console.info(colors.green(skippedFiles.size === 0
91244
+ ? '\nāœ… All prompts have been verified.'
91245
+ : '\nāœ… All prompts have been verified, except the skipped ones.'));
91234
91246
  break;
91235
91247
  }
91236
91248
  const outcome = await resolvePrompt(nextPrompt);
91249
+ if (outcome.wasSkipped) {
91250
+ skippedFiles.add(nextPrompt.file.path);
91251
+ }
91237
91252
  await $commitVerificationOutcome(normalizedOptions.gitSync, commitScope, outcome);
91238
91253
  promptFiles = (await loadPromptFilesForVerification(normalizedOptions)).promptFiles;
91239
91254
  }
@@ -91573,6 +91588,12 @@ function displayPromptOverview(promptFiles) {
91573
91588
  console.info(colors.green(' All files have been verified!'));
91574
91589
  }
91575
91590
  }
91591
+ /**
91592
+ * Finds the next todo prompt to ask about, excluding files that have been skipped in this session.
91593
+ */
91594
+ function findNextTodoPromptToVerify(promptFiles, skippedFiles) {
91595
+ return findNextTodoPrompt(promptFiles.filter((file) => !skippedFiles.has(file.path)));
91596
+ }
91576
91597
  /**
91577
91598
  * Resolves a single prompt section by asking the user for its status.
91578
91599
  */
@@ -91583,8 +91604,11 @@ async function resolvePrompt(selection) {
91583
91604
  await archivePromptFile(selection.file);
91584
91605
  return { wasSkipped: false, commitMessage: buildArchiveCommitMessage(selection.file) };
91585
91606
  }
91586
- await appendRepairPrompt(selection.file, selection.section);
91587
- return { wasSkipped: false, commitMessage: buildRepairCommitMessage(selection.file) };
91607
+ // Note: A `[ ]` section has not been run yet, so a `Fix` prompt for it would describe work that never happened.
91608
+ // The section stays in the queue unchanged and its file is skipped for the rest of this run,
91609
+ // otherwise the same section is offered again on every iteration of the loop
91610
+ console.info(colors.gray('\nā© Kept in the queue, no changes made.'));
91611
+ return { wasSkipped: true, commitMessage: null };
91588
91612
  }
91589
91613
  /**
91590
91614
  * Presents the interactive decision menu for the current prompt section.
@@ -91603,9 +91627,9 @@ async function promptForDecision(selection) {
91603
91627
  // description: 'Move this file under prompts/done',
91604
91628
  },
91605
91629
  {
91606
- title: 'šŸ› ļø Not done - add follow-up prompt',
91630
+ title: 'ā© Not done - keep it in the queue',
91607
91631
  value: 'not-done',
91608
- // description: 'Append a Fix prompt referencing the previous section',
91632
+ // description: 'Leave the prompt unchanged and skip this file for the rest of the run',
91609
91633
  },
91610
91634
  ],
91611
91635
  initial: 0,
@@ -91742,7 +91766,8 @@ if (require.main === module) {
91742
91766
  var verifyPrompts$1 = /*#__PURE__*/Object.freeze({
91743
91767
  __proto__: null,
91744
91768
  verifyPrompts: verifyPrompts,
91745
- partitionPromptFilesByIgnore: partitionPromptFilesByIgnore
91769
+ partitionPromptFilesByIgnore: partitionPromptFilesByIgnore,
91770
+ findNextTodoPromptToVerify: findNextTodoPromptToVerify
91746
91771
  });
91747
91772
 
91748
91773
  export { BOOK_LANGUAGE_VERSION, PROMPTBOOK_ENGINE_VERSION, _AgentOsTranspilerRegistration, _AnthropicClaudeManagedTranspilerRegistration, _AnthropicClaudeMetadataRegistration, _AnthropicClaudeRegistration, _AnthropicClaudeSdkTranspilerRegistration, _AzureOpenAiMetadataRegistration, _AzureOpenAiRegistration, _BoilerplateScraperMetadataRegistration, _BoilerplateScraperRegistration, _CLI, _DeepseekMetadataRegistration, _DeepseekRegistration, _DocumentScraperMetadataRegistration, _DocumentScraperRegistration, _E2BTranspilerRegistration, _FormattedBookInMarkdownTranspilerRegistration, _GoogleMetadataRegistration, _GoogleRegistration, _LegacyDocumentScraperMetadataRegistration, _LegacyDocumentScraperRegistration, _MarkdownScraperMetadataRegistration, _MarkdownScraperRegistration, _MarkitdownScraperMetadataRegistration, _MarkitdownScraperRegistration, _OllamaMetadataRegistration, _OllamaRegistration, _OpenAiAgentsTranspilerRegistration, _OpenAiAssistantMetadataRegistration, _OpenAiAssistantRegistration, _OpenAiCompatibleMetadataRegistration, _OpenAiCompatibleRegistration, _OpenAiMetadataRegistration, _OpenAiRegistration, _OpenAiSdkTranspilerRegistration, _PdfScraperMetadataRegistration, _PdfScraperRegistration, _WebsiteScraperMetadataRegistration, _WebsiteScraperRegistration };