@alpaca-editor/core 1.0.4176 → 1.0.4179

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 (32) hide show
  1. package/dist/agents-view/AgentsView.d.ts +2 -2
  2. package/dist/agents-view/AgentsView.js +105 -62
  3. package/dist/agents-view/AgentsView.js.map +1 -1
  4. package/dist/editor/ai/Agents.js +15 -7
  5. package/dist/editor/ai/Agents.js.map +1 -1
  6. package/dist/editor/ai/useAgentStatus.js +6 -1
  7. package/dist/editor/ai/useAgentStatus.js.map +1 -1
  8. package/dist/editor/services/agentService.d.ts +24 -2
  9. package/dist/editor/services/agentService.js +25 -18
  10. package/dist/editor/services/agentService.js.map +1 -1
  11. package/dist/editor/services/aiService.d.ts +1 -0
  12. package/dist/editor/services/aiService.js +9 -6
  13. package/dist/editor/services/aiService.js.map +1 -1
  14. package/dist/page-wizard/steps/ContentStep.js +8 -1
  15. package/dist/page-wizard/steps/ContentStep.js.map +1 -1
  16. package/dist/page-wizard/steps/SelectStep.js +7 -3
  17. package/dist/page-wizard/steps/SelectStep.js.map +1 -1
  18. package/dist/page-wizard/steps/usePageCreator.js +5 -0
  19. package/dist/page-wizard/steps/usePageCreator.js.map +1 -1
  20. package/dist/revision.d.ts +2 -2
  21. package/dist/revision.js +2 -2
  22. package/dist/styles.css +12 -0
  23. package/package.json +1 -1
  24. package/src/agents-view/AgentsView.tsx +303 -208
  25. package/src/editor/ai/Agents.tsx +17 -7
  26. package/src/editor/ai/useAgentStatus.ts +6 -1
  27. package/src/editor/services/agentService.ts +54 -23
  28. package/src/editor/services/aiService.ts +16 -6
  29. package/src/page-wizard/steps/ContentStep.tsx +9 -4
  30. package/src/page-wizard/steps/SelectStep.tsx +8 -3
  31. package/src/page-wizard/steps/usePageCreator.ts +5 -0
  32. package/src/revision.ts +2 -2
@@ -75,9 +75,18 @@ export type AgentStatus =
75
75
  export type Agent = {
76
76
  id: string;
77
77
  name: string;
78
+ description?: string;
78
79
  userId: string;
79
80
  updatedDate: string;
80
81
  status: AgentStatus;
82
+ isShared?: boolean;
83
+ ownerName?: string;
84
+ profileId?: string;
85
+ profileName?: string;
86
+ profileSvgIcon?: string;
87
+ messageCount?: number;
88
+ totalCost?: number;
89
+ totalTokensUsed?: number;
81
90
  };
82
91
 
83
92
  export type AgentDetails = Agent & {
@@ -494,18 +503,43 @@ export async function getAgent(agentId: string): Promise<AgentDetails> {
494
503
  return result.data!;
495
504
  }
496
505
 
506
+ export interface GetAgentsParams {
507
+ skip?: number;
508
+ limit?: number;
509
+ includeShared?: boolean;
510
+ includeOwned?: boolean;
511
+ searchTerm?: string;
512
+ }
513
+
514
+ export interface GetAgentsResponse {
515
+ agents: Agent[];
516
+ totalCount: number;
517
+ hasMore: boolean;
518
+ }
519
+
497
520
  /**
498
- * Gets all agents for the current user
521
+ * Gets all agents for the current user with pagination and search support
499
522
  */
500
- export async function getActiveAgents(limit?: number): Promise<Agent[]> {
501
- const params = new URLSearchParams();
502
- if (limit) params.append("limit", limit.toString());
503
-
504
- const queryString = params.toString();
523
+ export async function getActiveAgents(
524
+ params?: GetAgentsParams,
525
+ ): Promise<GetAgentsResponse> {
526
+ const queryParams = new URLSearchParams();
527
+
528
+ if (params?.skip !== undefined)
529
+ queryParams.append("skip", params.skip.toString());
530
+ if (params?.limit !== undefined)
531
+ queryParams.append("limit", params.limit.toString());
532
+ if (params?.includeShared !== undefined)
533
+ queryParams.append("includeShared", params.includeShared.toString());
534
+ if (params?.includeOwned !== undefined)
535
+ queryParams.append("includeOwned", params.includeOwned.toString());
536
+ if (params?.searchTerm) queryParams.append("searchTerm", params.searchTerm);
537
+
538
+ const queryString = queryParams.toString();
505
539
  const url =
506
540
  AGENT_BASE_URL + "/getAgents" + (queryString ? `?${queryString}` : "");
507
541
 
508
- const result = await get<Agent[]>(url);
542
+ const result = await get<GetAgentsResponse>(url);
509
543
 
510
544
  if (result.type !== "success") {
511
545
  throw new Error(
@@ -513,30 +547,27 @@ export async function getActiveAgents(limit?: number): Promise<Agent[]> {
513
547
  );
514
548
  }
515
549
 
516
- return result.data || [];
550
+ return result.data || { agents: [], totalCount: 0, hasMore: false };
517
551
  }
518
552
 
519
553
  /**
520
554
  * Gets all closed agents for the current user
555
+ * @deprecated Use getActiveAgents() instead - the backend now returns all agents (including closed) by default
521
556
  */
522
557
  export async function getClosedAgents(limit?: number): Promise<Agent[]> {
523
- const params = new URLSearchParams();
524
- params.append("status", "closed");
525
- if (limit) params.append("limit", limit.toString());
526
-
527
- const queryString = params.toString();
528
- const url =
529
- AGENT_BASE_URL + "/getAgents" + (queryString ? `?${queryString}` : "");
530
-
531
- const result = await get<Agent[]>(url);
558
+ // Use the new endpoint format which returns all agents including closed ones
559
+ const response = await getActiveAgents({
560
+ limit: limit || 1000,
561
+ includeShared: false, // Only get user's own closed agents
562
+ includeOwned: true,
563
+ });
532
564
 
533
- if (result.type !== "success") {
534
- throw new Error(
535
- `Failed to get closed agents: ${result.summary || "Unknown error"} ${result.details || ""}`,
536
- );
537
- }
565
+ // Filter to only closed agents on the client side
566
+ const closedAgents = response.agents.filter(
567
+ (agent) => agent.status === "closed" || agent.status === 5, // 5 is the numeric value for Closed
568
+ );
538
569
 
539
- return result.data || [];
570
+ return closedAgents;
540
571
  }
541
572
 
542
573
  /**
@@ -362,11 +362,16 @@ function parseJsonContent<T>(content: string): T {
362
362
  }
363
363
  }
364
364
 
365
- // Apply JsonCleaner to handle incomplete JSON during streaming
366
- const cleanupResult = JsonCleaner.cleanupJson(cleanedContent);
367
- console.log("CLEANED CONTENT: ", cleanupResult.cleanedJson);
365
+ // Replace JavaScript undefined with JSON null
366
+ // Pattern matches: undefined as a value (not inside strings)
367
+ cleanedContent = cleanedContent.replace(
368
+ /:\s*undefined\s*([,\}])/g,
369
+ ": null$1",
370
+ );
368
371
 
369
- return JSON.parse(cleanupResult.cleanedJson) as T;
372
+ // Content is already cleaned by executePrompt for streaming responses
373
+ // and by backend for non-streaming responses, so just parse it
374
+ return JSON.parse(cleanedContent) as T;
370
375
  }
371
376
 
372
377
  /**
@@ -404,7 +409,8 @@ export async function executePromptWithJsonResult<T = any>(
404
409
  const parsed = parseJsonContent<T>(response.content);
405
410
  callback(parsed);
406
411
  } catch (parseError) {
407
- console.error("Error parsing JSON in callback:", parseError);
412
+ // During streaming, JSON may still be incomplete even after cleaning
413
+ // Only invoke callback when we have valid parseable JSON
408
414
  }
409
415
  }
410
416
  : undefined;
@@ -438,9 +444,13 @@ export async function generateImage(
438
444
  prompt: string;
439
445
  sessionId: string;
440
446
  pageItem: ItemDescriptor;
447
+ wizardId: ItemDescriptor;
441
448
  },
442
449
  ): Promise<ExecutionResult<any>> {
443
- const response = await post("/alpaca/editor/agent/generateImage", options);
450
+ const response = await post(
451
+ "/alpaca/editor/page-wizard/generateImage",
452
+ options,
453
+ );
444
454
  return response;
445
455
  }
446
456
  export async function requestQuota() {
@@ -21,10 +21,7 @@ import { convertPageSchemaToWizardComponents } from "./schema";
21
21
  import { WizardPageModel } from "../PageWizard";
22
22
  import { createWizardAiContext, wipeComponents } from "../service";
23
23
 
24
- import {
25
- executePrompt,
26
- executePromptWithJsonResult,
27
- } from "../../editor/services/aiService";
24
+ import { executePromptWithJsonResult } from "../../editor/services/aiService";
28
25
  import { usePageCreator } from "./usePageCreator";
29
26
  import { useThrottledCallback } from "use-debounce";
30
27
  import { Textarea } from "../../components/ui/textarea";
@@ -735,6 +732,13 @@ export function ContentStep({
735
732
 
736
733
  pageLoadedRef.current = false;
737
734
 
735
+ // Reload the current page item to ensure we stay on the same page
736
+ if (currentPageItem) {
737
+ editContextRef.current?.loadItem(getItemDescriptor(currentPageItem), {
738
+ addToBrowseHistory: false,
739
+ });
740
+ }
741
+
738
742
  editContextRef.current?.requestRefresh("immediate");
739
743
  await waitForPageLoaded();
740
744
  console.log("Page loaded after wipe");
@@ -793,6 +797,7 @@ export function ContentStep({
793
797
  Generate a descriptive name for each component including the topic.
794
798
  Only use component types that are in the page schema.
795
799
  Keep existing components with their ids. Leave id field empty for new components.
800
+ To generate images write generate: <keywords> into the picture / image field value.
796
801
  ${(existingPageModel && `Existing page model: ${JSON.stringify(existingPageModel)}`) || ""}
797
802
  Fill empty fields of existing components before you insert new components. Page fields: ${JSON.stringify(
798
803
  schema.pageFields.map((f: SchemaField) => {
@@ -125,7 +125,7 @@ export function SelectStep({
125
125
 
126
126
  // Call the executePromptWithJsonResult function with the prompt
127
127
  const abortController = new AbortController();
128
- const options = await executePromptWithJsonResult<Option[]>(
128
+ const result = await executePromptWithJsonResult<Option[] | Response>(
129
129
  [
130
130
  {
131
131
  content: `You are a helpful assistant that generates options for a wizard select step.
@@ -150,11 +150,16 @@ Create ${step.fields.numberOfOptions || 5} relevant options.`,
150
150
  { signal: abortController.signal },
151
151
  );
152
152
 
153
+ // Handle both array and object responses
154
+ const optionsArray = Array.isArray(result)
155
+ ? result
156
+ : (result as Response)?.options || [];
157
+
153
158
  // Set the parsed options
154
- setOptions(options);
159
+ setOptions(optionsArray);
155
160
  setInternalState((state: any) => ({
156
161
  ...state,
157
- [step.id + "options"]: options,
162
+ [step.id + "options"]: optionsArray,
158
163
  }));
159
164
  } catch (err) {
160
165
  const errorMessage =
@@ -343,6 +343,11 @@ export function usePageCreator(
343
343
  prompt: rawValue,
344
344
  sessionId: editContext.sessionId,
345
345
  pageItem: getItemDescriptor(pageItem),
346
+ wizardId: {
347
+ id: wizard.id,
348
+ language: pageItem.language,
349
+ version: pageItem.version,
350
+ },
346
351
  });
347
352
  } else {
348
353
  if (rawValue.startsWith("id:")) {
package/src/revision.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const version = "1.0.4176";
2
- export const buildDate = "2025-10-21 14:26:44";
1
+ export const version = "1.0.4179";
2
+ export const buildDate = "2025-10-21 20:54:41";