@wix/ditto-codegen-public 1.0.46 → 1.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/out.js CHANGED
@@ -117469,7 +117469,7 @@ var require_utils14 = __commonJS({
117469
117469
  return loadRelevantFiles(srcOnlyPaths, basePath).join("\n\n---\n\n");
117470
117470
  }
117471
117471
  var buildUserPromptForCodeGenerationAgent = (params, primaryAction) => {
117472
- const { extension, blueprint, scaffold, userRequestSummary, relevantFilePaths, createdCollections, basePath } = params;
117472
+ const { extension, blueprint, scaffold, userRequestSummary, relevantFilePaths, planAndResources, basePath } = params;
117473
117473
  const contextSections = [];
117474
117474
  if (extension.name)
117475
117475
  contextSections.push(`Extension Name: ${extension.name}`);
@@ -117497,10 +117497,15 @@ Path: ${scaffold.path}
117497
117497
  ${scaffold.content}
117498
117498
  \`\`\``);
117499
117499
  }
117500
- if (createdCollections) {
117500
+ if (planAndResources?.createdCollections) {
117501
117501
  contextSections.push(`
117502
117502
  ## CREATED COLLECTIONS
117503
- ${JSON.stringify(createdCollections, null, 2)}`);
117503
+ ${JSON.stringify(planAndResources.createdCollections, null, 2)}`);
117504
+ }
117505
+ if (planAndResources?.apiSpec) {
117506
+ contextSections.push(`
117507
+ ## API SPEC
117508
+ ${JSON.stringify(planAndResources.apiSpec, null, 2)}`);
117504
117509
  }
117505
117510
  const userMessage = `${primaryAction}:
117506
117511
  ${contextSections.join("\n")}`;
@@ -117761,10 +117766,10 @@ var require_SPIAgent = __commonJS({
117761
117766
  return (0, servicePluginPrompt_1.getServicePluginPrompt)(spiNames, useData);
117762
117767
  }
117763
117768
  async generate(params) {
117764
- const { extension, blueprint, createdCollections } = params;
117769
+ const { extension, blueprint, planAndResources } = params;
117765
117770
  const examples = (0, load_examples_1.loadExamples)([load_examples_1.types.ServicePluginExtension]);
117766
117771
  const allSpiNames = extension.relatedSpis?.map((spi) => spi.name).filter((name) => !!name) || [];
117767
- const useData = Boolean(createdCollections && createdCollections.length > 0);
117772
+ const useData = Boolean(planAndResources?.createdCollections?.length);
117768
117773
  const systemPrompt = `${this.buildSystemPrompt(allSpiNames, useData)}
117769
117774
  ${examples}
117770
117775
  `;
@@ -117804,6 +117809,196 @@ ${examples}
117804
117809
  }
117805
117810
  });
117806
117811
 
117812
+ // dist/system-prompts/planner/apiSpec.js
117813
+ var require_apiSpec = __commonJS({
117814
+ "dist/system-prompts/planner/apiSpec.js"(exports2) {
117815
+ "use strict";
117816
+ Object.defineProperty(exports2, "__esModule", { value: true });
117817
+ exports2.apiSpecPrompt = void 0;
117818
+ var todoExample = {
117819
+ name: "Todo API",
117820
+ description: "A simple todo application API for managing tasks",
117821
+ endpoints: [
117822
+ {
117823
+ id: "get-todos",
117824
+ path: "/api/todos",
117825
+ method: "GET",
117826
+ name: "Get All Todos",
117827
+ description: "Retrieve all todo items",
117828
+ parameters: [],
117829
+ response: {
117830
+ statusCode: 200,
117831
+ type: "array"
117832
+ }
117833
+ },
117834
+ {
117835
+ id: "create-todo",
117836
+ path: "/api/todos",
117837
+ method: "POST",
117838
+ name: "Create Todo",
117839
+ description: "Create a new todo item",
117840
+ parameters: [
117841
+ {
117842
+ name: "title",
117843
+ type: "string",
117844
+ required: true,
117845
+ location: "body"
117846
+ },
117847
+ {
117848
+ name: "description",
117849
+ type: "string",
117850
+ required: false,
117851
+ location: "body"
117852
+ },
117853
+ {
117854
+ name: "completed",
117855
+ type: "boolean",
117856
+ required: false,
117857
+ location: "body"
117858
+ }
117859
+ ],
117860
+ response: {
117861
+ statusCode: 201,
117862
+ type: "object"
117863
+ }
117864
+ },
117865
+ {
117866
+ id: "get-todo-by-id",
117867
+ path: "/api/todos/[id]",
117868
+ method: "GET",
117869
+ name: "Get Todo by ID",
117870
+ description: "Retrieve a specific todo item by its ID",
117871
+ parameters: [
117872
+ {
117873
+ name: "id",
117874
+ type: "string",
117875
+ required: true,
117876
+ location: "path"
117877
+ }
117878
+ ],
117879
+ response: {
117880
+ statusCode: 200,
117881
+ type: "object"
117882
+ }
117883
+ },
117884
+ {
117885
+ id: "update-todo",
117886
+ path: "/api/todos/[id]",
117887
+ method: "PUT",
117888
+ name: "Update Todo",
117889
+ description: "Update an existing todo item",
117890
+ parameters: [
117891
+ {
117892
+ name: "id",
117893
+ type: "string",
117894
+ required: true,
117895
+ location: "path"
117896
+ },
117897
+ {
117898
+ name: "title",
117899
+ type: "string",
117900
+ required: false,
117901
+ location: "body"
117902
+ },
117903
+ {
117904
+ name: "description",
117905
+ type: "string",
117906
+ required: false,
117907
+ location: "body"
117908
+ },
117909
+ {
117910
+ name: "completed",
117911
+ type: "boolean",
117912
+ required: false,
117913
+ location: "body"
117914
+ }
117915
+ ],
117916
+ response: {
117917
+ statusCode: 200,
117918
+ type: "object"
117919
+ }
117920
+ },
117921
+ {
117922
+ id: "delete-todo",
117923
+ path: "/api/todos/[id]",
117924
+ method: "DELETE",
117925
+ name: "Delete Todo",
117926
+ description: "Delete a todo item",
117927
+ parameters: [
117928
+ {
117929
+ name: "id",
117930
+ type: "string",
117931
+ required: true,
117932
+ location: "path"
117933
+ }
117934
+ ],
117935
+ response: {
117936
+ statusCode: 204,
117937
+ type: "object"
117938
+ }
117939
+ }
117940
+ ],
117941
+ dataModels: [
117942
+ {
117943
+ name: "Todo",
117944
+ properties: {
117945
+ id: {
117946
+ type: "string",
117947
+ required: true
117948
+ },
117949
+ title: {
117950
+ type: "string",
117951
+ required: true
117952
+ },
117953
+ description: {
117954
+ type: "string",
117955
+ required: false
117956
+ },
117957
+ completed: {
117958
+ type: "boolean",
117959
+ required: true
117960
+ },
117961
+ createdAt: {
117962
+ type: "string",
117963
+ required: true
117964
+ },
117965
+ updatedAt: {
117966
+ type: "string",
117967
+ required: true
117968
+ }
117969
+ }
117970
+ }
117971
+ ]
117972
+ };
117973
+ var apiSpecPrompt = () => `
117974
+ <API_SPEC_PLANNER_SYSTEM_PROMPT>
117975
+
117976
+ <role>
117977
+ You are a Fullstack API Endpoints planning expert.
117978
+ Given a blueprint describing an app (name, summary, and extensions), you must produce a concrete API spec.
117979
+
117980
+ Your output must be strictly JSON that conforms to the provided schema (no markdown).
117981
+ </role>
117982
+
117983
+ <constraints>
117984
+ - An API Spec is only needed if the blueprint contains an extension with type "BACKEND_API".
117985
+ </constraints>
117986
+
117987
+ <example_output>
117988
+ Expected plan (abbreviated):
117989
+
117990
+ \`\`\`
117991
+ ${JSON.stringify({
117992
+ apiSpec: todoExample
117993
+ }, null, 2)}
117994
+ \`\`\`
117995
+ </example_output>
117996
+
117997
+ </API_SPEC_PLANNER_SYSTEM_PROMPT>`;
117998
+ exports2.apiSpecPrompt = apiSpecPrompt;
117999
+ }
118000
+ });
118001
+
117807
118002
  // dist/system-prompts/planner/data.js
117808
118003
  var require_data2 = __commonJS({
117809
118004
  "dist/system-prompts/planner/data.js"(exports2) {
@@ -117859,32 +118054,30 @@ Your output must be strictly JSON that conforms to the provided schema (no markd
117859
118054
  <example>
117860
118055
  Blueprint indicates a handling fees system for products.
117861
118056
 
117862
- Expected plan (abbreviated):
117863
- {
117864
- "collections": [
117865
- {
117866
- "id": "handling-fees-rules",
117867
- "displayName": "Handling Fees Rules",
117868
- "displayField": "productId",
117869
- "fields": [
117870
- {
117871
- "key": "productId",
117872
- "displayName": "Product",
117873
- "type": "REFERENCE",
117874
- "typeMetadata": {
117875
- "reference": {
117876
- "referencedCollectionId": "Stores/Products"
117877
- }
118057
+ For the collections field, return:
118058
+ [
118059
+ {
118060
+ "id": "handling-fees-rules",
118061
+ "displayName": "Handling Fees Rules",
118062
+ "displayField": "productId",
118063
+ "fields": [
118064
+ {
118065
+ "key": "productId",
118066
+ "displayName": "Product",
118067
+ "type": "REFERENCE",
118068
+ "typeMetadata": {
118069
+ "reference": {
118070
+ "referencedCollectionId": "Stores/Products"
117878
118071
  }
117879
- },
117880
- { "key": "oversizedFee", "displayName": "Oversized Fee", "type": "NUMBER" },
117881
- { "key": "fragileFee", "displayName": "Fragile Fee", "type": "NUMBER" }
117882
- ],
117883
- "permissions": { "read": "ADMIN", "insert": "ADMIN", "update": "ADMIN", "remove": "ADMIN" },
117884
- "plugins": []
117885
- }
117886
- ]
117887
- }
118072
+ }
118073
+ },
118074
+ { "key": "oversizedFee", "displayName": "Oversized Fee", "type": "NUMBER" },
118075
+ { "key": "fragileFee", "displayName": "Fragile Fee", "type": "NUMBER" }
118076
+ ],
118077
+ "permissions": { "read": "ADMIN", "insert": "ADMIN", "update": "ADMIN", "remove": "ADMIN" },
118078
+ "plugins": []
118079
+ }
118080
+ ]
117888
118081
  </example>
117889
118082
 
117890
118083
  <approach>
@@ -117906,10 +118099,13 @@ var require_planner = __commonJS({
117906
118099
  "use strict";
117907
118100
  Object.defineProperty(exports2, "__esModule", { value: true });
117908
118101
  exports2.plannerPrompt = void 0;
118102
+ var apiSpec_1 = require_apiSpec();
117909
118103
  var data_1 = require_data2();
117910
118104
  var plannerPrompt = () => `
117911
118105
  <WIXCLI_PLANNER_SYSTEM_PROMPT>
117912
118106
  ${(0, data_1.cmsPlannerPrompt)()}
118107
+
118108
+ ${(0, apiSpec_1.apiSpecPrompt)()}
117913
118109
  </WIXCLI_PLANNER_SYSTEM_PROMPT>
117914
118110
  `;
117915
118111
  exports2.plannerPrompt = plannerPrompt;
@@ -119818,6 +120014,47 @@ var require_CMSAgent = __commonJS({
119818
120014
  }
119819
120015
  });
119820
120016
 
120017
+ // dist/ApiSpecSchema.js
120018
+ var require_ApiSpecSchema = __commonJS({
120019
+ "dist/ApiSpecSchema.js"(exports2) {
120020
+ "use strict";
120021
+ Object.defineProperty(exports2, "__esModule", { value: true });
120022
+ exports2.ApiSpecSchema = void 0;
120023
+ var zod_1 = require_zod();
120024
+ var HttpMethodSchema = zod_1.z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]);
120025
+ var EndpointSchema = zod_1.z.object({
120026
+ id: zod_1.z.string().describe("Unique identifier for the endpoint"),
120027
+ path: zod_1.z.string().describe("API endpoint path (e.g., '/api/users', '/api/users/[id]')"),
120028
+ method: HttpMethodSchema.describe("HTTP method for the endpoint"),
120029
+ name: zod_1.z.string().describe("Human-readable name for the endpoint"),
120030
+ description: zod_1.z.string().describe("What the endpoint does"),
120031
+ parameters: zod_1.z.array(zod_1.z.object({
120032
+ name: zod_1.z.string(),
120033
+ type: zod_1.z.enum(["string", "number", "boolean", "object", "array"]),
120034
+ required: zod_1.z.boolean().default(false),
120035
+ location: zod_1.z.enum(["path", "query", "body"]).default("body")
120036
+ })).default([]).describe("Input parameters"),
120037
+ response: zod_1.z.object({
120038
+ statusCode: zod_1.z.number().default(200),
120039
+ type: zod_1.z.enum(["string", "number", "boolean", "object", "array"]).default("object")
120040
+ }).describe("Expected response")
120041
+ });
120042
+ var DataModelSchema = zod_1.z.object({
120043
+ name: zod_1.z.string().describe("Name of the data model"),
120044
+ properties: zod_1.z.record(zod_1.z.string(), zod_1.z.object({
120045
+ type: zod_1.z.enum(["string", "number", "boolean", "object", "array"]),
120046
+ required: zod_1.z.boolean().default(false)
120047
+ })).describe("Properties of the model")
120048
+ });
120049
+ exports2.ApiSpecSchema = zod_1.z.object({
120050
+ name: zod_1.z.string().describe("Name of the API"),
120051
+ description: zod_1.z.string().describe("Overall description of the API"),
120052
+ endpoints: zod_1.z.array(EndpointSchema).describe("List of API endpoints to implement"),
120053
+ dataModels: zod_1.z.array(DataModelSchema).default([]).describe("Shared data models/types")
120054
+ }).describe("Complete API specification");
120055
+ }
120056
+ });
120057
+
119821
120058
  // dist/agents/PlannerAgent.js
119822
120059
  var require_PlannerAgent = __commonJS({
119823
120060
  "dist/agents/PlannerAgent.js"(exports2) {
@@ -119830,8 +120067,10 @@ var require_PlannerAgent = __commonJS({
119830
120067
  var planner_1 = require_planner();
119831
120068
  var CMSAgent_1 = require_CMSAgent();
119832
120069
  var utils_1 = require_utils14();
120070
+ var ApiSpecSchema_1 = require_ApiSpecSchema();
119833
120071
  exports2.PlannerOutputSchema = zod_1.z.object({
119834
- collections: zod_1.z.array(CMSAgent_1.CmsCollectionSchema).default([])
120072
+ collections: zod_1.z.array(CMSAgent_1.CmsCollectionSchema).default([]),
120073
+ apiSpec: ApiSpecSchema_1.ApiSpecSchema.optional()
119835
120074
  });
119836
120075
  var PlannerAgent = class {
119837
120076
  constructor(apiKey) {
@@ -121543,6 +121782,149 @@ var require_SiteComponentAgent = __commonJS({
121543
121782
  }
121544
121783
  });
121545
121784
 
121785
+ // dist/system-prompts/backend/backendApi.js
121786
+ var require_backendApi = __commonJS({
121787
+ "dist/system-prompts/backend/backendApi.js"(exports2) {
121788
+ "use strict";
121789
+ Object.defineProperty(exports2, "__esModule", { value: true });
121790
+ exports2.backendApiPrompt = void 0;
121791
+ var backendApiPrompt = () => {
121792
+ return `
121793
+ You are a specialized code-generation agent for creating Astro Server Endpoints (API Routes) for fullstack applications.
121794
+
121795
+ ## Core Knowledge
121796
+
121797
+ ### Astro Server Endpoints Overview
121798
+ - Astro Server Endpoints are API routes that run on the server side
121799
+ - They are located in the \`src/pages/api/\` directory
121800
+ - Each file exports named functions for HTTP methods (GET, POST, PUT, DELETE, etc.)
121801
+ - Files use the \`.ts\` extension and are automatically converted to API endpoints
121802
+
121803
+ ### File Structure and Naming
121804
+ - API routes are created in \`src/pages/api/\` directory
121805
+ - File names become the endpoint path (e.g., \`users.ts\` \u2192 \`/api/users\`)
121806
+ - For dynamic routes with parameters, use square brackets in the filename (e.g., \`/api/users/[id]\`)
121807
+ - Dynamic parameters can be extracted at runtime using the \`params\` parameter in the function
121808
+
121809
+ Example for dynamic route:
121810
+ \`\`\`
121811
+ // src/pages/api/user/[id].ts
121812
+
121813
+ export async function GET({ params }) {
121814
+ const id = params.id;
121815
+ const user = await getUser(id);
121816
+
121817
+ if (!user) {
121818
+ return new Response(null, {
121819
+ status: 404,
121820
+ statusText: "Not found",
121821
+ });
121822
+ }
121823
+
121824
+ return new Response(JSON.stringify(user), {
121825
+ status: 200,
121826
+ headers: {
121827
+ "Content-Type": "application/json",
121828
+ },
121829
+ });
121830
+ }
121831
+ \`\`\`
121832
+
121833
+ ### TypeScript Patterns
121834
+ - Import \`APIRoute\` type from 'astro'
121835
+ - Export named functions for HTTP methods: \`GET\`, \`POST\`, \`PUT\`, \`DELETE\`, \`PATCH\`
121836
+ - Use async/await for handling asynchronous operations
121837
+ - Always return a \`Response\` object
121838
+
121839
+ ### Request Handling
121840
+ - Access request data through the \`request\` parameter
121841
+ - Use \`request.json()\` for POST/PUT request bodies
121842
+ - Use \`request.url\` for the full URL
121843
+ - Use \`new URL(request.url).searchParams\` for query parameters
121844
+ - Access headers via \`request.headers\`
121845
+
121846
+ ### Response Patterns
121847
+ - Always return a \`Response\` object
121848
+ - Use \`JSON.stringify()\` for JSON responses
121849
+ - Set appropriate status codes (200, 201, 400, 404, 500, etc.)
121850
+ - Include proper headers, especially \`Content-Type: application/json\`
121851
+
121852
+ ### Common Patterns
121853
+ - GET endpoints for data retrieval
121854
+ - POST endpoints for data creation
121855
+ - PUT/PATCH endpoints for data updates
121856
+ - DELETE endpoints for data removal
121857
+ - Use proper HTTP status codes
121858
+
121859
+ ### Best Practices
121860
+ - Use proper TypeScript types
121861
+ - Return appropriate HTTP status codes
121862
+ - Include proper headers
121863
+ - Use async/await for asynchronous operations
121864
+ - Keep endpoints focused and single-purpose
121865
+
121866
+ ## Your Task
121867
+ Generate clean, well-structured Astro Server Endpoints based on the API Spec that follow these patterns and best practices.
121868
+ Focus on creating maintainable, secure, and efficient API routes that integrate well with frontend applications.
121869
+ `;
121870
+ };
121871
+ exports2.backendApiPrompt = backendApiPrompt;
121872
+ }
121873
+ });
121874
+
121875
+ // dist/agents/BackendApiAgent.js
121876
+ var require_BackendApiAgent = __commonJS({
121877
+ "dist/agents/BackendApiAgent.js"(exports2) {
121878
+ "use strict";
121879
+ Object.defineProperty(exports2, "__esModule", { value: true });
121880
+ exports2.BackendApiAgent = void 0;
121881
+ var anthropic_1 = require_dist5();
121882
+ var backendApi_1 = require_backendApi();
121883
+ var utils_1 = require_utils14();
121884
+ var ai_1 = require_dist7();
121885
+ var BackendApiAgent = class {
121886
+ constructor(apiKey) {
121887
+ this.apiKey = apiKey;
121888
+ this.name = "BackendApiAgent";
121889
+ }
121890
+ buildSystemPrompt() {
121891
+ return (0, backendApi_1.backendApiPrompt)();
121892
+ }
121893
+ async generate(params) {
121894
+ const { blueprint } = params;
121895
+ const systemPrompt = this.buildSystemPrompt();
121896
+ const primaryAction = `Create Astro Server Endpoints for the app ${blueprint?.appName}`;
121897
+ const userMessage = (0, utils_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
121898
+ const model = (0, anthropic_1.createAnthropic)({ apiKey: this.apiKey })("claude-sonnet-4-20250514");
121899
+ const result = await (0, ai_1.generateObject)({
121900
+ model,
121901
+ schema: utils_1.FileSchema,
121902
+ messages: [
121903
+ {
121904
+ role: "system",
121905
+ content: systemPrompt,
121906
+ providerOptions: (0, utils_1.withCaching)("1h")
121907
+ },
121908
+ {
121909
+ role: "user",
121910
+ content: userMessage
121911
+ }
121912
+ ],
121913
+ experimental_telemetry: {
121914
+ isEnabled: true,
121915
+ functionId: this.name
121916
+ },
121917
+ maxOutputTokens: 1e4,
121918
+ maxRetries: 3,
121919
+ temperature: 0
121920
+ });
121921
+ return result.object.files;
121922
+ }
121923
+ };
121924
+ exports2.BackendApiAgent = BackendApiAgent;
121925
+ }
121926
+ });
121927
+
121546
121928
  // dist/system-prompts/iterationAgent/iterationAgentPrompt.js
121547
121929
  var require_iterationAgentPrompt = __commonJS({
121548
121930
  "dist/system-prompts/iterationAgent/iterationAgentPrompt.js"(exports2) {
@@ -122942,6 +123324,150 @@ var require_data3 = __commonJS({
122942
123324
  }
122943
123325
  });
122944
123326
 
123327
+ // dist/system-prompts/dashboardPage/apiSpecPrompt.js
123328
+ var require_apiSpecPrompt = __commonJS({
123329
+ "dist/system-prompts/dashboardPage/apiSpecPrompt.js"(exports2) {
123330
+ "use strict";
123331
+ Object.defineProperty(exports2, "__esModule", { value: true });
123332
+ exports2.apiSpecPrompt = void 0;
123333
+ exports2.apiSpecPrompt = `
123334
+ <api_spec_docs>
123335
+ You will be given an API specification under the "API SPEC" spec.
123336
+ The dashboard page code you generate can make API calls to these endpoints to read and write data.
123337
+ You cannot write the API calls yourself, you must use the API calls provided in the API SPEC.
123338
+
123339
+ <example_api_spec>
123340
+ ${JSON.stringify({
123341
+ name: "Todo Management API",
123342
+ description: "A simple API for managing todo items with CRUD operations",
123343
+ endpoints: [
123344
+ {
123345
+ id: "get-todos",
123346
+ path: "/api/todos",
123347
+ method: "GET",
123348
+ name: "Get All Todos",
123349
+ description: "Retrieve all todo items",
123350
+ parameters: [],
123351
+ response: {
123352
+ statusCode: 200,
123353
+ type: "array"
123354
+ }
123355
+ },
123356
+ {
123357
+ id: "create-todo",
123358
+ path: "/api/todos",
123359
+ method: "POST",
123360
+ name: "Create Todo",
123361
+ description: "Create a new todo item",
123362
+ parameters: [
123363
+ {
123364
+ name: "todo",
123365
+ type: "object",
123366
+ required: true,
123367
+ location: "body"
123368
+ }
123369
+ ],
123370
+ response: {
123371
+ statusCode: 201,
123372
+ type: "object"
123373
+ }
123374
+ },
123375
+ {
123376
+ id: "update-todo",
123377
+ path: "/api/todos/[id]",
123378
+ method: "PUT",
123379
+ name: "Update Todo",
123380
+ description: "Update an existing todo item",
123381
+ parameters: [
123382
+ {
123383
+ name: "id",
123384
+ type: "string",
123385
+ required: true,
123386
+ location: "path"
123387
+ },
123388
+ {
123389
+ name: "todo",
123390
+ type: "object",
123391
+ required: true,
123392
+ location: "body"
123393
+ }
123394
+ ],
123395
+ response: {
123396
+ statusCode: 200,
123397
+ type: "object"
123398
+ }
123399
+ }
123400
+ ],
123401
+ dataModels: [
123402
+ {
123403
+ name: "Todo",
123404
+ properties: {
123405
+ id: {
123406
+ type: "string",
123407
+ required: true
123408
+ },
123409
+ title: {
123410
+ type: "string",
123411
+ required: true
123412
+ },
123413
+ description: {
123414
+ type: "string",
123415
+ required: false
123416
+ },
123417
+ completed: {
123418
+ type: "boolean",
123419
+ required: true
123420
+ },
123421
+ createdAt: {
123422
+ type: "string",
123423
+ required: true
123424
+ }
123425
+ }
123426
+ }
123427
+ ]
123428
+ }, null, 2)}
123429
+ </example_api_spec>
123430
+
123431
+ <example_output_code>
123432
+ // Reading data - GET request
123433
+ async function getTodos(): Promise<Todo[]> {
123434
+ const response = await fetch('/api/todos');
123435
+ const data = await response.json();
123436
+ return data;
123437
+ }
123438
+
123439
+ // Writing data - POST request with data model entity
123440
+ async function createTodo(todo: Omit<Todo, 'id' | 'createdAt'>): Promise<Todo> {
123441
+ const response = await fetch('/api/todos', {
123442
+ method: 'POST',
123443
+ headers: {
123444
+ 'Content-Type': 'application/json',
123445
+ },
123446
+ body: JSON.stringify(todo),
123447
+ });
123448
+ const data = await response.json();
123449
+ return data;
123450
+ }
123451
+
123452
+ // Writing data - PUT request with data model entity
123453
+ async function updateTodo(id: string, todo: Partial<Todo>): Promise<Todo> {
123454
+ const response = await fetch(\`/api/todos/\${id}\`, {
123455
+ method: 'PUT',
123456
+ headers: {
123457
+ 'Content-Type': 'application/json',
123458
+ },
123459
+ body: JSON.stringify(todo),
123460
+ });
123461
+ const data = await response.json();
123462
+ return data;
123463
+ }
123464
+ </example_output_code>
123465
+
123466
+ </api_spec_docs>
123467
+ `;
123468
+ }
123469
+ });
123470
+
122945
123471
  // dist/system-prompts/dashboardPage/dashboardPagePrompt.js
122946
123472
  var require_dashboardPagePrompt = __commonJS({
122947
123473
  "dist/system-prompts/dashboardPage/dashboardPagePrompt.js"(exports2) {
@@ -122952,6 +123478,7 @@ var require_dashboardPagePrompt = __commonJS({
122952
123478
  var dashboardPackage_1 = require_dashboardPackage();
122953
123479
  var wdsPackage_1 = require_wdsPackage();
122954
123480
  var data_1 = require_data3();
123481
+ var apiSpecPrompt_1 = require_apiSpecPrompt();
122955
123482
  var wdsPackage_2 = require_wdsPackage();
122956
123483
  Object.defineProperty(exports2, "buildWdsSystemPrompt", { enumerable: true, get: function() {
122957
123484
  return wdsPackage_2.buildWdsSystemPrompt;
@@ -122981,7 +123508,7 @@ var require_dashboardPagePrompt = __commonJS({
122981
123508
  "ToggleSwitch",
122982
123509
  "InfoIcon"
122983
123510
  ];
122984
- var dashboardPagePrompt = async (useData) => {
123511
+ var dashboardPagePrompt = async ({ useData, useApiSpec }) => {
122985
123512
  const wdsPrompt = await (0, wdsPackage_1.buildWdsSystemPrompt)(listOfWdsComponents);
122986
123513
  return `
122987
123514
  <WIXCLI_DASHBOARD_PAGE_SYSTEM_PROMPT>
@@ -123062,6 +123589,8 @@ ${wdsPrompt}
123062
123589
  </typescript_quality_guidelines>
123063
123590
 
123064
123591
  ${useData ? data_1.dataPrompt : ""}
123592
+
123593
+ ${useApiSpec ? apiSpecPrompt_1.apiSpecPrompt : ""}
123065
123594
  </WIXCLI_DASHBOARD_PAGE_SYSTEM_PROMPT>
123066
123595
  `;
123067
123596
  };
@@ -123085,14 +123614,15 @@ var require_DashboardPageAgent = __commonJS({
123085
123614
  this.apiKey = apiKey;
123086
123615
  this.name = "DashboardPageAgent";
123087
123616
  }
123088
- async buildSystemPrompt(useData) {
123089
- return (0, dashboardPagePrompt_1.dashboardPagePrompt)(useData);
123617
+ async buildSystemPrompt(opts) {
123618
+ return (0, dashboardPagePrompt_1.dashboardPagePrompt)(opts);
123090
123619
  }
123091
123620
  async generate(params) {
123092
- const { blueprint, createdCollections } = params;
123621
+ const { blueprint, planAndResources } = params;
123093
123622
  const examples = (0, load_examples_1.loadExamples)([load_examples_1.types.DashboardPage]);
123094
- const useData = Boolean(createdCollections && createdCollections.length > 0);
123095
- const systemPrompt = `${await this.buildSystemPrompt(useData)}
123623
+ const useData = Boolean(planAndResources?.createdCollections?.length);
123624
+ const useApiSpec = Boolean(planAndResources?.apiSpec);
123625
+ const systemPrompt = `${await this.buildSystemPrompt({ useData, useApiSpec })}
123096
123626
  ${examples}
123097
123627
  `;
123098
123628
  console.log(`Dashboard Agent System Prompt length: ${systemPrompt.length} (is that what you expect?)`);
@@ -123385,12 +123915,13 @@ Dashboard Page Description: ${extension.description}
123385
123915
  ${collectionsInfo}
123386
123916
  </available-collections>`;
123387
123917
  }
123388
- async generate({ blueprint, extension, createdCollections }) {
123389
- if (createdCollections.length === 0) {
123918
+ async generate({ blueprint, extension, planAndResources }) {
123919
+ if (!planAndResources.createdCollections?.length) {
123390
123920
  return {
123391
123921
  useAutoPatterns: false
123392
123922
  };
123393
123923
  }
123924
+ const { createdCollections } = planAndResources;
123394
123925
  const model = (0, anthropic_1.createAnthropic)({ apiKey: this.apiKey })("claude-3-5-haiku-latest");
123395
123926
  const collectionsInfo = createdCollections.map((collection, index) => {
123396
123927
  const userFields = collection.fields?.filter((field) => !field.key?.startsWith("_")) || [];
@@ -123609,15 +124140,11 @@ var require_scaffolding = __commonJS({
123609
124140
  }
123610
124141
  async function copyBackendApiScaffolding(extension, outputPath) {
123611
124142
  const uniqueFolderName = toKebabCase(extension.name || "my-api");
123612
- const apiScaffoldingSubPath = "src/backend/api/my-api";
123613
- const webMethodFile = "src/backend/my-web-method.web.ts";
123614
- const apiOutputFolder = `src/backend/api/${uniqueFolderName}`;
123615
- const webMethodOutputFile = `src/backend/${uniqueFolderName}.web.ts`;
123616
- console.log(` \u{1F50C} Copying backend API scaffolding from: ${apiScaffoldingSubPath} to ${apiOutputFolder}`);
123617
- const apiFiles = (0, tools_1.copyScaffolding)(apiScaffoldingSubPath, outputPath, apiOutputFolder);
123618
- console.log(` \u{1F310} Copying web method from: ${webMethodFile} to ${webMethodOutputFile}`);
123619
- const webMethodFiles = (0, tools_1.copyScaffolding)(webMethodFile, outputPath, webMethodOutputFile);
123620
- return [...apiFiles, ...webMethodFiles];
124143
+ const apiScaffoldingFile = "src/pages/api/my-api.ts";
124144
+ const apiOutputFile = `src/pages/api/${uniqueFolderName}.ts`;
124145
+ console.log(` \u{1F50C} Copying backend API scaffolding from: ${apiScaffoldingFile} to ${apiOutputFile}`);
124146
+ const apiFiles = (0, tools_1.copyScaffolding)(apiScaffoldingFile, outputPath, apiOutputFile);
124147
+ return apiFiles;
123621
124148
  }
123622
124149
  async function copyBackendEventScaffolding(extension, outputPath) {
123623
124150
  const scaffoldingSubPath = "src/backend/events/my-event";
@@ -124013,6 +124540,7 @@ var require_AgentsFactory = __commonJS({
124013
124540
  var CMSAgent_1 = require_CMSAgent();
124014
124541
  var CMSDataAgent_1 = require_CMSDataAgent();
124015
124542
  var SiteComponentAgent_1 = __importDefault2(require_SiteComponentAgent());
124543
+ var BackendApiAgent_1 = require_BackendApiAgent();
124016
124544
  var IterationAgent_1 = __importDefault2(require_IterationAgent());
124017
124545
  var CustomElementAgent_1 = __importDefault2(require_CustomElementAgent());
124018
124546
  var DashboardPageAgent_1 = __importDefault2(require_DashboardPageAgent());
@@ -124044,6 +124572,8 @@ var require_AgentsFactory = __commonJS({
124044
124572
  return new SiteComponentAgent_1.default(this.apiKey);
124045
124573
  case types_1.ExtensionType.SITE_WIDGET:
124046
124574
  return new CustomElementAgent_1.default(this.apiKey);
124575
+ case types_1.ExtensionType.BACKEND_API:
124576
+ return new BackendApiAgent_1.BackendApiAgent(this.apiKey);
124047
124577
  default:
124048
124578
  throw new Error(`Unsupported extension type for AI customization: ${extension.type}`);
124049
124579
  }
@@ -126609,7 +127139,6 @@ var require_extensionGenerators = __commonJS({
126609
127139
  var __importDefault2 = exports2 && exports2.__importDefault || function(mod2) {
126610
127140
  return mod2 && mod2.__esModule ? mod2 : { "default": mod2 };
126611
127141
  };
126612
- var _a2;
126613
127142
  Object.defineProperty(exports2, "__esModule", { value: true });
126614
127143
  exports2.ExtensionFactory = void 0;
126615
127144
  var path_1 = __importDefault2(require("path"));
@@ -126620,62 +127149,117 @@ var require_extensionGenerators = __commonJS({
126620
127149
  var ditto_scaffolding_2 = require_dist11();
126621
127150
  var ExtensionFactory = class {
126622
127151
  static generateExtension(extension, outputPath, scaffoldPath) {
126623
- const config = this.extensionConfigs[extension.type];
126624
- if (!config) {
126625
- throw new Error(`Unsupported extension type: ${extension.type}`);
126626
- }
126627
127152
  const scaffoldDir = path_1.default.dirname(scaffoldPath);
126628
- const name = extension.name || config.defaultName;
126629
127153
  const id = (0, crypto_1.randomUUID)();
126630
- const builderMethod = typeof config.builderMethod === "function" ? config.builderMethod(extension, scaffoldDir, outputPath) : config.builderMethod;
126631
- const baseData = {
126632
- id,
126633
- name,
126634
- extensionType: extension.type,
126635
- builderMethod,
126636
- ...config.createExtensionData(extension, scaffoldDir, id)
126637
- };
126638
- writeExtensionTs(outputPath, name, baseData, scaffoldDir);
126639
- }
126640
- static getServicePluginBuilderMethod(ext) {
126641
- if (!ext.relatedSpis || ext.relatedSpis.length !== 1) {
126642
- throw new Error("Service plugin extension must have only one related SPI");
126643
- }
126644
- const scaffoldingSubPath = findScaffoldingSubPath(ext.relatedSpis[0]);
126645
- if (!scaffoldingSubPath) {
126646
- throw new Error("No valid scaffolding subpath found for service plugin");
126647
- }
126648
- if (!this.servicePluginBuilderMap[scaffoldingSubPath]) {
126649
- throw new Error(`Unsupported scaffolding subpath: ${scaffoldingSubPath}`);
127154
+ switch (extension.type) {
127155
+ case types_1.ExtensionType.SERVICE_PLUGIN: {
127156
+ const name = extension.name || "My Service Plugin";
127157
+ const servicePluginType = this.getServicePluginType(extension);
127158
+ const builderMethod = this.servicePluginBuilderMap[servicePluginType];
127159
+ const extensionConfig = this.createServicePluginData(name, scaffoldDir, id, servicePluginType);
127160
+ writeExtensionFile({
127161
+ outputPath,
127162
+ name,
127163
+ builderMethodName: builderMethod,
127164
+ extensionConfig,
127165
+ extensionType: extension.type,
127166
+ scaffoldDir
127167
+ });
127168
+ break;
127169
+ }
127170
+ case types_1.ExtensionType.DASHBOARD_PAGE: {
127171
+ const name = extension.name || "My Backoffice Page";
127172
+ const extensionConfig = this.createDashboardPageData(id, name, scaffoldDir);
127173
+ writeExtensionFile({
127174
+ outputPath,
127175
+ name,
127176
+ builderMethodName: "backofficePage",
127177
+ extensionConfig,
127178
+ extensionType: extension.type,
127179
+ scaffoldDir
127180
+ });
127181
+ break;
127182
+ }
127183
+ case types_1.ExtensionType.SITE_COMPONENT: {
127184
+ const name = extension.name || "My Site Component";
127185
+ const extensionConfig = this.createSiteComponentData(name, scaffoldDir, id);
127186
+ writeExtensionFile({
127187
+ outputPath,
127188
+ name,
127189
+ builderMethodName: "siteComponent",
127190
+ extensionConfig,
127191
+ extensionType: extension.type,
127192
+ scaffoldDir
127193
+ });
127194
+ break;
127195
+ }
127196
+ case types_1.ExtensionType.SITE_WIDGET: {
127197
+ const name = extension.name || "My Site Widget";
127198
+ const extensionConfig = this.createCustomElementData(id, name, scaffoldDir);
127199
+ writeExtensionFile({
127200
+ outputPath,
127201
+ name,
127202
+ builderMethodName: "customElement",
127203
+ extensionConfig,
127204
+ extensionType: extension.type,
127205
+ scaffoldDir
127206
+ });
127207
+ break;
127208
+ }
127209
+ default:
127210
+ console.log(`Skipping extension type: ${extension.type}. It doesn't need presence in the extensions.ts file (e.g. Backend API is astro only)`);
127211
+ return;
126650
127212
  }
126651
- return this.servicePluginBuilderMap[scaffoldingSubPath];
126652
127213
  }
126653
- static createServicePluginData(ext, scaffoldDir) {
127214
+ static getServicePluginType(ext) {
126654
127215
  if (!ext.relatedSpis || ext.relatedSpis.length !== 1) {
126655
127216
  throw new Error("Service plugin extension must have only one related SPI");
126656
127217
  }
126657
- const scaffoldingSubPath = findScaffoldingSubPath(ext.relatedSpis[0]);
126658
- if (!scaffoldingSubPath) {
126659
- throw new Error("No valid scaffolding subpath found for service plugin");
127218
+ const relatedSpi = ext.relatedSpis[0];
127219
+ if (relatedSpi?.name && ditto_scaffolding_1.spiToSubPath[relatedSpi.name]) {
127220
+ return ditto_scaffolding_1.spiToSubPath[relatedSpi.name];
126660
127221
  }
127222
+ throw new Error("No valid service plugin type found for service plugin");
127223
+ }
127224
+ static createServicePluginData(name, scaffoldDir, id, servicePluginType) {
126661
127225
  const source = "./" + path_1.default.join(scaffoldDir, "plugin.ts").replace(/^src\//, "");
126662
- return { source, name: ext.name };
127226
+ switch (servicePluginType) {
127227
+ case "ecom-shipping-rates":
127228
+ return {
127229
+ id,
127230
+ source,
127231
+ name
127232
+ };
127233
+ case "ecom-additional-fees":
127234
+ return { id, source };
127235
+ case "ecom-validations":
127236
+ return { id, source };
127237
+ case "ecom-discounts-trigger":
127238
+ return { id, source };
127239
+ case "gift-cards-provider":
127240
+ return { id, source };
127241
+ case "ecom-payment-settings":
127242
+ return { id, source };
127243
+ default:
127244
+ throw new Error(`Unsupported service plugin type ${servicePluginType}`);
127245
+ }
126663
127246
  }
126664
- static createDashboardPageData(ext, scaffoldDir) {
126665
- const title = ext.name || "My Backoffice Page";
126666
- const routePath = ext.name?.toLowerCase().replace(/\s+/g, "-");
127247
+ static createDashboardPageData(id, name, scaffoldDir) {
127248
+ const routePath = name.toLowerCase().replace(/\s+/g, "-");
126667
127249
  const component = "./" + path_1.default.join(scaffoldDir, "page.tsx").replace(/^src\//, "");
126668
127250
  return {
126669
- title,
127251
+ id,
127252
+ title: name,
126670
127253
  routePath,
126671
127254
  component
126672
127255
  };
126673
127256
  }
126674
- static createCustomElementData(ext, scaffoldDir) {
126675
- const componentName = ext.name ?? "custom-element";
126676
- const kebabCaseComponentName = (0, ditto_scaffolding_2.toKebabCase)(componentName);
127257
+ static createCustomElementData(id, name, scaffoldDir) {
127258
+ const kebabCaseComponentName = (0, ditto_scaffolding_2.toKebabCase)(name);
126677
127259
  const componentPath = "./" + path_1.default.join(scaffoldDir, "widget.tsx").replace(/^src\//, "");
126678
127260
  return {
127261
+ id,
127262
+ name,
126679
127263
  tagName: "custom-element",
126680
127264
  element: componentPath,
126681
127265
  installation: { base: { autoAdd: true } },
@@ -126685,15 +127269,15 @@ var require_extensionGenerators = __commonJS({
126685
127269
  size: { height: { defaultHeight: 500 }, width: { defaultWidth: 500 } }
126686
127270
  };
126687
127271
  }
126688
- static createSiteComponentData(ext, scaffoldDir, id) {
126689
- const componentName = ext.name ?? "my-component";
126690
- const kebabCaseComponentName = (0, ditto_scaffolding_2.toKebabCase)(componentName);
127272
+ static createSiteComponentData(name, scaffoldDir, id) {
127273
+ const kebabCaseComponentName = (0, ditto_scaffolding_2.toKebabCase)(name);
126691
127274
  const componentPath = "./" + path_1.default.join(scaffoldDir, "component.tsx").replace(/^src\//, "");
126692
127275
  return {
126693
- description: ext.name,
127276
+ id,
127277
+ description: name,
126694
127278
  type: `platform.builder.${id}`,
126695
127279
  editorElement: {
126696
- displayName: componentName,
127280
+ displayName: name,
126697
127281
  selector: kebabCaseComponentName
126698
127282
  },
126699
127283
  resources: {
@@ -126705,29 +127289,6 @@ var require_extensionGenerators = __commonJS({
126705
127289
  }
126706
127290
  };
126707
127291
  exports2.ExtensionFactory = ExtensionFactory;
126708
- _a2 = ExtensionFactory;
126709
- ExtensionFactory.extensionConfigs = {
126710
- [types_1.ExtensionType.SERVICE_PLUGIN]: {
126711
- builderMethod: _a2.getServicePluginBuilderMethod.bind(_a2),
126712
- defaultName: "My Service Plugin",
126713
- createExtensionData: _a2.createServicePluginData.bind(_a2)
126714
- },
126715
- [types_1.ExtensionType.DASHBOARD_PAGE]: {
126716
- builderMethod: "backofficePage",
126717
- defaultName: "My Backoffice Page",
126718
- createExtensionData: _a2.createDashboardPageData.bind(_a2)
126719
- },
126720
- [types_1.ExtensionType.SITE_COMPONENT]: {
126721
- builderMethod: "siteComponent",
126722
- defaultName: "my-component",
126723
- createExtensionData: _a2.createSiteComponentData.bind(_a2)
126724
- },
126725
- [types_1.ExtensionType.SITE_WIDGET]: {
126726
- builderMethod: "customElement",
126727
- defaultName: "my-custom-element",
126728
- createExtensionData: _a2.createCustomElementData.bind(_a2)
126729
- }
126730
- };
126731
127292
  ExtensionFactory.servicePluginBuilderMap = {
126732
127293
  "ecom-shipping-rates": "ecomShippingRates",
126733
127294
  "ecom-additional-fees": "ecomAdditionalFees",
@@ -126736,12 +127297,12 @@ var require_extensionGenerators = __commonJS({
126736
127297
  "gift-cards-provider": "ecomGiftCardsProvider",
126737
127298
  "ecom-payment-settings": "ecomPaymentSettings"
126738
127299
  };
126739
- function writeExtensionTs(outputPath, name, extensionData, scaffoldPath) {
127300
+ function writeExtensionFile({ outputPath, name, builderMethodName, extensionConfig, extensionType, scaffoldDir }) {
126740
127301
  const sanitizedName = name.replace(/[^a-zA-Z0-9\s-_]/g, "").trim();
126741
127302
  if (!sanitizedName) {
126742
127303
  throw new Error(`Invalid extension name: "${name}"`);
126743
127304
  }
126744
- const absoluteScaffoldPath = path_1.default.isAbsolute(scaffoldPath) ? scaffoldPath : path_1.default.resolve(outputPath, scaffoldPath);
127305
+ const absoluteScaffoldPath = path_1.default.isAbsolute(scaffoldDir) ? scaffoldDir : path_1.default.resolve(outputPath, scaffoldDir);
126745
127306
  const filePath = path_1.default.join(absoluteScaffoldPath, "extensions.ts");
126746
127307
  const relativePath = path_1.default.relative(outputPath, filePath);
126747
127308
  const normalizedFilePath = path_1.default.resolve(filePath);
@@ -126749,16 +127310,15 @@ var require_extensionGenerators = __commonJS({
126749
127310
  if (!normalizedFilePath.startsWith(normalizedOutputPath)) {
126750
127311
  throw new Error(`Attempted to write extension file outside output path: ${filePath}`);
126751
127312
  }
126752
- const tsContent = generateExtensionTsContent(extensionData);
127313
+ const tsContent = generateExtensionTsContent(builderMethodName, extensionConfig, extensionType, name);
126753
127314
  fs_extra_1.default.outputFileSync(filePath, tsContent);
126754
127315
  return relativePath;
126755
127316
  }
126756
- function generateExtensionTsContent(extensionData) {
126757
- const { builderMethod, extensionType, name, ...config } = extensionData;
127317
+ function generateExtensionTsContent(builderMethodName, extensionConfig, extensionType, name) {
126758
127318
  const extensionName = generateUniqueExtensionName(extensionType, name);
126759
- const configString = JSON.stringify(config, null, 2);
127319
+ const configString = JSON.stringify(extensionConfig, null, 2);
126760
127320
  return `import * as extensions from '@wix/astro/builders';
126761
- export const ${extensionName} = extensions.${builderMethod}(${configString})
127321
+ export const ${extensionName} = extensions.${builderMethodName}(${configString})
126762
127322
  `;
126763
127323
  }
126764
127324
  function generateUniqueExtensionName(extensionType, name) {
@@ -126767,12 +127327,6 @@ export const ${extensionName} = extensions.${builderMethod}(${configString})
126767
127327
  const camelCaseName = toCamelCase(sanitizedName);
126768
127328
  return `${typePrefix}${camelCaseName}`;
126769
127329
  }
126770
- function findScaffoldingSubPath(relatedSpis) {
126771
- if (relatedSpis?.name && ditto_scaffolding_1.spiToSubPath[relatedSpis.name]) {
126772
- return ditto_scaffolding_1.spiToSubPath[relatedSpis.name];
126773
- }
126774
- return null;
126775
- }
126776
127330
  function sanitizeName(name) {
126777
127331
  return name.replace(/[^a-zA-Z0-9\s-_]/g, "").replace(/\s+/g, " ").trim();
126778
127332
  }
@@ -133467,19 +134021,26 @@ var require_orchestrator = __commonJS({
133467
134021
  this.emitEvent("cms:start", {});
133468
134022
  const cmsAgent = this.agentsFactory.getAgent({ type: "CMS" });
133469
134023
  for (const collection of plan.collections) {
133470
- const result = await cmsAgent.generate({
134024
+ const result2 = await cmsAgent.generate({
133471
134025
  blueprint,
133472
134026
  siteId,
133473
134027
  accessToken,
133474
134028
  collection
133475
134029
  });
133476
- createdCollections.push(result.collection);
134030
+ createdCollections.push(result2.collection);
133477
134031
  }
133478
134032
  this.emitEvent("cms:done", {
133479
134033
  numberOfCollections: plan.collections.length
133480
134034
  });
133481
134035
  }
133482
- return { createdCollections };
134036
+ const result = {};
134037
+ if (createdCollections.length > 0) {
134038
+ result.createdCollections = createdCollections;
134039
+ }
134040
+ if (plan?.apiSpec) {
134041
+ result.apiSpec = plan.apiSpec;
134042
+ }
134043
+ return result;
133483
134044
  }
133484
134045
  async runIterationPlanningAndAugmentExtensions(outputPath, chatHistory) {
133485
134046
  const iterationAgent = this.agentsFactory.getAgent({
@@ -133490,94 +134051,70 @@ var require_orchestrator = __commonJS({
133490
134051
  const iterationPlan = await iterationAgent.generate(outputPath, candidateFiles, currentUserRequest, chatHistory);
133491
134052
  return iterationPlan;
133492
134053
  }
133493
- async processExtension({ extension, blueprint, outputPath, createdCollections }) {
134054
+ async processExtension({ extension, blueprint, outputPath, planAndResources }) {
133494
134055
  switch (extension.type) {
133495
134056
  case types_1.ExtensionType.DASHBOARD_PAGE:
133496
134057
  return this.processDashboardPage({
133497
134058
  extension,
133498
134059
  blueprint,
133499
134060
  outputPath,
133500
- createdCollections
134061
+ planAndResources
133501
134062
  });
133502
134063
  case types_1.ExtensionType.SERVICE_PLUGIN:
133503
134064
  return this.processServicePlugin({
133504
134065
  extension,
133505
134066
  blueprint,
133506
134067
  outputPath,
133507
- createdCollections
134068
+ planAndResources
133508
134069
  });
133509
134070
  default:
133510
134071
  return this.processStandardExtension({
133511
134072
  extension,
133512
134073
  blueprint,
133513
134074
  outputPath,
133514
- createdCollections
134075
+ planAndResources
133515
134076
  });
133516
134077
  }
133517
134078
  }
133518
- async processDashboardPage({ extension, blueprint, outputPath, createdCollections }) {
134079
+ async processDashboardPage(opts) {
133519
134080
  const decisionAgent = this.agentsFactory.getAgent({
133520
134081
  type: "DASHBOARD_DECISION"
133521
134082
  });
133522
- const decision = await decisionAgent.generate({
133523
- blueprint,
133524
- extension,
133525
- createdCollections
133526
- });
134083
+ const decision = await decisionAgent.generate(opts);
133527
134084
  const useAutoPatterns = decision.useAutoPatterns && decision.schema && decision.relevantCollectionId;
133528
- if (useAutoPatterns) {
133529
- console.log("\u{1F3AF} Using auto-patterns for dashboard generation");
133530
- const relevantCollection = createdCollections.find((c) => c.id === decision.relevantCollectionId);
133531
- if (!relevantCollection) {
133532
- throw new Error(`\u274C Collection with ID ${decision.relevantCollectionId} not found in created collections`);
133533
- }
133534
- const autoPatternsGenerator = this.agentsFactory.getAgent({
133535
- type: "AUTO_PATTERNS_GENERATOR"
133536
- });
133537
- this.emitEvent("agent:start", {
133538
- extension,
133539
- name: "AutoPatternsGenerator"
133540
- });
133541
- const files = autoPatternsGenerator.generate({
133542
- collection: relevantCollection,
133543
- decision,
133544
- extensionName: extension.name || ""
133545
- });
133546
- this.writeFile(files, outputPath);
133547
- const pagePath = files[0].path || "";
133548
- extensionGenerators_1.ExtensionFactory.generateExtension(extension, outputPath, pagePath);
133549
- this.emitEvent("agent:done", {
133550
- extension,
133551
- name: "AutoPatternsGenerator",
133552
- files
133553
- });
133554
- } else {
134085
+ if (!useAutoPatterns) {
133555
134086
  console.log("\u{1F3A8} Using custom code generation for dashboard");
133556
- this.emitEvent("scaffold:start", { extension });
133557
- const scaffolds = await (0, ditto_scaffolding_1.copyScaffoldingTemplate)(extension, outputPath);
133558
- if (!scaffolds || scaffolds.length === 0) {
133559
- throw new Error(`\u274C Failed to scaffold ${extension.type}`);
133560
- }
133561
- const scaffold = scaffolds[0];
133562
- this.emitEvent("scaffold:done", {
133563
- extension,
133564
- scaffoldPath: scaffolds.map((s) => s.path).join(", ")
133565
- });
133566
- const agent = this.agentsFactory.getAgent(extension);
133567
- this.emitEvent("agent:start", { extension, name: agent.name });
133568
- const files = await agent.generate({
133569
- extension,
133570
- blueprint,
133571
- scaffold,
133572
- createdCollections,
133573
- basePath: outputPath
133574
- });
133575
- this.writeFile(files, outputPath);
133576
- extensionGenerators_1.ExtensionFactory.generateExtension(extension, outputPath, scaffold.path);
133577
- this.emitEvent("agent:done", { extension, name: agent.name, files });
134087
+ await this.processStandardExtension(opts);
134088
+ return;
133578
134089
  }
134090
+ console.log("\u{1F3AF} Using auto-patterns for dashboard generation");
134091
+ const { extension, outputPath, planAndResources: { createdCollections = [] } = {} } = opts;
134092
+ const relevantCollection = createdCollections.find((c) => c.id === decision.relevantCollectionId);
134093
+ if (!relevantCollection) {
134094
+ throw new Error(`\u274C Collection with ID ${decision.relevantCollectionId} not found in created collections`);
134095
+ }
134096
+ const autoPatternsGenerator = this.agentsFactory.getAgent({
134097
+ type: "AUTO_PATTERNS_GENERATOR"
134098
+ });
134099
+ this.emitEvent("agent:start", {
134100
+ extension,
134101
+ name: "AutoPatternsGenerator"
134102
+ });
134103
+ const files = autoPatternsGenerator.generate({
134104
+ collection: relevantCollection,
134105
+ decision,
134106
+ extensionName: extension.name || ""
134107
+ });
134108
+ this.writeFile(files, outputPath);
134109
+ const pagePath = files[0].path || "";
134110
+ extensionGenerators_1.ExtensionFactory.generateExtension(extension, outputPath, pagePath);
134111
+ this.emitEvent("agent:done", {
134112
+ extension,
134113
+ name: "AutoPatternsGenerator",
134114
+ files
134115
+ });
133579
134116
  }
133580
- async processServicePlugin({ extension, blueprint, outputPath, createdCollections }) {
134117
+ async processServicePlugin({ extension, blueprint, outputPath, planAndResources }) {
133581
134118
  this.emitEvent("scaffold:start", { extension });
133582
134119
  const scaffolds = await (0, ditto_scaffolding_1.copyScaffoldingTemplate)(extension, outputPath);
133583
134120
  if (!scaffolds || scaffolds.length === 0) {
@@ -133592,7 +134129,7 @@ var require_orchestrator = __commonJS({
133592
134129
  extension,
133593
134130
  blueprint,
133594
134131
  outputPath,
133595
- createdCollections,
134132
+ planAndResources,
133596
134133
  scaffolds
133597
134134
  });
133598
134135
  }
@@ -133603,14 +134140,14 @@ var require_orchestrator = __commonJS({
133603
134140
  extension,
133604
134141
  blueprint,
133605
134142
  scaffold,
133606
- createdCollections,
134143
+ planAndResources,
133607
134144
  basePath: outputPath
133608
134145
  });
133609
134146
  this.writeFile(files, outputPath);
133610
134147
  extensionGenerators_1.ExtensionFactory.generateExtension(extension, outputPath, scaffold.path);
133611
134148
  this.emitEvent("agent:done", { extension, name: agent.name, files });
133612
134149
  }
133613
- async processStandardExtension({ extension, blueprint, outputPath, createdCollections }) {
134150
+ async processStandardExtension({ extension, blueprint, outputPath, planAndResources }) {
133614
134151
  this.emitEvent("scaffold:start", { extension });
133615
134152
  const scaffolds = await (0, ditto_scaffolding_1.copyScaffoldingTemplate)(extension, outputPath);
133616
134153
  if (!scaffolds || scaffolds.length === 0) {
@@ -133627,14 +134164,14 @@ var require_orchestrator = __commonJS({
133627
134164
  extension,
133628
134165
  blueprint,
133629
134166
  scaffold,
133630
- createdCollections,
134167
+ planAndResources,
133631
134168
  basePath: outputPath
133632
134169
  });
133633
134170
  this.writeFile(files, outputPath);
133634
134171
  extensionGenerators_1.ExtensionFactory.generateExtension(extension, outputPath, scaffold.path);
133635
134172
  this.emitEvent("agent:done", { extension, name: agent.name, files });
133636
134173
  }
133637
- async processMultipleServicePluginScaffolds({ extension, blueprint, outputPath, createdCollections, scaffolds }) {
134174
+ async processMultipleServicePluginScaffolds({ extension, blueprint, outputPath, planAndResources, scaffolds }) {
133638
134175
  if (!extension.relatedSpis || extension.relatedSpis.length === 0) {
133639
134176
  throw new Error("Service plugin extension must have related SPIs");
133640
134177
  }
@@ -133656,7 +134193,7 @@ var require_orchestrator = __commonJS({
133656
134193
  extension: spiExtension,
133657
134194
  blueprint,
133658
134195
  scaffold,
133659
- createdCollections,
134196
+ planAndResources,
133660
134197
  basePath: outputPath
133661
134198
  });
133662
134199
  this.writeFile(files, outputPath);
@@ -133686,7 +134223,7 @@ var require_orchestrator = __commonJS({
133686
134223
  blueprint: { extensions: [], appName: "", summary: "" },
133687
134224
  // Minimal blueprint for iteration
133688
134225
  outputPath,
133689
- createdCollections: [],
134226
+ planAndResources: {},
133690
134227
  scaffolds
133691
134228
  });
133692
134229
  return;
@@ -133753,19 +134290,16 @@ var require_orchestrator = __commonJS({
133753
134290
  });
133754
134291
  const start = Date.now();
133755
134292
  const { extensions = [] } = blueprint;
133756
- const createdCollections = [];
133757
- if (siteId && siteId !== "N/A" && accessToken) {
133758
- const planAndResourcesResult = await this.generatePlanAndResources(request);
133759
- createdCollections.push(...planAndResourcesResult.createdCollections);
133760
- }
134293
+ const planAndResources = await this.generatePlanAndResources(request);
133761
134294
  const parallelTasks = extensions.map((extension) => this.processExtension({
133762
134295
  extension,
133763
134296
  blueprint,
133764
134297
  outputPath,
133765
- createdCollections
134298
+ planAndResources
133766
134299
  }));
133767
- if (createdCollections.length > 0 && siteId && accessToken) {
133768
- parallelTasks.push(this.generateCMSData(request, createdCollections));
134300
+ const collections = planAndResources.createdCollections ?? [];
134301
+ if (collections.length > 0 && siteId && siteId !== "N/A" && accessToken) {
134302
+ parallelTasks.push(this.generateCMSData(request, collections));
133769
134303
  }
133770
134304
  await Promise.all(parallelTasks.filter(Boolean));
133771
134305
  await (0, extensionIndexer_1.generateMainExtensionsFile)(outputPath);