@wix/ditto-codegen-public 1.0.16 → 1.0.18
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 +998 -131
- package/package.json +2 -2
package/dist/out.js
CHANGED
|
@@ -114034,16 +114034,23 @@ var require_index_node = __commonJS({
|
|
|
114034
114034
|
var require_utils14 = __commonJS({
|
|
114035
114035
|
"dist/agents/utils.js"(exports2) {
|
|
114036
114036
|
"use strict";
|
|
114037
|
+
var __importDefault2 = exports2 && exports2.__importDefault || function(mod2) {
|
|
114038
|
+
return mod2 && mod2.__esModule ? mod2 : { "default": mod2 };
|
|
114039
|
+
};
|
|
114037
114040
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
114038
|
-
exports2.
|
|
114041
|
+
exports2.buildUserPromptForCodeGenerationAgent = exports2.getHttpClient = exports2.withCaching = exports2.FileSchema = void 0;
|
|
114042
|
+
exports2.loadRelevantFilesAsString = loadRelevantFilesAsString;
|
|
114039
114043
|
var zod_1 = require_zod();
|
|
114040
114044
|
var http_client_1 = require_index_node();
|
|
114041
|
-
|
|
114042
|
-
|
|
114045
|
+
var fs_1 = __importDefault2(require("fs"));
|
|
114046
|
+
var path_1 = __importDefault2(require("path"));
|
|
114047
|
+
var FileItemSchema = zod_1.z.object({
|
|
114048
|
+
operation: zod_1.z.enum(["insert", "update", "delete"]).describe("File operation: insert (new file), update (modify existing), delete (remove file)").default("insert"),
|
|
114049
|
+
path: zod_1.z.string().describe("Relative file path from project root").optional(),
|
|
114050
|
+
content: zod_1.z.string().describe("Complete file content as a string (for JSON files, stringify the object). Required for insert and update operations.").optional()
|
|
114043
114051
|
});
|
|
114044
|
-
exports2.
|
|
114045
|
-
|
|
114046
|
-
content: exports2.FileSchema.shape.content
|
|
114052
|
+
exports2.FileSchema = zod_1.z.object({
|
|
114053
|
+
files: zod_1.z.array(FileItemSchema).default([])
|
|
114047
114054
|
});
|
|
114048
114055
|
var withCaching = (ttl = "5m") => {
|
|
114049
114056
|
return {
|
|
@@ -114068,6 +114075,78 @@ var require_utils14 = __commonJS({
|
|
|
114068
114075
|
timeout: 6e6
|
|
114069
114076
|
});
|
|
114070
114077
|
exports2.getHttpClient = getHttpClient;
|
|
114078
|
+
function loadRelevantFiles(relevantFilePaths = [], basePath) {
|
|
114079
|
+
return relevantFilePaths.map((filePath) => {
|
|
114080
|
+
const fullPath = path_1.default.isAbsolute(basePath) ? path_1.default.join(basePath, filePath) : path_1.default.join(process.cwd(), basePath, filePath);
|
|
114081
|
+
try {
|
|
114082
|
+
if (!fs_1.default.existsSync(fullPath)) {
|
|
114083
|
+
return `Path: ${filePath}
|
|
114084
|
+
|
|
114085
|
+
[File does not exist]`;
|
|
114086
|
+
}
|
|
114087
|
+
const stats = fs_1.default.statSync(fullPath);
|
|
114088
|
+
if (stats.isDirectory()) {
|
|
114089
|
+
return `Path: ${filePath}
|
|
114090
|
+
|
|
114091
|
+
[Path is a directory, not a file]`;
|
|
114092
|
+
}
|
|
114093
|
+
const content = fs_1.default.readFileSync(fullPath, "utf8");
|
|
114094
|
+
return `Path: ${filePath}
|
|
114095
|
+
|
|
114096
|
+
${content}`;
|
|
114097
|
+
} catch (error) {
|
|
114098
|
+
return `Path: ${filePath}
|
|
114099
|
+
|
|
114100
|
+
[Could not read file: ${error instanceof Error ? error.message : "Unknown error"}]`;
|
|
114101
|
+
}
|
|
114102
|
+
});
|
|
114103
|
+
}
|
|
114104
|
+
function loadRelevantFilesAsString(relevantFilePaths = [], basePath) {
|
|
114105
|
+
const srcOnlyPaths = relevantFilePaths.filter((p) => {
|
|
114106
|
+
const normalized = path_1.default.normalize(p);
|
|
114107
|
+
return normalized.startsWith("src" + path_1.default.sep);
|
|
114108
|
+
});
|
|
114109
|
+
return loadRelevantFiles(srcOnlyPaths, basePath).join("\n\n---\n\n");
|
|
114110
|
+
}
|
|
114111
|
+
var buildUserPromptForCodeGenerationAgent = (params, primaryAction) => {
|
|
114112
|
+
const { extension, blueprint, scaffold, userRequestSummary, relevantFilePaths, createdCollections, basePath } = params;
|
|
114113
|
+
const contextSections = [];
|
|
114114
|
+
if (extension.name)
|
|
114115
|
+
contextSections.push(`Extension Name: ${extension.name}`);
|
|
114116
|
+
if (extension.description)
|
|
114117
|
+
contextSections.push(`Extension Description: ${extension.description}`);
|
|
114118
|
+
if (blueprint?.summary) {
|
|
114119
|
+
contextSections.push(`App Summary: ${blueprint.summary}`);
|
|
114120
|
+
}
|
|
114121
|
+
if (userRequestSummary) {
|
|
114122
|
+
contextSections.push(`
|
|
114123
|
+
## USER REQUEST
|
|
114124
|
+
${userRequestSummary}`);
|
|
114125
|
+
}
|
|
114126
|
+
if (relevantFilePaths) {
|
|
114127
|
+
const relevantFiles = loadRelevantFilesAsString(relevantFilePaths, basePath);
|
|
114128
|
+
contextSections.push(`
|
|
114129
|
+
## RELEVANT FILES
|
|
114130
|
+
${relevantFiles}`);
|
|
114131
|
+
}
|
|
114132
|
+
if (scaffold) {
|
|
114133
|
+
contextSections.push(`
|
|
114134
|
+
## CURRENT SCAFFOLDED FILE
|
|
114135
|
+
Path: ${scaffold.path}
|
|
114136
|
+
\`\`\`
|
|
114137
|
+
${scaffold.content}
|
|
114138
|
+
\`\`\``);
|
|
114139
|
+
}
|
|
114140
|
+
if (createdCollections) {
|
|
114141
|
+
contextSections.push(`
|
|
114142
|
+
## CREATED COLLECTIONS
|
|
114143
|
+
${JSON.stringify(createdCollections, null, 2)}`);
|
|
114144
|
+
}
|
|
114145
|
+
const userMessage = `${primaryAction}:
|
|
114146
|
+
${contextSections.join("\n")}`;
|
|
114147
|
+
return userMessage;
|
|
114148
|
+
};
|
|
114149
|
+
exports2.buildUserPromptForCodeGenerationAgent = buildUserPromptForCodeGenerationAgent;
|
|
114071
114150
|
}
|
|
114072
114151
|
});
|
|
114073
114152
|
|
|
@@ -114351,22 +114430,17 @@ var require_SPIAgent = __commonJS({
|
|
|
114351
114430
|
buildSystemPrompt(spiNames = []) {
|
|
114352
114431
|
return (0, servicePluginPrompt_1.getServicePluginPrompt)(spiNames);
|
|
114353
114432
|
}
|
|
114354
|
-
async generate(
|
|
114433
|
+
async generate(params) {
|
|
114434
|
+
const { extension, blueprint } = params;
|
|
114355
114435
|
const examples = (0, load_examples_1.loadExamples)([load_examples_1.types.ServicePluginExtension]);
|
|
114356
114436
|
const allSpiNames = extension.relatedSpis?.map((spi) => spi.name).filter((name) => !!name) || [];
|
|
114357
114437
|
const systemPrompt = `${this.buildSystemPrompt(allSpiNames)}
|
|
114358
114438
|
${examples}
|
|
114359
114439
|
`;
|
|
114360
114440
|
console.log(`SPI Agent System Prompt length: ${systemPrompt.length} (is that what you expect?)`);
|
|
114361
|
-
const
|
|
114362
|
-
|
|
114363
|
-
|
|
114364
|
-
App Summary: ${blueprint.summary}
|
|
114365
|
-
## CURRENT SCAFFOLDED FILE
|
|
114366
|
-
Path: ${scaffold.path}
|
|
114367
|
-
\`\`\`
|
|
114368
|
-
${scaffold.content}
|
|
114369
|
-
\`\`\``;
|
|
114441
|
+
const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
|
|
114442
|
+
const primaryAction = `Customize the Wix CLI service plugin scaffolding for the app ${appName}`;
|
|
114443
|
+
const userMessage = (0, utils_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
|
|
114370
114444
|
const model = (0, anthropic_1.createAnthropic)({
|
|
114371
114445
|
apiKey: this.apiKey
|
|
114372
114446
|
})("claude-sonnet-4-20250514");
|
|
@@ -114391,7 +114465,7 @@ ${scaffold.content}
|
|
|
114391
114465
|
maxRetries: 3,
|
|
114392
114466
|
temperature: 0
|
|
114393
114467
|
});
|
|
114394
|
-
return result.object;
|
|
114468
|
+
return result.object.files;
|
|
114395
114469
|
}
|
|
114396
114470
|
};
|
|
114397
114471
|
exports2.SPIAgent = SPIAgent;
|
|
@@ -115157,12 +115231,196 @@ dashboard.onBeforeUnload(() => {
|
|
|
115157
115231
|
}
|
|
115158
115232
|
});
|
|
115159
115233
|
|
|
115234
|
+
// dist/system-prompts/dashboardPage/buttonAndModalExamples.js
|
|
115235
|
+
var require_buttonAndModalExamples = __commonJS({
|
|
115236
|
+
"dist/system-prompts/dashboardPage/buttonAndModalExamples.js"(exports2) {
|
|
115237
|
+
"use strict";
|
|
115238
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
115239
|
+
exports2.buttonAndModalExamples = void 0;
|
|
115240
|
+
exports2.buttonAndModalExamples = `
|
|
115241
|
+
## Dashboard UI Components - Buttons and Modals Examples
|
|
115242
|
+
|
|
115243
|
+
### Essential Imports for Dashboard Components
|
|
115244
|
+
|
|
115245
|
+
\`\`\`typescript
|
|
115246
|
+
import React, { type FC, useState, useEffect } from 'react';
|
|
115247
|
+
import { dashboard } from '@wix/dashboard';
|
|
115248
|
+
import {
|
|
115249
|
+
Button,
|
|
115250
|
+
Page,
|
|
115251
|
+
WixDesignSystemProvider,
|
|
115252
|
+
Tabs,
|
|
115253
|
+
Card,
|
|
115254
|
+
Table,
|
|
115255
|
+
TableActionCell,
|
|
115256
|
+
TableToolbar,
|
|
115257
|
+
Modal,
|
|
115258
|
+
CustomModalLayout,
|
|
115259
|
+
FormField,
|
|
115260
|
+
Input,
|
|
115261
|
+
ToggleSwitch,
|
|
115262
|
+
Layout,
|
|
115263
|
+
Cell,
|
|
115264
|
+
Badge,
|
|
115265
|
+
Box,
|
|
115266
|
+
Text,
|
|
115267
|
+
} from '@wix/design-system';
|
|
115268
|
+
import '@wix/design-system/styles.global.css';
|
|
115269
|
+
import * as Icons from '@wix/wix-ui-icons-common';
|
|
115270
|
+
import { items } from "@wix/data";
|
|
115271
|
+
\`\`\`
|
|
115272
|
+
|
|
115273
|
+
### Button Examples
|
|
115274
|
+
|
|
115275
|
+
#### Primary Action Buttons
|
|
115276
|
+
\`\`\`typescript
|
|
115277
|
+
// Add/Create button with icon
|
|
115278
|
+
<Button
|
|
115279
|
+
size="small"
|
|
115280
|
+
prefixIcon={<Icons.Add />}
|
|
115281
|
+
onClick={() => openModal('item')}
|
|
115282
|
+
>
|
|
115283
|
+
Add Item
|
|
115284
|
+
</Button>
|
|
115285
|
+
|
|
115286
|
+
// Save button (primary)
|
|
115287
|
+
<Button
|
|
115288
|
+
priority="primary"
|
|
115289
|
+
onClick={handleSave}
|
|
115290
|
+
disabled={loading}
|
|
115291
|
+
>
|
|
115292
|
+
{loading ? 'Saving...' : 'Save'}
|
|
115293
|
+
</Button>
|
|
115294
|
+
\`\`\`
|
|
115295
|
+
|
|
115296
|
+
#### Table Action Buttons
|
|
115297
|
+
\`\`\`typescript
|
|
115298
|
+
const columns = [
|
|
115299
|
+
{ title: 'Name', render: (row: YourType) => row.name },
|
|
115300
|
+
{
|
|
115301
|
+
render: (row: YourType) => (
|
|
115302
|
+
<TableActionCell
|
|
115303
|
+
primaryAction={{
|
|
115304
|
+
text: 'Edit',
|
|
115305
|
+
onClick: () => openModal('item', row)
|
|
115306
|
+
}}
|
|
115307
|
+
secondaryActions={[
|
|
115308
|
+
{
|
|
115309
|
+
text: 'Delete',
|
|
115310
|
+
icon: <Icons.DeleteSmall />,
|
|
115311
|
+
onClick: () => handleDelete(row._id!)
|
|
115312
|
+
}
|
|
115313
|
+
]}
|
|
115314
|
+
/>
|
|
115315
|
+
)
|
|
115316
|
+
}
|
|
115317
|
+
];
|
|
115318
|
+
\`\`\`
|
|
115319
|
+
|
|
115320
|
+
### Modal Examples
|
|
115321
|
+
|
|
115322
|
+
#### State Management for Modals
|
|
115323
|
+
\`\`\`typescript
|
|
115324
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
115325
|
+
const [modalType, setModalType] = useState<'item'>('item');
|
|
115326
|
+
const [editingItem, setEditingItem] = useState<YourType | null>(null);
|
|
115327
|
+
const [formData, setFormData] = useState<any>({});
|
|
115328
|
+
|
|
115329
|
+
const openModal = (type: 'item', item?: YourType) => {
|
|
115330
|
+
setModalType(type);
|
|
115331
|
+
setEditingItem(item || null);
|
|
115332
|
+
|
|
115333
|
+
// Initialize form data based on editing or creating
|
|
115334
|
+
if (item) {
|
|
115335
|
+
setFormData({
|
|
115336
|
+
name: item.name,
|
|
115337
|
+
description: item.description,
|
|
115338
|
+
isActive: item.isActive,
|
|
115339
|
+
// ... other fields
|
|
115340
|
+
});
|
|
115341
|
+
} else {
|
|
115342
|
+
setFormData({
|
|
115343
|
+
name: '',
|
|
115344
|
+
description: '',
|
|
115345
|
+
isActive: true,
|
|
115346
|
+
// ... default values
|
|
115347
|
+
});
|
|
115348
|
+
}
|
|
115349
|
+
|
|
115350
|
+
setIsModalOpen(true);
|
|
115351
|
+
};
|
|
115352
|
+
|
|
115353
|
+
const closeModal = () => {
|
|
115354
|
+
setIsModalOpen(false);
|
|
115355
|
+
setEditingItem(null);
|
|
115356
|
+
setFormData({});
|
|
115357
|
+
};
|
|
115358
|
+
\`\`\`
|
|
115359
|
+
|
|
115360
|
+
#### Basic Modal with Form
|
|
115361
|
+
\`\`\`typescript
|
|
115362
|
+
<Modal isOpen={isModalOpen} onRequestClose={closeModal}>
|
|
115363
|
+
<CustomModalLayout
|
|
115364
|
+
primaryButtonText="Save"
|
|
115365
|
+
secondaryButtonText="Cancel"
|
|
115366
|
+
onCloseButtonClick={closeModal}
|
|
115367
|
+
primaryButtonOnClick={handleSave}
|
|
115368
|
+
secondaryButtonOnClick={closeModal}
|
|
115369
|
+
title={\`\${editingItem ? 'Edit' : 'Add'} Item\`}
|
|
115370
|
+
content={
|
|
115371
|
+
<Layout gap="24px">
|
|
115372
|
+
<Cell span={12}>
|
|
115373
|
+
<FormField label="Name">
|
|
115374
|
+
<Input
|
|
115375
|
+
value={formData.name || ''}
|
|
115376
|
+
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
|
115377
|
+
placeholder="Enter item name"
|
|
115378
|
+
/>
|
|
115379
|
+
</FormField>
|
|
115380
|
+
</Cell>
|
|
115381
|
+
<Cell span={12}>
|
|
115382
|
+
<FormField label="Description">
|
|
115383
|
+
<Input
|
|
115384
|
+
value={formData.description || ''}
|
|
115385
|
+
onChange={(e) => setFormData({ ...formData, description: e.target.value })}
|
|
115386
|
+
placeholder="Enter description"
|
|
115387
|
+
/>
|
|
115388
|
+
</FormField>
|
|
115389
|
+
</Cell>
|
|
115390
|
+
<Cell span={6}>
|
|
115391
|
+
<FormField label="Price">
|
|
115392
|
+
<Input
|
|
115393
|
+
type="number"
|
|
115394
|
+
value={formData.price || ''}
|
|
115395
|
+
onChange={(e) => setFormData({ ...formData, price: Number(e.target.value) })}
|
|
115396
|
+
placeholder="0.00"
|
|
115397
|
+
/>
|
|
115398
|
+
</FormField>
|
|
115399
|
+
</Cell>
|
|
115400
|
+
<Cell span={6}>
|
|
115401
|
+
<FormField label="Active" labelPlacement="right" stretchContent={false}>
|
|
115402
|
+
<ToggleSwitch
|
|
115403
|
+
checked={formData.isActive || false}
|
|
115404
|
+
onChange={() => setFormData({ ...formData, isActive: !formData.isActive })}
|
|
115405
|
+
/>
|
|
115406
|
+
</FormField>
|
|
115407
|
+
</Cell>
|
|
115408
|
+
</Layout>
|
|
115409
|
+
}
|
|
115410
|
+
/>
|
|
115411
|
+
</Modal>
|
|
115412
|
+
\`\`\`
|
|
115413
|
+
`;
|
|
115414
|
+
}
|
|
115415
|
+
});
|
|
115416
|
+
|
|
115160
115417
|
// dist/system-prompts/dashboardPage/wdsPackage.js
|
|
115161
115418
|
var require_wdsPackage = __commonJS({
|
|
115162
115419
|
"dist/system-prompts/dashboardPage/wdsPackage.js"(exports2) {
|
|
115163
115420
|
"use strict";
|
|
115164
115421
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
115165
115422
|
exports2.buildWdsSystemPrompt = buildWdsSystemPrompt;
|
|
115423
|
+
var buttonAndModalExamples_1 = require_buttonAndModalExamples();
|
|
115166
115424
|
var STORIES_URL = "https://mykolass.wixsite.com/storybook-builder/_functions/getStoriesList?production=true&library=wix-style-react";
|
|
115167
115425
|
function normalize(text) {
|
|
115168
115426
|
return (text || "").toLowerCase();
|
|
@@ -115215,11 +115473,147 @@ ${exampleLines}
|
|
|
115215
115473
|
<wds_reference>
|
|
115216
115474
|
<source>Wix Design System \u2014 filtered components</source>
|
|
115217
115475
|
${blocks}
|
|
115476
|
+
|
|
115477
|
+
${buttonAndModalExamples_1.buttonAndModalExamples}
|
|
115478
|
+
|
|
115218
115479
|
</wds_reference>`;
|
|
115219
115480
|
}
|
|
115220
115481
|
}
|
|
115221
115482
|
});
|
|
115222
115483
|
|
|
115484
|
+
// dist/system-prompts/dashboardPage/data.js
|
|
115485
|
+
var require_data = __commonJS({
|
|
115486
|
+
"dist/system-prompts/dashboardPage/data.js"(exports2) {
|
|
115487
|
+
"use strict";
|
|
115488
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
115489
|
+
exports2.dataPrompt = void 0;
|
|
115490
|
+
exports2.dataPrompt = `<wix_data_docs>
|
|
115491
|
+
Summary:
|
|
115492
|
+
- Read: items.query('Collection').filter/sort.limit.find() \u2192 { items, totalCount, hasNext }
|
|
115493
|
+
- Write: items.insert | update | remove. Ensure collection permissions allow the action
|
|
115494
|
+
|
|
115495
|
+
WixDataItem Interface:
|
|
115496
|
+
The WixDataItem is the base interface for all data items in Wix Data collections. It includes:
|
|
115497
|
+
- [key: string]: any - Additional custom fields defined in your collection schema
|
|
115498
|
+
|
|
115499
|
+
Access data using the collection schema:
|
|
115500
|
+
- Always use the exact field keys you defined in the collection schema.
|
|
115501
|
+
- YOU MUST use the collection id exactly as you defined it in the collection schema.
|
|
115502
|
+
- YOU MUST use the collection schema's exact field types for all operations (query, insert, update, remove)
|
|
115503
|
+
- All custom fields are stored in the [key: string]: any part of the WixDataItem interface
|
|
115504
|
+
|
|
115505
|
+
Example - Insert / Update / Delete (if permissions allow):
|
|
115506
|
+
|
|
115507
|
+
import { items } from "@wix/data";
|
|
115508
|
+
|
|
115509
|
+
export type WixDataItem = items.WixDataItem;
|
|
115510
|
+
|
|
115511
|
+
/**
|
|
115512
|
+
* Creates a new item in the collection
|
|
115513
|
+
* @param collectionId - ID of the collection
|
|
115514
|
+
* @param itemData - Data for the new item
|
|
115515
|
+
* @returns Promise<T> - The created item
|
|
115516
|
+
*/
|
|
115517
|
+
async function createItem<T extends WixDataItem>(collectionId: string, itemData: T): Promise<T> {
|
|
115518
|
+
try {
|
|
115519
|
+
const result = await items.insert(collectionId, itemData);
|
|
115520
|
+
return result as T;
|
|
115521
|
+
} catch (error) {
|
|
115522
|
+
console.error(\`Error creating \${collectionId}:\`, error);
|
|
115523
|
+
throw new Error(
|
|
115524
|
+
error instanceof Error ? error.message : \`Failed to create \${collectionId}\`
|
|
115525
|
+
);
|
|
115526
|
+
}
|
|
115527
|
+
}
|
|
115528
|
+
|
|
115529
|
+
/**
|
|
115530
|
+
* Retrieves all items from the collection
|
|
115531
|
+
* @param collectionId - ID of the collection
|
|
115532
|
+
* @returns Promise<items.WixDataResult<T>> - Query result with all items
|
|
115533
|
+
*/
|
|
115534
|
+
async function getAllItems<T extends WixDataItem>(collectionId: string): Promise<items.WixDataResult<T>> {
|
|
115535
|
+
try {
|
|
115536
|
+
const result = await items.query(collectionId).find();
|
|
115537
|
+
return result as items.WixDataResult<T>;
|
|
115538
|
+
} catch (error) {
|
|
115539
|
+
console.error(\`Error fetching \${collectionId}s:\`, error);
|
|
115540
|
+
throw new Error(
|
|
115541
|
+
error instanceof Error ? error.message : \`Failed to fetch \${collectionId}s\`
|
|
115542
|
+
);
|
|
115543
|
+
}
|
|
115544
|
+
}
|
|
115545
|
+
|
|
115546
|
+
/**
|
|
115547
|
+
* Retrieves a single item by ID
|
|
115548
|
+
* @param collectionId - ID of the collection
|
|
115549
|
+
* @param itemId - ID of the item to retrieve
|
|
115550
|
+
* @returns Promise<T | null> - The item or null if not found
|
|
115551
|
+
*/
|
|
115552
|
+
async function getItemById<T extends WixDataItem>(collectionId: string, itemId: string): Promise<T | null> {
|
|
115553
|
+
try {
|
|
115554
|
+
const result = await items.query(collectionId)
|
|
115555
|
+
.eq("_id", itemId)
|
|
115556
|
+
.find();
|
|
115557
|
+
|
|
115558
|
+
if (result.items.length > 0) {
|
|
115559
|
+
return result.items[0] as T;
|
|
115560
|
+
}
|
|
115561
|
+
return null;
|
|
115562
|
+
} catch (error) {
|
|
115563
|
+
console.error(\`Error fetching \${collectionId} by ID:\`, error);
|
|
115564
|
+
throw new Error(
|
|
115565
|
+
error instanceof Error ? error.message : \`Failed to fetch \${collectionId}\`
|
|
115566
|
+
);
|
|
115567
|
+
}
|
|
115568
|
+
}
|
|
115569
|
+
|
|
115570
|
+
/**
|
|
115571
|
+
* Updates an existing item
|
|
115572
|
+
* @param collectionId - ID of the collection
|
|
115573
|
+
* @param itemData - Updated item data (must include _id)
|
|
115574
|
+
* @returns Promise<T> - The updated item
|
|
115575
|
+
*/
|
|
115576
|
+
async function updateItem<T extends WixDataItem>(collectionId: string, itemData: T): Promise<T> {
|
|
115577
|
+
try {
|
|
115578
|
+
if (!itemData._id) {
|
|
115579
|
+
throw new Error(\`\${collectionId} ID is required for update\`);
|
|
115580
|
+
}
|
|
115581
|
+
|
|
115582
|
+
const result = await items.update(collectionId, itemData);
|
|
115583
|
+
return result as T;
|
|
115584
|
+
} catch (error) {
|
|
115585
|
+
console.error(\`Error updating \${collectionId}:\`, error);
|
|
115586
|
+
throw new Error(
|
|
115587
|
+
error instanceof Error ? error.message : \`Failed to update \${collectionId}\`
|
|
115588
|
+
);
|
|
115589
|
+
}
|
|
115590
|
+
}
|
|
115591
|
+
|
|
115592
|
+
/**
|
|
115593
|
+
* Deletes an item by ID
|
|
115594
|
+
* @param collectionId - ID of the collection
|
|
115595
|
+
* @param itemId - ID of the item to delete
|
|
115596
|
+
* @returns Promise<T> - The deleted item
|
|
115597
|
+
*/
|
|
115598
|
+
async function deleteItem<T extends WixDataItem>(collectionId: string, itemId: string): Promise<T> {
|
|
115599
|
+
try {
|
|
115600
|
+
if (!itemId) {
|
|
115601
|
+
throw new Error(\`\${collectionId} ID is required for deletion\`);
|
|
115602
|
+
}
|
|
115603
|
+
|
|
115604
|
+
const result = await items.remove(collectionId, itemId);
|
|
115605
|
+
return result as T;
|
|
115606
|
+
} catch (error) {
|
|
115607
|
+
console.error(\`Error deleting \${collectionId}:\`, error);
|
|
115608
|
+
throw new Error(
|
|
115609
|
+
error instanceof Error ? error.message : \`Failed to delete \${collectionId}\`
|
|
115610
|
+
);
|
|
115611
|
+
}
|
|
115612
|
+
}
|
|
115613
|
+
</wix_data_docs>`;
|
|
115614
|
+
}
|
|
115615
|
+
});
|
|
115616
|
+
|
|
115223
115617
|
// dist/system-prompts/dashboardPage/dashboardPagePrompt.js
|
|
115224
115618
|
var require_dashboardPagePrompt = __commonJS({
|
|
115225
115619
|
"dist/system-prompts/dashboardPage/dashboardPagePrompt.js"(exports2) {
|
|
@@ -115229,6 +115623,7 @@ var require_dashboardPagePrompt = __commonJS({
|
|
|
115229
115623
|
var ecomPackage_1 = require_ecomPackage();
|
|
115230
115624
|
var dashboardPackage_1 = require_dashboardPackage();
|
|
115231
115625
|
var wdsPackage_1 = require_wdsPackage();
|
|
115626
|
+
var data_1 = require_data();
|
|
115232
115627
|
var wdsPackage_2 = require_wdsPackage();
|
|
115233
115628
|
Object.defineProperty(exports2, "buildWdsSystemPrompt", { enumerable: true, get: function() {
|
|
115234
115629
|
return wdsPackage_2.buildWdsSystemPrompt;
|
|
@@ -115252,12 +115647,13 @@ var require_dashboardPagePrompt = __commonJS({
|
|
|
115252
115647
|
"SectionHeader",
|
|
115253
115648
|
"Heading",
|
|
115254
115649
|
"Modal",
|
|
115650
|
+
"Checkbox",
|
|
115255
115651
|
"Table",
|
|
115256
115652
|
"Badge",
|
|
115257
115653
|
"ToggleSwitch",
|
|
115258
115654
|
"InfoIcon"
|
|
115259
115655
|
];
|
|
115260
|
-
var dashboardPagePrompt = async () => {
|
|
115656
|
+
var dashboardPagePrompt = async (useData) => {
|
|
115261
115657
|
const wdsPrompt = await (0, wdsPackage_1.buildWdsSystemPrompt)(listOfWdsComponents);
|
|
115262
115658
|
return `
|
|
115263
115659
|
<WIXCLI_DASHBOARD_PAGE_SYSTEM_PROMPT>
|
|
@@ -115321,8 +115717,6 @@ ${dashboardPackage_1.dashboardPackage}
|
|
|
115321
115717
|
${ecomPackage_1.ecomPackage}
|
|
115322
115718
|
</api_references>
|
|
115323
115719
|
|
|
115324
|
-
|
|
115325
|
-
|
|
115326
115720
|
<wds_reference>
|
|
115327
115721
|
${wdsPrompt}
|
|
115328
115722
|
</wds_reference>
|
|
@@ -115336,30 +115730,7 @@ ${wdsPrompt}
|
|
|
115336
115730
|
- Do NOT use // @ts-ignore or // @ts-expect-error; fix the types or add guards instead
|
|
115337
115731
|
</typescript_quality_guidelines>
|
|
115338
115732
|
|
|
115339
|
-
|
|
115340
|
-
Summary:
|
|
115341
|
-
- Read: items.query('Collection').filter/sort.limit.find() \u2192 { items, totalCount, hasNext }
|
|
115342
|
-
- Write: items.insert | update | remove. Ensure collection permissions allow the action
|
|
115343
|
-
|
|
115344
|
-
Access data using the collection schema:
|
|
115345
|
-
- Always use the exact field keys you defined in the collection schema.
|
|
115346
|
-
- YOU MUST use the collection id exactly as you defined it in the collection schema.
|
|
115347
|
-
|
|
115348
|
-
Example - Insert / Update / Delete (if permissions allow):
|
|
115349
|
-
import { items } from '@wix/data';
|
|
115350
|
-
|
|
115351
|
-
async function addItem(collectionId: string, itemData: WixDataItem) {
|
|
115352
|
-
return items.insert(collectionId, itemData);
|
|
115353
|
-
}
|
|
115354
|
-
|
|
115355
|
-
async function renameItem(collectionId: string, itemData: WixDataItem) {
|
|
115356
|
-
await items.update(collectionId, itemData);
|
|
115357
|
-
}
|
|
115358
|
-
|
|
115359
|
-
async function deleteItem(collectionId: string, itemId: WixDataItem) {
|
|
115360
|
-
await items.remove(collectionId, itemId);
|
|
115361
|
-
}
|
|
115362
|
-
</wix_data_docs>
|
|
115733
|
+
${useData ? data_1.dataPrompt : ""}
|
|
115363
115734
|
</WIXCLI_DASHBOARD_PAGE_SYSTEM_PROMPT>
|
|
115364
115735
|
`;
|
|
115365
115736
|
};
|
|
@@ -115383,28 +115754,20 @@ var require_DashboardPageAgent = __commonJS({
|
|
|
115383
115754
|
this.apiKey = apiKey;
|
|
115384
115755
|
this.name = "DashboardPageAgent";
|
|
115385
115756
|
}
|
|
115386
|
-
async buildSystemPrompt() {
|
|
115387
|
-
return (0, dashboardPagePrompt_1.dashboardPagePrompt)();
|
|
115757
|
+
async buildSystemPrompt(useData) {
|
|
115758
|
+
return (0, dashboardPagePrompt_1.dashboardPagePrompt)(useData);
|
|
115388
115759
|
}
|
|
115389
|
-
async generate(
|
|
115760
|
+
async generate(params) {
|
|
115761
|
+
const { blueprint, createdCollections } = params;
|
|
115390
115762
|
const examples = (0, load_examples_1.loadExamples)([load_examples_1.types.DashboardPage]);
|
|
115391
|
-
const
|
|
115763
|
+
const useData = Boolean(createdCollections && createdCollections.length > 0);
|
|
115764
|
+
const systemPrompt = `${await this.buildSystemPrompt(useData)}
|
|
115392
115765
|
${examples}
|
|
115393
115766
|
`;
|
|
115394
115767
|
console.log(`Dashboard Agent System Prompt length: ${systemPrompt.length} (is that what you expect?)`);
|
|
115395
|
-
const
|
|
115396
|
-
|
|
115397
|
-
|
|
115398
|
-
App Summary: ${blueprint.summary}
|
|
115399
|
-
|
|
115400
|
-
## CREATED COLLECTIONS
|
|
115401
|
-
${JSON.stringify(createdCollections, null, 2)}
|
|
115402
|
-
|
|
115403
|
-
## CURRENT SCAFFOLDED FILE
|
|
115404
|
-
Path: ${scaffold.path}
|
|
115405
|
-
\`\`\`
|
|
115406
|
-
${scaffold.content}
|
|
115407
|
-
\`\`\``;
|
|
115768
|
+
const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
|
|
115769
|
+
const primaryAction = `Customize the Wix CLI dashboard page scaffolding for the app ${appName}`;
|
|
115770
|
+
const userMessage = (0, utils_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
|
|
115408
115771
|
const model = (0, anthropic_1.createAnthropic)({ apiKey: this.apiKey })("claude-sonnet-4-20250514");
|
|
115409
115772
|
const result = await (0, ai_1.generateObject)({
|
|
115410
115773
|
model,
|
|
@@ -115428,7 +115791,7 @@ ${scaffold.content}
|
|
|
115428
115791
|
maxRetries: 3,
|
|
115429
115792
|
temperature: 0
|
|
115430
115793
|
});
|
|
115431
|
-
return result.object;
|
|
115794
|
+
return result.object.files;
|
|
115432
115795
|
}
|
|
115433
115796
|
};
|
|
115434
115797
|
exports2.DashboardPageAgent = DashboardPageAgent;
|
|
@@ -115437,7 +115800,7 @@ ${scaffold.content}
|
|
|
115437
115800
|
});
|
|
115438
115801
|
|
|
115439
115802
|
// dist/system-prompts/planner/data.js
|
|
115440
|
-
var
|
|
115803
|
+
var require_data2 = __commonJS({
|
|
115441
115804
|
"dist/system-prompts/planner/data.js"(exports2) {
|
|
115442
115805
|
"use strict";
|
|
115443
115806
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -115454,6 +115817,7 @@ Your output must be strictly JSON that conforms to the provided schema (no markd
|
|
|
115454
115817
|
<constraints>
|
|
115455
115818
|
- Collection must include: id, displayName, displayField (when appropriate), fields[], permissions, and plugins[].
|
|
115456
115819
|
- Field definitions must use supported FieldType enums exactly as strings: TEXT, NUMBER, DATE, DATETIME, IMAGE, BOOLEAN, DOCUMENT, URL, RICH_TEXT, VIDEO, ANY, ARRAY_STRING, ARRAY_DOCUMENT, AUDIO, TIME, LANGUAGE, RICH_CONTENT, MEDIA_GALLERY, ADDRESS, PAGE_LINK, REFERENCE, MULTI_REFERENCE, OBJECT, ARRAY.
|
|
115820
|
+
- ALWAYS use REFERENCE fields when creating relationships between different CMS collections. ALL related fields must use REFERENCE type.
|
|
115457
115821
|
- ALWAYS use REFERENCE fields when the blueprint indicates relationships to Stores entities (products, categories, orders). Use TEXT fields for all other relationships.
|
|
115458
115822
|
- MANDATORY REFERENCE scenarios (you MUST use REFERENCE type):
|
|
115459
115823
|
- productId, product \u2192 REFERENCE to "Stores/Products"
|
|
@@ -115466,8 +115830,9 @@ Your output must be strictly JSON that conforms to the provided schema (no markd
|
|
|
115466
115830
|
- SITE_MEMBER_AUTHOR: Each member manages their own items.
|
|
115467
115831
|
- SITE_MEMBER: Any logged-in member.
|
|
115468
115832
|
- ANYONE: All site visitors, including anonymous.
|
|
115469
|
-
- Choose minimal but meaningful fields that fit the blueprint
|
|
115833
|
+
- Choose minimal but meaningful fields that fit the blueprint's domain. Do not add system fields like _id, _createdDate, etc.; they are created automatically.
|
|
115470
115834
|
- Ensure field keys are lowerCamelCase and ASCII. displayName values are human-readable.
|
|
115835
|
+
- Do NOT create fields that can be inferred or aggregated from other existing fields (e.g., don't create an "averageRating" field if you already have individual "rating" fields - calculate it dynamically).
|
|
115471
115836
|
- Do NOT create audit, transaction, log, history, or analytics collections unless the blueprint explicitly requests them.
|
|
115472
115837
|
- If the blueprint does not request persistent data, do not create any collections.
|
|
115473
115838
|
- For static or hardcoded behaviors, at most create one minimal read-only configuration collection only when strictly necessary.
|
|
@@ -115536,7 +115901,7 @@ var require_planner = __commonJS({
|
|
|
115536
115901
|
"use strict";
|
|
115537
115902
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
115538
115903
|
exports2.plannerPrompt = void 0;
|
|
115539
|
-
var data_1 =
|
|
115904
|
+
var data_1 = require_data2();
|
|
115540
115905
|
var plannerPrompt = () => `
|
|
115541
115906
|
<WIXCLI_PLANNER_SYSTEM_PROMPT>
|
|
115542
115907
|
${(0, data_1.cmsPlannerPrompt)()}
|
|
@@ -119122,18 +119487,12 @@ var require_SiteComponentAgent = __commonJS({
|
|
|
119122
119487
|
async buildSystemPrompt() {
|
|
119123
119488
|
return (0, siteComponentPrompt_1.siteComponentPrompt)();
|
|
119124
119489
|
}
|
|
119125
|
-
async generate(
|
|
119490
|
+
async generate(params) {
|
|
119491
|
+
const { blueprint } = params;
|
|
119126
119492
|
const systemPrompt = `${await this.buildSystemPrompt()}`;
|
|
119127
|
-
const
|
|
119128
|
-
|
|
119129
|
-
|
|
119130
|
-
App Summary: ${blueprint.summary}
|
|
119131
|
-
|
|
119132
|
-
## CURRENT SCAFFOLDED FILE
|
|
119133
|
-
Path: ${scaffold.path}
|
|
119134
|
-
\`\`\`
|
|
119135
|
-
${scaffold.content}
|
|
119136
|
-
\`\`\``;
|
|
119493
|
+
const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
|
|
119494
|
+
const primaryAction = `Customize the Wix CLI site component scaffolding for the app ${appName}`;
|
|
119495
|
+
const userMessage = (0, utils_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
|
|
119137
119496
|
const model = (0, anthropic_1.createAnthropic)({ apiKey: this.apiKey })("claude-sonnet-4-20250514");
|
|
119138
119497
|
const result = await (0, ai_1.generateObject)({
|
|
119139
119498
|
model,
|
|
@@ -119157,7 +119516,7 @@ ${scaffold.content}
|
|
|
119157
119516
|
maxRetries: 3,
|
|
119158
119517
|
temperature: 0
|
|
119159
119518
|
});
|
|
119160
|
-
return result.object;
|
|
119519
|
+
return result.object.files;
|
|
119161
119520
|
}
|
|
119162
119521
|
};
|
|
119163
119522
|
exports2.SiteComponentAgent = SiteComponentAgent;
|
|
@@ -119165,6 +119524,261 @@ ${scaffold.content}
|
|
|
119165
119524
|
}
|
|
119166
119525
|
});
|
|
119167
119526
|
|
|
119527
|
+
// dist/system-prompts/iterationAgent/iterationAgentPrompt.js
|
|
119528
|
+
var require_iterationAgentPrompt = __commonJS({
|
|
119529
|
+
"dist/system-prompts/iterationAgent/iterationAgentPrompt.js"(exports2) {
|
|
119530
|
+
"use strict";
|
|
119531
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
119532
|
+
exports2.iterationAgentPrompt = void 0;
|
|
119533
|
+
var iterationAgentPrompt = () => `
|
|
119534
|
+
<WIXCLI_ITERATION_AGENT_SYSTEM_PROMPT>
|
|
119535
|
+
|
|
119536
|
+
<role>
|
|
119537
|
+
You are an iteration agent for a Wix app code generation system.
|
|
119538
|
+
Given the full chat history, current user request, blueprint, and all project files:
|
|
119539
|
+
1. Generate a clear summary of what the user wants to achieve
|
|
119540
|
+
2. Identify which existing extensions should be triggered to handle this request
|
|
119541
|
+
3. Map each triggered extension to the relevant file paths it needs to modify
|
|
119542
|
+
4. Propose new extensions if the request requires functionality not covered by existing ones
|
|
119543
|
+
</role>
|
|
119544
|
+
|
|
119545
|
+
<supported_extension_types>
|
|
119546
|
+
|
|
119547
|
+
<dashboard_page>
|
|
119548
|
+
**Use when:**
|
|
119549
|
+
- User wants to create a management interface/admin panel
|
|
119550
|
+
- Need to display data tables, forms, or configuration screens
|
|
119551
|
+
- Building settings pages, analytics dashboards, or content management interfaces
|
|
119552
|
+
- Example: 'Create a dashboard to manage FAQ items', 'Add settings page for the app'
|
|
119553
|
+
</dashboard_page>
|
|
119554
|
+
|
|
119555
|
+
<site_component>
|
|
119556
|
+
**Use when:**
|
|
119557
|
+
- User wants to create a custom UI component for the site frontend
|
|
119558
|
+
- Need to build interactive widgets, forms, or display components for visitors
|
|
119559
|
+
- Creating custom elements that appear on the site (not admin interfaces)
|
|
119560
|
+
- Building components that integrate with site data or user interactions
|
|
119561
|
+
- Example: 'Create a product showcase widget', 'Add a contact form component', 'Build a testimonial slider'
|
|
119562
|
+
</site_component>
|
|
119563
|
+
|
|
119564
|
+
<service_plugin>
|
|
119565
|
+
**Use when:**
|
|
119566
|
+
- User needs custom business logic for eCommerce (fees, shipping, discounts, validations)
|
|
119567
|
+
- Integrating with external payment providers
|
|
119568
|
+
- Custom pricing calculations for bookings
|
|
119569
|
+
- Form validation logic
|
|
119570
|
+
- Example: 'Calculate custom shipping rates', 'Add payment validation', 'Custom discount rules'
|
|
119571
|
+
|
|
119572
|
+
**Available SPI Names (choose appropriate ones for relatedSpis):**
|
|
119573
|
+
- "ecom.shippingRates.getShippingRates" - For custom shipping rate calculations
|
|
119574
|
+
- "ecom.additionalFees.calculateAdditionalFees" - For calculating additional fees (handling, processing, etc.)
|
|
119575
|
+
- "ecom.paymentSettings.getPaymentSettings" - For payment configuration and 3D Secure settings
|
|
119576
|
+
- "ecom.validations.getValidationViolations" - For cart and checkout validations
|
|
119577
|
+
- "ecom.customTriggers.getEligibleTriggers" - For custom discount trigger logic
|
|
119578
|
+
- "ecom.customTriggers.listTriggers" - For listing available custom discount triggers
|
|
119579
|
+
- "ecom.giftCardsProvider.redeem" - For gift card redemption logic
|
|
119580
|
+
- "ecom.giftCardsProvider._void" - For voiding gift card transactions
|
|
119581
|
+
- "ecom.giftCardsProvider.getBalance" - For checking gift card balances
|
|
119582
|
+
- "ecom.taxCalculationProvider.calculateTax" - For custom tax calculations
|
|
119583
|
+
- "ecom.recommendationsProvider.getRecommendations" - For product recommendations
|
|
119584
|
+
- "ecom.catalog.getCatalogItems" - For external catalog integration
|
|
119585
|
+
|
|
119586
|
+
**SPI Selection Guidelines:**
|
|
119587
|
+
- For shipping-related requests \u2192 use "ecom.shippingRates.getShippingRates"
|
|
119588
|
+
- For fee calculations \u2192 use "ecom.additionalFees.calculateAdditionalFees"
|
|
119589
|
+
- For payment processing \u2192 use "ecom.paymentSettings.getPaymentSettings"
|
|
119590
|
+
- For cart/checkout validation \u2192 use "ecom.validations.getValidationViolations"
|
|
119591
|
+
- For discount logic \u2192 use "ecom.customTriggers.getEligibleTriggers" or "ecom.customTriggers.listTriggers"
|
|
119592
|
+
- For gift card functionality \u2192 use appropriate "ecom.giftCardsProvider.*" methods
|
|
119593
|
+
- For tax calculations \u2192 use "ecom.taxCalculationProvider.calculateTax"
|
|
119594
|
+
- For product recommendations \u2192 use "ecom.recommendationsProvider.getRecommendations"
|
|
119595
|
+
- For external catalog \u2192 use "ecom.catalog.getCatalogItems"
|
|
119596
|
+
</service_plugin>
|
|
119597
|
+
|
|
119598
|
+
</supported_extension_types>
|
|
119599
|
+
|
|
119600
|
+
<extension_selection_logic>
|
|
119601
|
+
|
|
119602
|
+
<selection_rules>
|
|
119603
|
+
1. **For UI/Admin interfaces**: Use DASHBOARD_PAGE
|
|
119604
|
+
2. **For site frontend components**: Use SITE_COMPONENT
|
|
119605
|
+
3. **For eCommerce business logic**: Use SERVICE_PLUGIN
|
|
119606
|
+
4. **For management interfaces**: Use DASHBOARD_PAGE
|
|
119607
|
+
5. **For eCommerce features**: Combine SERVICE_PLUGIN (logic) + DASHBOARD_PAGE (configuration UI)
|
|
119608
|
+
6. **For site features**: Combine SITE_COMPONENT (frontend) + SERVICE_PLUGIN (backend logic) + DASHBOARD_PAGE (admin interface)
|
|
119609
|
+
</selection_rules>
|
|
119610
|
+
|
|
119611
|
+
<common_patterns>
|
|
119612
|
+
- **eCommerce Extensions**: SERVICE_PLUGIN + DASHBOARD_PAGE
|
|
119613
|
+
- **Configuration/Settings Apps**: DASHBOARD_PAGE only
|
|
119614
|
+
- **Site Frontend Features**: SITE_COMPONENT only
|
|
119615
|
+
- **Full-Featured Apps**: SITE_COMPONENT + SERVICE_PLUGIN + DASHBOARD_PAGE
|
|
119616
|
+
</common_patterns>
|
|
119617
|
+
|
|
119618
|
+
</extension_selection_logic>
|
|
119619
|
+
|
|
119620
|
+
<constraints>
|
|
119621
|
+
- Return the JSON schema with currentExtensions, additionalExtensions, and summary
|
|
119622
|
+
- Only propose additional extensions if existing ones cannot fulfill the user's request
|
|
119623
|
+
- Be specific about which file paths are relevant for each current extension (all extension types)
|
|
119624
|
+
- Consider the full chat history context when making decisions
|
|
119625
|
+
- Prioritize reusing existing extensions over creating new ones
|
|
119626
|
+
- **SUPPORTED EXTENSION TYPES ONLY**: DASHBOARD_PAGE, SERVICE_PLUGIN, and SITE_COMPONENT
|
|
119627
|
+
- **IMPORTANT**: The "type" field is ONLY for SERVICE_PLUGIN extensions - specify the SPI type
|
|
119628
|
+
- The "paths" field is for ALL extension types - specify relevant file paths to modify
|
|
119629
|
+
- Choose SPI types based on the specific eCommerce functionality requested (shipping, fees, validation, etc.)
|
|
119630
|
+
- Each extension should have a clear relevantUserRequest explaining what part of the request it addresses
|
|
119631
|
+
- If files already exist for an extension (e.g., dashboard page component files or a service plugin \`plugin.ts\` under the relevant SPI directory), you MUST treat it as a currentExtensions item and update it, NOT as an additionalExtensions item
|
|
119632
|
+
- For currentExtensions, ensure relevantUserRequest precisely reflects the change to be applied in those files (e.g., "Update static fee from 5 ILS to 10 ILS"), not a generic description
|
|
119633
|
+
- Propose additionalExtensions ONLY when there is no existing file that matches the requested capability; avoid duplicates like proposing a new \`ecom.additionalFees.calculateAdditionalFees\` when one already exists in the project
|
|
119634
|
+
</constraints>
|
|
119635
|
+
|
|
119636
|
+
<output_format>
|
|
119637
|
+
The response must be a valid JSON object matching the IterationPlanSchema:
|
|
119638
|
+
|
|
119639
|
+
**Required Structure:**
|
|
119640
|
+
{
|
|
119641
|
+
"currentExtensions": [
|
|
119642
|
+
{
|
|
119643
|
+
"extensionName": "SERVICE_PLUGIN",
|
|
119644
|
+
"relatedSpis": ["ecom.shippingRates.getShippingRates"], // Only for SERVICE_PLUGIN extensions
|
|
119645
|
+
"paths": ["src/backend/service-plugins/shipping/custom-rates/plugin.ts"],
|
|
119646
|
+
"relevantUserRequest": "Calculate shipping rates based on product weight"
|
|
119647
|
+
},
|
|
119648
|
+
{
|
|
119649
|
+
"extensionName": "DASHBOARD_PAGE",
|
|
119650
|
+
"paths": ["src/dashboard/pages/AdminPage.tsx", "src/dashboard/components/SettingsForm.tsx"],
|
|
119651
|
+
"relevantUserRequest": "Provide admin interface for managing shipping settings"
|
|
119652
|
+
},
|
|
119653
|
+
{
|
|
119654
|
+
"extensionName": "SITE_COMPONENT",
|
|
119655
|
+
"paths": ["src/site/components/ProductShowcase/component.tsx"],
|
|
119656
|
+
"relevantUserRequest": "Create a product showcase widget for the site frontend"
|
|
119657
|
+
}
|
|
119658
|
+
],
|
|
119659
|
+
"additionalExtensions": [
|
|
119660
|
+
{
|
|
119661
|
+
"extensionName": "SERVICE_PLUGIN",
|
|
119662
|
+
"relatedSpis": ["ecom.additionalFees.calculateAdditionalFees"], // Only for SERVICE_PLUGIN extensions
|
|
119663
|
+
"relevantUserRequest": "Add handling fees for fragile items"
|
|
119664
|
+
}
|
|
119665
|
+
],
|
|
119666
|
+
"summary": "User wants to implement custom shipping rates and add handling fees for their eCommerce store"
|
|
119667
|
+
}
|
|
119668
|
+
|
|
119669
|
+
**Key Points:**
|
|
119670
|
+
- currentExtensions: Existing extensions that should be triggered/modified (use extensionName of "SERVICE_PLUGIN", "DASHBOARD_PAGE", or "SITE_COMPONENT")
|
|
119671
|
+
- additionalExtensions: New extensions that need to be created (use extensionName of "SERVICE_PLUGIN", "DASHBOARD_PAGE", or "SITE_COMPONENT")
|
|
119672
|
+
- summary: Brief summary combining the chat history and current user request
|
|
119673
|
+
- "relatedSpis" field: ONLY for SERVICE_PLUGIN extensions - specify the SPI name
|
|
119674
|
+
- "paths" field: For ALL extension types - specify relevant file paths to modify
|
|
119675
|
+
- For currentExtensions, always include paths; for additionalExtensions, paths are not needed
|
|
119676
|
+
</output_format>
|
|
119677
|
+
|
|
119678
|
+
</WIXCLI_ITERATION_AGENT_SYSTEM_PROMPT>
|
|
119679
|
+
`;
|
|
119680
|
+
exports2.iterationAgentPrompt = iterationAgentPrompt;
|
|
119681
|
+
}
|
|
119682
|
+
});
|
|
119683
|
+
|
|
119684
|
+
// dist/agents/IterationAgent.js
|
|
119685
|
+
var require_IterationAgent = __commonJS({
|
|
119686
|
+
"dist/agents/IterationAgent.js"(exports2) {
|
|
119687
|
+
"use strict";
|
|
119688
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
119689
|
+
exports2.IterationAgent = exports2.IterationPlanSchema = exports2.AdditionalExtensionSchema = exports2.CurrentExtensionSchema = void 0;
|
|
119690
|
+
var anthropic_1 = require_dist5();
|
|
119691
|
+
var ai_1 = require_dist7();
|
|
119692
|
+
var zod_1 = require_zod();
|
|
119693
|
+
var utils_1 = require_utils14();
|
|
119694
|
+
var types_1 = require_types_impl();
|
|
119695
|
+
var iterationAgentPrompt_1 = require_iterationAgentPrompt();
|
|
119696
|
+
exports2.CurrentExtensionSchema = zod_1.z.object({
|
|
119697
|
+
extensionName: zod_1.z.nativeEnum(types_1.ExtensionType).describe("The extension kind to trigger"),
|
|
119698
|
+
relatedSpis: zod_1.z.array(zod_1.z.string()).optional().describe("Optional value, only for SPI extensions - specify the SPI types"),
|
|
119699
|
+
paths: zod_1.z.array(zod_1.z.string()).describe("Paths relevant for this extension"),
|
|
119700
|
+
relevantUserRequest: zod_1.z.string().describe("What part of the user request this extension addresses")
|
|
119701
|
+
});
|
|
119702
|
+
exports2.AdditionalExtensionSchema = zod_1.z.object({
|
|
119703
|
+
extensionName: zod_1.z.nativeEnum(types_1.ExtensionType).describe("The extension kind to add"),
|
|
119704
|
+
relatedSpis: zod_1.z.array(zod_1.z.string()).optional().describe("Optional value, only for SPI extensions - specify the SPI types"),
|
|
119705
|
+
relevantUserRequest: zod_1.z.string().describe("What part of the user request this extension addresses")
|
|
119706
|
+
});
|
|
119707
|
+
exports2.IterationPlanSchema = zod_1.z.object({
|
|
119708
|
+
currentExtensions: zod_1.z.array(exports2.CurrentExtensionSchema).describe("Existing extensions to be triggered"),
|
|
119709
|
+
additionalExtensions: zod_1.z.array(exports2.AdditionalExtensionSchema).describe("New extensions to be created"),
|
|
119710
|
+
summary: zod_1.z.string().describe("Summary of the chat with the user request")
|
|
119711
|
+
});
|
|
119712
|
+
var IterationAgent = class {
|
|
119713
|
+
constructor(apiKey) {
|
|
119714
|
+
this.apiKey = apiKey;
|
|
119715
|
+
this.name = "IterationAgent";
|
|
119716
|
+
}
|
|
119717
|
+
buildSystemPrompt() {
|
|
119718
|
+
return (0, iterationAgentPrompt_1.iterationAgentPrompt)();
|
|
119719
|
+
}
|
|
119720
|
+
mapExtensionType(extensionName) {
|
|
119721
|
+
switch (extensionName) {
|
|
119722
|
+
case "SERVICE_PLUGIN":
|
|
119723
|
+
return types_1.ExtensionType.SERVICE_PLUGIN;
|
|
119724
|
+
case "DASHBOARD_PAGE":
|
|
119725
|
+
return types_1.ExtensionType.DASHBOARD_PAGE;
|
|
119726
|
+
case "SITE_COMPONENT":
|
|
119727
|
+
return types_1.ExtensionType.SITE_COMPONENT;
|
|
119728
|
+
default:
|
|
119729
|
+
throw new Error(`Unsupported extension type: ${extensionName}`);
|
|
119730
|
+
}
|
|
119731
|
+
}
|
|
119732
|
+
async generate(outputPath, candidateFilePaths, currentUserRequest, chatHistory) {
|
|
119733
|
+
const model = (0, anthropic_1.createAnthropic)({ apiKey: this.apiKey })("claude-3-5-haiku-latest");
|
|
119734
|
+
const historyStr = (chatHistory || []).map((m) => `${m.role.toUpperCase()}: ${m.text}`).join("\n\n");
|
|
119735
|
+
const allFilesContent = (0, utils_1.loadRelevantFilesAsString)(candidateFilePaths, outputPath);
|
|
119736
|
+
const userContent = [
|
|
119737
|
+
`
|
|
119738
|
+
Full Chat History:
|
|
119739
|
+
${historyStr}`,
|
|
119740
|
+
`
|
|
119741
|
+
Current User Request: ${currentUserRequest}`,
|
|
119742
|
+
`
|
|
119743
|
+
All Project Files (relative to output path):
|
|
119744
|
+
${candidateFilePaths.slice(0, 1e3).join("\n")}`,
|
|
119745
|
+
`
|
|
119746
|
+
All Project Files Content:
|
|
119747
|
+
${allFilesContent}`
|
|
119748
|
+
].join("\n\n");
|
|
119749
|
+
const result = await (0, ai_1.generateObject)({
|
|
119750
|
+
model,
|
|
119751
|
+
schema: exports2.IterationPlanSchema,
|
|
119752
|
+
messages: [
|
|
119753
|
+
{
|
|
119754
|
+
role: "system",
|
|
119755
|
+
content: this.buildSystemPrompt(),
|
|
119756
|
+
providerOptions: (0, utils_1.withCaching)("1h")
|
|
119757
|
+
},
|
|
119758
|
+
{ role: "user", content: userContent }
|
|
119759
|
+
],
|
|
119760
|
+
maxRetries: 3,
|
|
119761
|
+
temperature: 0,
|
|
119762
|
+
experimental_telemetry: { isEnabled: true, functionId: this.name }
|
|
119763
|
+
});
|
|
119764
|
+
const resultObject = result.object;
|
|
119765
|
+
resultObject.currentExtensions = result.object.currentExtensions.map((ext) => ({
|
|
119766
|
+
...ext,
|
|
119767
|
+
extensionName: this.mapExtensionType(ext.extensionName)
|
|
119768
|
+
}));
|
|
119769
|
+
resultObject.additionalExtensions = result.object.additionalExtensions.map((ext) => ({
|
|
119770
|
+
...ext,
|
|
119771
|
+
extensionName: this.mapExtensionType(ext.extensionName)
|
|
119772
|
+
}));
|
|
119773
|
+
console.log("IterationAgent result:", JSON.stringify(resultObject, null, 2));
|
|
119774
|
+
return resultObject;
|
|
119775
|
+
}
|
|
119776
|
+
};
|
|
119777
|
+
exports2.IterationAgent = IterationAgent;
|
|
119778
|
+
exports2.default = IterationAgent;
|
|
119779
|
+
}
|
|
119780
|
+
});
|
|
119781
|
+
|
|
119168
119782
|
// dist/agents/AgentsFactory.js
|
|
119169
119783
|
var require_AgentsFactory = __commonJS({
|
|
119170
119784
|
"dist/agents/AgentsFactory.js"(exports2) {
|
|
@@ -119181,6 +119795,7 @@ var require_AgentsFactory = __commonJS({
|
|
|
119181
119795
|
var CMSAgent_1 = require_CMSAgent();
|
|
119182
119796
|
var CMSDataAgent_1 = require_CMSDataAgent();
|
|
119183
119797
|
var SiteComponentAgent_1 = __importDefault2(require_SiteComponentAgent());
|
|
119798
|
+
var IterationAgent_1 = __importDefault2(require_IterationAgent());
|
|
119184
119799
|
var AgentsFactory = class {
|
|
119185
119800
|
constructor(apiKey) {
|
|
119186
119801
|
this.apiKey = apiKey;
|
|
@@ -119197,6 +119812,8 @@ var require_AgentsFactory = __commonJS({
|
|
|
119197
119812
|
return new CMSDataAgent_1.CMSDataAgent(this.apiKey);
|
|
119198
119813
|
case "PLANNER":
|
|
119199
119814
|
return new PlannerAgent_1.default(this.apiKey);
|
|
119815
|
+
case "ITERATION_AGENT":
|
|
119816
|
+
return new IterationAgent_1.default(this.apiKey);
|
|
119200
119817
|
case types_1.ExtensionType.SITE_COMPONENT:
|
|
119201
119818
|
return new SiteComponentAgent_1.default(this.apiKey);
|
|
119202
119819
|
default:
|
|
@@ -119225,6 +119842,9 @@ var require_cli_listeners = __commonJS({
|
|
|
119225
119842
|
console.log(`\u{1F527} Extensions to generate: ${info.extensionsCount}
|
|
119226
119843
|
`);
|
|
119227
119844
|
});
|
|
119845
|
+
orchestrator.onEvent("start:iteration", () => {
|
|
119846
|
+
console.log("\n\u{1F680} Starting code iteration for app");
|
|
119847
|
+
});
|
|
119228
119848
|
orchestrator.onEvent("scaffold:start", ({ extension }) => {
|
|
119229
119849
|
console.log(`\u{1F4E6} Scaffolding ${extId(extension)}...`);
|
|
119230
119850
|
});
|
|
@@ -119268,8 +119888,22 @@ var require_cli_listeners = __commonJS({
|
|
|
119268
119888
|
timer.delete("PlannerAgent");
|
|
119269
119889
|
console.log(`\u{1F916}\u2714\uFE0F Generated plan in ${duration / 1e3}s`);
|
|
119270
119890
|
});
|
|
119891
|
+
orchestrator.onEvent("iterationAgent:start", () => {
|
|
119892
|
+
timer.set("IterationAgent", Date.now());
|
|
119893
|
+
console.log("\u{1F916} Generating iteration plan...");
|
|
119894
|
+
});
|
|
119895
|
+
orchestrator.onEvent("iterationAgent:done", ({ newExtensions, currentExtensions }) => {
|
|
119896
|
+
const duration = Date.now() - timer.get("IterationAgent");
|
|
119897
|
+
timer.delete("IterationAgent");
|
|
119898
|
+
console.log(`\u{1F916}\u2714\uFE0F Generated ${newExtensions} new extensions and modified ${currentExtensions} extensions in ${duration / 1e3}s`);
|
|
119899
|
+
});
|
|
119271
119900
|
orchestrator.onEvent("finish", ({ outputPath, durationMs }) => {
|
|
119272
119901
|
console.log(`
|
|
119902
|
+
\u2705 Done in ${durationMs}ms`);
|
|
119903
|
+
console.log(`\u{1F4C1} Files generated in: ${outputPath}`);
|
|
119904
|
+
});
|
|
119905
|
+
orchestrator.onEvent("finish:iteration", ({ outputPath, durationMs }) => {
|
|
119906
|
+
console.log(`
|
|
119273
119907
|
\u2705 Done in ${durationMs}ms`);
|
|
119274
119908
|
console.log(`\u{1F4C1} Files generated in: ${outputPath}`);
|
|
119275
119909
|
});
|
|
@@ -119575,6 +120209,10 @@ ${b}
|
|
|
119575
120209
|
)`).join("\n")};
|
|
119576
120210
|
`;
|
|
119577
120211
|
const filePath = path_1.default.join(outputPath, "src", "extensions.ts");
|
|
120212
|
+
const dir = path_1.default.dirname(filePath);
|
|
120213
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
120214
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
120215
|
+
}
|
|
119578
120216
|
fs_1.default.writeFileSync(filePath, content);
|
|
119579
120217
|
console.log(`\u{1F4DD} Generated: ${path_1.default.relative(outputPath, filePath)}`);
|
|
119580
120218
|
}
|
|
@@ -119868,24 +120506,15 @@ var require_orchestrator = __commonJS({
|
|
|
119868
120506
|
return mod2 && mod2.__esModule ? mod2 : { "default": mod2 };
|
|
119869
120507
|
};
|
|
119870
120508
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
119871
|
-
exports2.DittoOrchestrator =
|
|
120509
|
+
exports2.DittoOrchestrator = void 0;
|
|
119872
120510
|
var path_1 = __importDefault2(require("path"));
|
|
119873
120511
|
var events_1 = require("events");
|
|
119874
120512
|
var ditto_scaffolding_1 = require_dist11();
|
|
119875
120513
|
var fs_1 = __importDefault2(require("fs"));
|
|
119876
120514
|
var extensions_file_1 = require_extensions_file();
|
|
119877
|
-
var zod_1 = require_zod();
|
|
119878
120515
|
var ValidatorFactory_1 = __importDefault2(require_ValidatorFactory());
|
|
119879
120516
|
var FixerFactory_1 = __importDefault2(require_FixerFactory());
|
|
119880
120517
|
var MAX_FIX_ATTEMPTS = 3;
|
|
119881
|
-
exports2.FileSchema = zod_1.z.object({
|
|
119882
|
-
path: zod_1.z.string().describe("Relative file path from project root"),
|
|
119883
|
-
content: zod_1.z.string().describe("Complete file content as a string (for JSON files, stringify the object)"),
|
|
119884
|
-
type: zod_1.z.enum(["typescript", "json"]).describe("File type for syntax highlighting")
|
|
119885
|
-
});
|
|
119886
|
-
exports2.FilesSchema = zod_1.z.object({
|
|
119887
|
-
files: zod_1.z.array(exports2.FileSchema).describe("Array of files to generate")
|
|
119888
|
-
});
|
|
119889
120518
|
var DittoOrchestrator = class extends events_1.EventEmitter {
|
|
119890
120519
|
constructor(agentsFactory, apiKey) {
|
|
119891
120520
|
super();
|
|
@@ -119900,21 +120529,54 @@ var require_orchestrator = __commonJS({
|
|
|
119900
120529
|
emitEvent(event, payload) {
|
|
119901
120530
|
return super.emit(event, payload);
|
|
119902
120531
|
}
|
|
119903
|
-
|
|
119904
|
-
|
|
119905
|
-
|
|
119906
|
-
|
|
119907
|
-
|
|
119908
|
-
|
|
119909
|
-
|
|
119910
|
-
|
|
119911
|
-
|
|
119912
|
-
|
|
119913
|
-
|
|
119914
|
-
|
|
120532
|
+
writeFile(files, outputPath) {
|
|
120533
|
+
if (!files) {
|
|
120534
|
+
console.warn("\u26A0\uFE0F Skipping file operation: no files provided");
|
|
120535
|
+
return;
|
|
120536
|
+
}
|
|
120537
|
+
for (const file of files) {
|
|
120538
|
+
if (!file.path) {
|
|
120539
|
+
console.warn("\u26A0\uFE0F Skipping file operation: no path specified");
|
|
120540
|
+
continue;
|
|
120541
|
+
}
|
|
120542
|
+
const fullPath = path_1.default.join(outputPath, file.path);
|
|
120543
|
+
switch (file.operation) {
|
|
120544
|
+
case "insert":
|
|
120545
|
+
if (!file.content) {
|
|
120546
|
+
console.warn(`\u26A0\uFE0F Skipping insert operation for ${file.path}: no content provided`);
|
|
120547
|
+
continue;
|
|
120548
|
+
}
|
|
120549
|
+
const dir = path_1.default.dirname(fullPath);
|
|
120550
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
120551
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
120552
|
+
}
|
|
120553
|
+
fs_1.default.writeFileSync(fullPath, file.content.trim());
|
|
120554
|
+
console.log(`\u{1F4DD} Inserted: ${file.path}`);
|
|
120555
|
+
break;
|
|
120556
|
+
case "update":
|
|
120557
|
+
if (!file.content) {
|
|
120558
|
+
console.warn(`\u26A0\uFE0F Skipping update operation for ${file.path}: no content provided`);
|
|
120559
|
+
continue;
|
|
120560
|
+
}
|
|
120561
|
+
if (!fs_1.default.existsSync(fullPath)) {
|
|
120562
|
+
console.warn(`\u26A0\uFE0F Skipping update operation for ${file.path}: file does not exist`);
|
|
120563
|
+
continue;
|
|
120564
|
+
}
|
|
120565
|
+
fs_1.default.writeFileSync(fullPath, file.content.trim());
|
|
120566
|
+
console.log(`\u{1F4DD} Updated: ${file.path}`);
|
|
120567
|
+
break;
|
|
120568
|
+
case "delete":
|
|
120569
|
+
if (fs_1.default.existsSync(fullPath)) {
|
|
120570
|
+
fs_1.default.unlinkSync(fullPath);
|
|
120571
|
+
console.log(`\u{1F5D1}\uFE0F Deleted: ${file.path}`);
|
|
120572
|
+
} else {
|
|
120573
|
+
console.warn(`\u26A0\uFE0F Skipping delete operation for ${file.path}: file does not exist`);
|
|
120574
|
+
}
|
|
120575
|
+
break;
|
|
120576
|
+
default:
|
|
120577
|
+
throw new Error(`Unknown operation "${file.operation}" for file ${file.path}`);
|
|
120578
|
+
}
|
|
119915
120579
|
}
|
|
119916
|
-
fs_1.default.writeFileSync(fullPath, file.content.trim());
|
|
119917
|
-
console.log(`\u{1F4DD} Generated: ${file.path}`);
|
|
119918
120580
|
}
|
|
119919
120581
|
async generatePlanAndResources(request) {
|
|
119920
120582
|
const { siteId, accessToken, blueprint } = request;
|
|
@@ -119941,6 +120603,65 @@ var require_orchestrator = __commonJS({
|
|
|
119941
120603
|
}
|
|
119942
120604
|
return { createdCollections };
|
|
119943
120605
|
}
|
|
120606
|
+
async runIterationPlanningAndAugmentExtensions(outputPath, chatHistory) {
|
|
120607
|
+
const iterationAgent = this.agentsFactory.getAgent({
|
|
120608
|
+
type: "ITERATION_AGENT"
|
|
120609
|
+
});
|
|
120610
|
+
const candidateFiles = this.listGeneratedAppFiles(outputPath);
|
|
120611
|
+
const currentUserRequest = chatHistory[chatHistory.length - 1]?.text || "";
|
|
120612
|
+
const iterationPlan = await iterationAgent.generate(outputPath, candidateFiles, currentUserRequest, chatHistory);
|
|
120613
|
+
return iterationPlan;
|
|
120614
|
+
}
|
|
120615
|
+
async processExtension({ extension, blueprint, outputPath, createdCollections }) {
|
|
120616
|
+
this.emitEvent("scaffold:start", { extension });
|
|
120617
|
+
const [scaffold] = await (0, ditto_scaffolding_1.copyScaffoldingTemplate)(extension, outputPath);
|
|
120618
|
+
this.emitEvent("scaffold:done", {
|
|
120619
|
+
extension,
|
|
120620
|
+
scaffoldPath: scaffold.path
|
|
120621
|
+
});
|
|
120622
|
+
const agent = this.agentsFactory.getAgent(extension);
|
|
120623
|
+
this.emitEvent("agent:start", { extension, name: agent.name });
|
|
120624
|
+
const files = await agent.generate({
|
|
120625
|
+
extension,
|
|
120626
|
+
blueprint,
|
|
120627
|
+
scaffold,
|
|
120628
|
+
createdCollections,
|
|
120629
|
+
basePath: outputPath
|
|
120630
|
+
});
|
|
120631
|
+
this.writeFile(files, outputPath);
|
|
120632
|
+
this.emitEvent("agent:done", {
|
|
120633
|
+
extension,
|
|
120634
|
+
name: agent.name,
|
|
120635
|
+
files
|
|
120636
|
+
});
|
|
120637
|
+
}
|
|
120638
|
+
async processIterationExtension({ extension, paths, relevantUserRequest, outputPath, newExtension }) {
|
|
120639
|
+
let scaffold;
|
|
120640
|
+
if (newExtension) {
|
|
120641
|
+
this.emitEvent("scaffold:start", { extension });
|
|
120642
|
+
const [result] = await (0, ditto_scaffolding_1.copyScaffoldingTemplate)(extension, outputPath);
|
|
120643
|
+
scaffold = result;
|
|
120644
|
+
this.emitEvent("scaffold:done", {
|
|
120645
|
+
extension,
|
|
120646
|
+
scaffoldPath: scaffold.path
|
|
120647
|
+
});
|
|
120648
|
+
}
|
|
120649
|
+
const agent = this.agentsFactory.getAgent(extension);
|
|
120650
|
+
this.emitEvent("agent:start", { extension, name: agent.name });
|
|
120651
|
+
const files = await agent.generate({
|
|
120652
|
+
extension,
|
|
120653
|
+
scaffold,
|
|
120654
|
+
userRequestSummary: relevantUserRequest,
|
|
120655
|
+
relevantFilePaths: paths,
|
|
120656
|
+
basePath: outputPath
|
|
120657
|
+
});
|
|
120658
|
+
this.writeFile(files, outputPath);
|
|
120659
|
+
this.emitEvent("agent:done", {
|
|
120660
|
+
extension,
|
|
120661
|
+
name: agent.name,
|
|
120662
|
+
files
|
|
120663
|
+
});
|
|
120664
|
+
}
|
|
119944
120665
|
async generateCMSData(request, createdCollections) {
|
|
119945
120666
|
const { siteId, accessToken, blueprint } = request;
|
|
119946
120667
|
this.emitEvent("cms-data:start", {
|
|
@@ -119959,10 +120680,6 @@ var require_orchestrator = __commonJS({
|
|
|
119959
120680
|
totalItemsInserted
|
|
119960
120681
|
});
|
|
119961
120682
|
}
|
|
119962
|
-
/**
|
|
119963
|
-
* AI Generation Methods for customizing scaffolding
|
|
119964
|
-
* Currently supports: SERVICE_PLUGIN, DASHBOARD_PAGE
|
|
119965
|
-
*/
|
|
119966
120683
|
async generateCode(request) {
|
|
119967
120684
|
const { blueprint, outputPath, siteId, accessToken } = request;
|
|
119968
120685
|
this.emitEvent("start", {
|
|
@@ -119978,33 +120695,16 @@ var require_orchestrator = __commonJS({
|
|
|
119978
120695
|
const planAndResourcesResult = await this.generatePlanAndResources(request);
|
|
119979
120696
|
createdCollections.push(...planAndResourcesResult.createdCollections);
|
|
119980
120697
|
}
|
|
119981
|
-
const parallelTasks = extensions.map(
|
|
119982
|
-
|
|
119983
|
-
|
|
119984
|
-
|
|
119985
|
-
|
|
119986
|
-
|
|
119987
|
-
this.emitEvent("scaffold:done", {
|
|
119988
|
-
extension,
|
|
119989
|
-
scaffoldPath: scaffold.path
|
|
119990
|
-
});
|
|
119991
|
-
const agent = this.agentsFactory.getAgent(extension);
|
|
119992
|
-
this.emitEvent("agent:start", { extension, name: agent.name });
|
|
119993
|
-
const file = await agent.generate(extension, blueprint, scaffold, createdCollections);
|
|
119994
|
-
const files = [
|
|
119995
|
-
{ path: scaffold.path, content: file.content }
|
|
119996
|
-
];
|
|
119997
|
-
this.writeFile(files[0], outputPath);
|
|
119998
|
-
this.emitEvent("agent:done", {
|
|
119999
|
-
extension,
|
|
120000
|
-
name: agent.name,
|
|
120001
|
-
files
|
|
120002
|
-
});
|
|
120003
|
-
});
|
|
120698
|
+
const parallelTasks = extensions.map((extension) => this.processExtension({
|
|
120699
|
+
extension,
|
|
120700
|
+
blueprint,
|
|
120701
|
+
outputPath,
|
|
120702
|
+
createdCollections
|
|
120703
|
+
}));
|
|
120004
120704
|
if (createdCollections.length > 0 && siteId && accessToken) {
|
|
120005
120705
|
parallelTasks.push(this.generateCMSData(request, createdCollections));
|
|
120006
120706
|
}
|
|
120007
|
-
await Promise.all(parallelTasks);
|
|
120707
|
+
await Promise.all(parallelTasks.filter(Boolean));
|
|
120008
120708
|
(0, extensions_file_1.generateExtensionsFile)(outputPath, extensions);
|
|
120009
120709
|
const durationMsCodeGeneration = Date.now() - start;
|
|
120010
120710
|
this.emitEvent("finish:code-generation", {
|
|
@@ -120018,6 +120718,80 @@ var require_orchestrator = __commonJS({
|
|
|
120018
120718
|
const durationMs = Date.now() - start;
|
|
120019
120719
|
this.emitEvent("finish", { outputPath, durationMs });
|
|
120020
120720
|
}
|
|
120721
|
+
async generateIterationCode(request) {
|
|
120722
|
+
this.emitEvent("start:iteration", {});
|
|
120723
|
+
const { outputPath, chatHistory } = request;
|
|
120724
|
+
const start = Date.now();
|
|
120725
|
+
this.emitEvent("iterationAgent:start", {});
|
|
120726
|
+
const iterationPlan = await this.runIterationPlanningAndAugmentExtensions(outputPath, chatHistory);
|
|
120727
|
+
this.emitEvent("iterationAgent:done", {
|
|
120728
|
+
newExtensions: iterationPlan?.additionalExtensions?.length || 0,
|
|
120729
|
+
currentExtensions: iterationPlan?.currentExtensions?.length || 0
|
|
120730
|
+
});
|
|
120731
|
+
const parallelTasks = iterationPlan?.additionalExtensions?.map((extension) => {
|
|
120732
|
+
const extensionObj = {
|
|
120733
|
+
type: extension.extensionName,
|
|
120734
|
+
name: "",
|
|
120735
|
+
description: `Generated from iteration: ${extension.relevantUserRequest}`,
|
|
120736
|
+
relatedSpis: extension.relatedSpis?.map((spi) => ({
|
|
120737
|
+
name: spi,
|
|
120738
|
+
purpose: ""
|
|
120739
|
+
})) || []
|
|
120740
|
+
};
|
|
120741
|
+
return this.processIterationExtension({
|
|
120742
|
+
extension: extensionObj,
|
|
120743
|
+
paths: [],
|
|
120744
|
+
relevantUserRequest: iterationPlan.summary,
|
|
120745
|
+
outputPath,
|
|
120746
|
+
newExtension: true
|
|
120747
|
+
});
|
|
120748
|
+
}) || [];
|
|
120749
|
+
if (iterationPlan?.currentExtensions && iterationPlan.currentExtensions.length > 0) {
|
|
120750
|
+
parallelTasks.push(...iterationPlan.currentExtensions.map((extension) => {
|
|
120751
|
+
const extensionObj = {
|
|
120752
|
+
type: extension.extensionName,
|
|
120753
|
+
name: "",
|
|
120754
|
+
description: `Generated from iteration: ${extension.relevantUserRequest}`,
|
|
120755
|
+
relatedSpis: extension.relatedSpis?.map((spi) => ({
|
|
120756
|
+
name: spi,
|
|
120757
|
+
purpose: ""
|
|
120758
|
+
})) || []
|
|
120759
|
+
};
|
|
120760
|
+
return this.processIterationExtension({
|
|
120761
|
+
extension: extensionObj,
|
|
120762
|
+
paths: extension.paths,
|
|
120763
|
+
relevantUserRequest: extension.relevantUserRequest,
|
|
120764
|
+
outputPath,
|
|
120765
|
+
newExtension: false
|
|
120766
|
+
});
|
|
120767
|
+
}));
|
|
120768
|
+
}
|
|
120769
|
+
await Promise.all(parallelTasks.filter(Boolean));
|
|
120770
|
+
const finalExtensionsToWrite = iterationPlan?.additionalExtensions?.map((extension) => {
|
|
120771
|
+
const extensionObj = {
|
|
120772
|
+
type: extension.extensionName,
|
|
120773
|
+
name: "",
|
|
120774
|
+
description: `Generated from iteration: ${extension.relevantUserRequest}`,
|
|
120775
|
+
relatedSpis: extension.relatedSpis?.map((spi) => ({
|
|
120776
|
+
name: spi,
|
|
120777
|
+
purpose: ""
|
|
120778
|
+
})) || []
|
|
120779
|
+
};
|
|
120780
|
+
return extensionObj;
|
|
120781
|
+
});
|
|
120782
|
+
(0, extensions_file_1.generateExtensionsFile)(outputPath, finalExtensionsToWrite);
|
|
120783
|
+
const durationMsCodeGeneration = Date.now() - start;
|
|
120784
|
+
this.emitEvent("finish:code-generation", {
|
|
120785
|
+
outputPath,
|
|
120786
|
+
durationMs: durationMsCodeGeneration
|
|
120787
|
+
});
|
|
120788
|
+
await this.startFixFlow({
|
|
120789
|
+
projectDir: outputPath,
|
|
120790
|
+
apiKey: this.apiKey
|
|
120791
|
+
});
|
|
120792
|
+
const durationMs = Date.now() - start;
|
|
120793
|
+
this.emitEvent("finish:iteration", { outputPath, durationMs });
|
|
120794
|
+
}
|
|
120021
120795
|
async startFixFlow(request) {
|
|
120022
120796
|
const { projectDir, apiKey } = request;
|
|
120023
120797
|
this.emitEvent("validation:start", { outputPath: projectDir });
|
|
@@ -120053,6 +120827,26 @@ ${unfixedValidationErrors}`)
|
|
|
120053
120827
|
throw new Error(`Validation failed after ${MAX_FIX_ATTEMPTS} attempts. Errors:
|
|
120054
120828
|
${unfixedValidationErrors}`);
|
|
120055
120829
|
}
|
|
120830
|
+
listGeneratedAppFiles(outputPath) {
|
|
120831
|
+
const root = outputPath;
|
|
120832
|
+
const srcDir = path_1.default.join(root, "src");
|
|
120833
|
+
const results = [];
|
|
120834
|
+
if (!fs_1.default.existsSync(srcDir)) {
|
|
120835
|
+
return results;
|
|
120836
|
+
}
|
|
120837
|
+
const walk = (dir) => {
|
|
120838
|
+
const entries = fs_1.default.existsSync(dir) ? fs_1.default.readdirSync(dir, { withFileTypes: true }) : [];
|
|
120839
|
+
for (const entry of entries) {
|
|
120840
|
+
const full = path_1.default.join(dir, entry.name);
|
|
120841
|
+
if (entry.isDirectory())
|
|
120842
|
+
walk(full);
|
|
120843
|
+
else
|
|
120844
|
+
results.push(path_1.default.relative(root, full));
|
|
120845
|
+
}
|
|
120846
|
+
};
|
|
120847
|
+
walk(srcDir);
|
|
120848
|
+
return results;
|
|
120849
|
+
}
|
|
120056
120850
|
};
|
|
120057
120851
|
exports2.DittoOrchestrator = DittoOrchestrator;
|
|
120058
120852
|
DittoOrchestrator.DEFAULT_OUTPUT_PATH = "generated-app";
|
|
@@ -120172,6 +120966,72 @@ var require_init_codegen = __commonJS({
|
|
|
120172
120966
|
}
|
|
120173
120967
|
});
|
|
120174
120968
|
|
|
120969
|
+
// dist/flows/iterate-codegen.js
|
|
120970
|
+
var require_iterate_codegen = __commonJS({
|
|
120971
|
+
"dist/flows/iterate-codegen.js"(exports2) {
|
|
120972
|
+
"use strict";
|
|
120973
|
+
var __importDefault2 = exports2 && exports2.__importDefault || function(mod2) {
|
|
120974
|
+
return mod2 && mod2.__esModule ? mod2 : { "default": mod2 };
|
|
120975
|
+
};
|
|
120976
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
120977
|
+
exports2.runIterateCodegenFlow = void 0;
|
|
120978
|
+
var path_1 = __importDefault2(require("path"));
|
|
120979
|
+
var __1 = require_index();
|
|
120980
|
+
var AgentsFactory_1 = require_AgentsFactory();
|
|
120981
|
+
var cli_listeners_1 = require_cli_listeners();
|
|
120982
|
+
var context_1 = require_context();
|
|
120983
|
+
var job_context_storage_1 = require_job_context_storage();
|
|
120984
|
+
var orchestrator_1 = require_orchestrator();
|
|
120985
|
+
var CodeGenService_1 = require_CodeGenService();
|
|
120986
|
+
var utils_1 = require_utils18();
|
|
120987
|
+
var slugify = (str = "") => {
|
|
120988
|
+
return str.toLowerCase().replace(/ /g, "-");
|
|
120989
|
+
};
|
|
120990
|
+
var runIterateCodegenFlow = async (chatHistory) => {
|
|
120991
|
+
const localJobContext = job_context_storage_1.jobContextStorage.getStore();
|
|
120992
|
+
console.log(`[Iterate] Starting iterate codegen task: jobId=${localJobContext?.jobId}, taskId=${localJobContext?.taskId}`);
|
|
120993
|
+
await __1.codeGenerationService.updateTask(localJobContext.jobId, localJobContext.taskId, CodeGenService_1.TaskStatus.RUNNING, {});
|
|
120994
|
+
console.log(`[Init] Marked task RUNNING: jobId=${localJobContext.jobId}, taskId=${localJobContext.taskId}`);
|
|
120995
|
+
try {
|
|
120996
|
+
const outputDir = process.env.OUTPUT_PATH || orchestrator_1.DittoOrchestrator.DEFAULT_OUTPUT_PATH;
|
|
120997
|
+
const outputPath = outputDir.startsWith("/") ? outputDir : path_1.default.join(process.cwd(), outputDir);
|
|
120998
|
+
const agentsFactory = new AgentsFactory_1.AgentsFactory(context_1.ctx?.apiKey);
|
|
120999
|
+
const orchestrator = new orchestrator_1.DittoOrchestrator(agentsFactory);
|
|
121000
|
+
orchestrator.onEvent("agent:start", ({ extension }) => {
|
|
121001
|
+
console.log(`[Agent] start: ${extension.name}`);
|
|
121002
|
+
__1.codeGenerationService.addTask(localJobContext.jobId, {
|
|
121003
|
+
id: `${localJobContext.taskId}-${slugify(extension.name)}`,
|
|
121004
|
+
kind: "run_agent",
|
|
121005
|
+
status: CodeGenService_1.TaskStatus.RUNNING,
|
|
121006
|
+
name: "run_agent",
|
|
121007
|
+
description: `Run agent for ${extension.name}`,
|
|
121008
|
+
payload: { extension }
|
|
121009
|
+
});
|
|
121010
|
+
});
|
|
121011
|
+
orchestrator.onEvent("agent:done", ({ extension, files }) => {
|
|
121012
|
+
console.log(`[Agent] done: ${extension.name}`);
|
|
121013
|
+
__1.codeGenerationService.updateTask(localJobContext.jobId, `${localJobContext.taskId}-${slugify(extension.name)}`, CodeGenService_1.TaskStatus.COMPLETED, { taskOutput: { files } });
|
|
121014
|
+
});
|
|
121015
|
+
(0, cli_listeners_1.attachOrchestratorListeners)(orchestrator);
|
|
121016
|
+
await orchestrator.generateIterationCode({
|
|
121017
|
+
chatHistory,
|
|
121018
|
+
outputPath,
|
|
121019
|
+
siteId: context_1.ctx.siteId,
|
|
121020
|
+
accessToken: context_1.ctx.accessToken
|
|
121021
|
+
});
|
|
121022
|
+
await __1.codeGenerationService.updateTask(localJobContext.jobId, localJobContext.taskId, CodeGenService_1.TaskStatus.COMPLETED, {});
|
|
121023
|
+
console.log(`[Init] Completed iterate codegen task: jobId=${localJobContext.jobId}, taskId=${localJobContext.taskId}`);
|
|
121024
|
+
} catch (error) {
|
|
121025
|
+
await __1.codeGenerationService.updateTask(localJobContext.jobId, localJobContext.taskId, CodeGenService_1.TaskStatus.FAILED, {
|
|
121026
|
+
error: (0, utils_1.serializeError)(error)
|
|
121027
|
+
});
|
|
121028
|
+
console.error(`\u274C [Init] Failed iterate codegen task: jobId=${localJobContext.jobId}, taskId=${localJobContext.taskId}`, error);
|
|
121029
|
+
}
|
|
121030
|
+
};
|
|
121031
|
+
exports2.runIterateCodegenFlow = runIterateCodegenFlow;
|
|
121032
|
+
}
|
|
121033
|
+
});
|
|
121034
|
+
|
|
120175
121035
|
// dist/index.js
|
|
120176
121036
|
var require_index = __commonJS({
|
|
120177
121037
|
"dist/index.js"(exports2) {
|
|
@@ -120219,6 +121079,7 @@ var require_index = __commonJS({
|
|
|
120219
121079
|
var CodeGenService_1 = __importStar2(require_CodeGenService());
|
|
120220
121080
|
var job_context_storage_1 = require_job_context_storage();
|
|
120221
121081
|
var init_codegen_1 = require_init_codegen();
|
|
121082
|
+
var iterate_codegen_1 = require_iterate_codegen();
|
|
120222
121083
|
var initializeTracing = async () => {
|
|
120223
121084
|
try {
|
|
120224
121085
|
await instrumentation_1.tracingReady;
|
|
@@ -120279,8 +121140,14 @@ var require_index = __commonJS({
|
|
|
120279
121140
|
context_1.ctx.setJobStatus(job.jobId, CodeGenService_1.TaskStatus.RUNNING);
|
|
120280
121141
|
console.log(`[Job] Marked job RUNNING: jobId=${job.jobId}, initTaskId=${task.id}`);
|
|
120281
121142
|
console.log("Task Payload", JSON.stringify(task.payload, null, 2));
|
|
120282
|
-
await job_context_storage_1.jobContextStorage.run({ jobId: job.jobId, taskId: task.id }, async () => {
|
|
120283
|
-
|
|
121143
|
+
await job_context_storage_1.jobContextStorage.run({ jobId: job.jobId, taskId: task.id, kind: task.kind }, async () => {
|
|
121144
|
+
const payload = task?.payload || {};
|
|
121145
|
+
if (task.kind === "ITERATE_CODEGEN") {
|
|
121146
|
+
const chatHistory = payload.history ?? [];
|
|
121147
|
+
await (0, iterate_codegen_1.runIterateCodegenFlow)(chatHistory);
|
|
121148
|
+
} else if (task.kind === "INIT_CODEGEN") {
|
|
121149
|
+
await (0, init_codegen_1.runInitCodegenFlow)(payload.blueprint);
|
|
121150
|
+
}
|
|
120284
121151
|
});
|
|
120285
121152
|
}
|
|
120286
121153
|
(0, context_1.initCtx)("dafdsf").then((ctx) => {
|