@autobe/agent 0.15.0 → 0.16.0
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/lib/AutoBeAgent.js +2 -2
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/AutoBeMockAgent.d.ts +1 -0
- package/lib/AutoBeMockAgent.js +18 -4
- package/lib/AutoBeMockAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +3 -3
- package/lib/factory/getAutoBeGenerated.js +2 -1
- package/lib/factory/getAutoBeGenerated.js.map +1 -1
- package/lib/index.mjs +739 -577
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.d.ts +0 -15
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js +0 -3
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyze.js +19 -12
- package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.d.ts +1 -2
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js +3 -5
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.d.ts +7 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js +363 -4
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.d.ts +3 -3
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +3 -118
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -1
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js +1 -1
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js.map +1 -1
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.d.ts +11 -4
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js +61 -45
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js.map +1 -1
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +17 -10
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
- package/lib/orchestrate/realize/ProviderCodeComparator.d.ts +5 -0
- package/lib/orchestrate/realize/ProviderCodeComparator.js +16 -0
- package/lib/orchestrate/realize/ProviderCodeComparator.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealize.js +41 -53
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js +13 -87
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js +32 -43
- package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +3 -2
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js +25 -39
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
- package/lib/orchestrate/realize/structures/IAutoBeRealizeAuthorizationApplication.d.ts +15 -15
- package/lib/orchestrate/realize/structures/IAutoBeRealizeAuthorizationCorrectApplication.d.ts +11 -17
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +4 -2
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.d.ts +21 -17
- package/lib/orchestrate/realize/transformRealizeAuthorization.js +5 -9
- package/lib/orchestrate/realize/transformRealizeAuthorization.js.map +1 -1
- package/lib/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.js +9 -0
- package/lib/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.js.map +1 -1
- package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +3 -2
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js +58 -27
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationFileSystem.d.ts +5 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationFileSystem.js +10 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationFileSystem.js.map +1 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationReplaceImport.d.ts +4 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationReplaceImport.js +38 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationReplaceImport.js.map +1 -0
- package/lib/orchestrate/realize/utils/replaceImportStatements.d.ts +2 -1
- package/lib/orchestrate/realize/utils/replaceImportStatements.js +15 -2
- package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.d.ts +9 -2
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +158 -100
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTest.js +1 -1
- package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
- package/package.json +6 -6
- package/src/AutoBeAgent.ts +1 -1
- package/src/AutoBeMockAgent.ts +20 -6
- package/src/constants/AutoBeSystemPromptConstant.ts +3 -3
- package/src/factory/getAutoBeGenerated.ts +2 -1
- package/src/orchestrate/analyze/AutoBeAnalyzeFileSystem.ts +0 -15
- package/src/orchestrate/analyze/orchestrateAnalyze.ts +17 -17
- package/src/orchestrate/analyze/orchestrateAnalyzeComposer.ts +4 -7
- package/src/orchestrate/analyze/orchestrateAnalyzeReviewer.ts +100 -6
- package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +5 -21
- package/src/orchestrate/analyze/writeDocumentUntilReviewPassed.ts +76 -59
- package/src/orchestrate/prisma/transformPrismaComponentsHistories.ts +17 -10
- package/src/orchestrate/realize/ProviderCodeComparator.ts +15 -0
- package/src/orchestrate/realize/orchestrateRealize.ts +54 -59
- package/src/orchestrate/realize/orchestrateRealizeAuthorization.ts +12 -120
- package/src/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.ts +21 -5
- package/src/orchestrate/realize/orchestrateRealizeCoder.ts +10 -9
- package/src/orchestrate/realize/structures/IAutoBeRealizeAuthorizationApplication.ts +15 -15
- package/src/orchestrate/realize/structures/IAutoBeRealizeAuthorizationCorrectApplication.ts +11 -18
- package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +4 -2
- package/src/orchestrate/realize/structures/IAutoBeRealizeCompile.ts +24 -17
- package/src/orchestrate/realize/transformRealizeAuthorization.ts +5 -9
- package/src/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.ts +9 -0
- package/src/orchestrate/realize/transformRealizeCoderHistories.ts +73 -25
- package/src/orchestrate/realize/utils/AutoBeRealizeAuthorizationFileSystem.ts +9 -0
- package/src/orchestrate/realize/utils/AutoBeRealizeAuthorizationReplaceImport.ts +64 -0
- package/src/orchestrate/realize/utils/replaceImportStatements.ts +41 -2
- package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +219 -145
- package/src/orchestrate/test/orchestrateTest.ts +1 -1
package/lib/index.mjs
CHANGED
|
@@ -38,16 +38,18 @@ async function getAutoBeGenerated(compiler, state, histories, tokenUsage, option
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
if (state.test?.step === state.analyze.step) Object.assign(ret, Object.fromEntries(state.test.files.map((f => [ f.location, f.content ]))), await compiler.test.getTemplate());
|
|
41
|
-
if (state.realize?.step === state.analyze.step)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
if (state.realize?.step === state.analyze.step) {
|
|
42
|
+
Object.assign(ret, {
|
|
43
|
+
...Object.fromEntries(state.realize.functions.map((f => [ f.location, f.content ]))),
|
|
44
|
+
...Object.fromEntries(state.realize.authorizations.map((auth => [ [ auth.decorator.location, auth.decorator.content ], [ auth.provider.location, auth.provider.content ], [ auth.payload.location, auth.payload.content ] ])).flat()),
|
|
45
|
+
...await compiler.realize.getTemplate(),
|
|
46
|
+
...await compiler.realize.controller({
|
|
47
|
+
document: state.interface.document,
|
|
48
|
+
functions: state.realize.functions,
|
|
49
|
+
authorizations: state.realize.authorizations
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
51
53
|
Object.assign(ret, {
|
|
52
54
|
"autobe/histories.json": JSON.stringify(histories),
|
|
53
55
|
"autobe/tokenUsage.json": JSON.stringify(tokenUsage)
|
|
@@ -195,13 +197,11 @@ function enforceToolCall(agent) {
|
|
|
195
197
|
return agent;
|
|
196
198
|
}
|
|
197
199
|
|
|
198
|
-
const orchestrateAnalyzeComposer = (ctx,
|
|
199
|
-
const controller = createController$
|
|
200
|
+
const orchestrateAnalyzeComposer = (ctx, setComposeInput) => {
|
|
201
|
+
const controller = createController$2({
|
|
200
202
|
model: ctx.model,
|
|
201
203
|
execute: new AutoBeAnalyzeComposerApplication,
|
|
202
|
-
|
|
203
|
-
pointer.value = value;
|
|
204
|
-
}
|
|
204
|
+
preExecute: setComposeInput
|
|
205
205
|
});
|
|
206
206
|
const agent = new MicroAgentica({
|
|
207
207
|
model: ctx.model,
|
|
@@ -230,23 +230,23 @@ class AutoBeAnalyzeComposerApplication {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
function createController$
|
|
233
|
+
function createController$2(props) {
|
|
234
234
|
assertSchemaModel(props.model);
|
|
235
|
-
const application = collection$
|
|
235
|
+
const application = collection$h[props.model];
|
|
236
236
|
return {
|
|
237
237
|
protocol: "class",
|
|
238
238
|
name: "Compose",
|
|
239
239
|
application,
|
|
240
240
|
execute: {
|
|
241
241
|
compose: input => {
|
|
242
|
-
props.
|
|
242
|
+
props.preExecute(input);
|
|
243
243
|
return props.execute.compose(input);
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
const claude$
|
|
249
|
+
const claude$h = {
|
|
250
250
|
model: "claude",
|
|
251
251
|
options: {
|
|
252
252
|
reference: true,
|
|
@@ -459,7 +459,7 @@ const claude$g = {
|
|
|
459
459
|
} ]
|
|
460
460
|
};
|
|
461
461
|
|
|
462
|
-
const collection$
|
|
462
|
+
const collection$h = {
|
|
463
463
|
chatgpt: {
|
|
464
464
|
model: "chatgpt",
|
|
465
465
|
options: {
|
|
@@ -672,10 +672,10 @@ const collection$g = {
|
|
|
672
672
|
})()
|
|
673
673
|
} ]
|
|
674
674
|
},
|
|
675
|
-
claude: claude$
|
|
676
|
-
llama: claude$
|
|
677
|
-
deepseek: claude$
|
|
678
|
-
3.1: claude$
|
|
675
|
+
claude: claude$h,
|
|
676
|
+
llama: claude$h,
|
|
677
|
+
deepseek: claude$h,
|
|
678
|
+
3.1: claude$h
|
|
679
679
|
};
|
|
680
680
|
|
|
681
681
|
const transformAnalyzeReviewerHistories = input => [ {
|
|
@@ -687,14 +687,26 @@ const transformAnalyzeReviewerHistories = input => [ {
|
|
|
687
687
|
id: v4(),
|
|
688
688
|
created_at: (new Date).toISOString(),
|
|
689
689
|
type: "systemMessage",
|
|
690
|
-
text: "# Reviewer Agent Operating Guidelines\n\n## Core Principles\n
|
|
690
|
+
text: "# Reviewer Agent Operating Guidelines\n\n## Core Principles\n- **Review only the document currently being viewed.** Ignore any references to other documents, even if implied.\n- If the current document is **not a table of contents page** (i.e., does not start with `00`) and references external documents, **instruct the planner to clear all content and rewrite the current document** to focus solely on its assigned scope.\n- **Do not request the creation of any other pages or documents.** Each agent must write and review **only the single page assigned to them.**\n- Attempts to write or request other pages are strictly prohibited. If such attempts occur, **command the agent to focus exclusively on the current page.**\n- The table of contents page (starting with `00`) is exempt from content rewriting rules unless it contains invalid references.\n- Other documents will be handled by other agents, so **do not request their creation** under any circumstances.\n\n## Role of the Reviewer\n- The Reviewer Agent’s role is to **ensure the document contains sufficient information** before it is delivered to developers.\n- **Review all hyperlinks** currently referenced in the markdown and ensure they are valid or appropriately handled:\n - Internal anchor links (e.g., `#section-title`) must point to existing headings within the document.\n - External document links are allowed only if they do not impact the core content of the current document (unless it’s a table of contents page).\n- **Do not create files** that are not specified in the table of contents.\n- If the user specifies an **exact number of pages**, that number **must be strictly followed.**\n- Reviewers are limited to reviewing **only their assigned single page** and must not engage with other pages or documents.\n- If an agent requests creation of other pages, **command them to stop** and enforce focus on the current page.\n\n## Conditions Requiring `reject`\nThe Reviewer Agent **must** call `reject` with a reason, feedback, and suggestions in the following cases:\n- Document length is **less than 2,000 characters** (excluding table of contents pages).\n- Any section listed in the table of contents is **missing or incomplete**.\n- Internal anchor links (e.g., `#section-title`) point to **non-existent headings** within the document.\n- External document references in a non-table-of-contents page impact the **core content** of the document.\n- Content is **insufficient relative to the number of headings** (e.g., average content per heading is less than 300 characters).\n- Any violation of the **page-based work division** rules (e.g., attempts to write or reference content outside the assigned page).\n\n## Conditions for `accept`\nThe Reviewer Agent **must** call `accept` only when **all** of the following conditions are met:\n- Document length is **between 2,000 and 6,000 characters** (excluding table of contents pages).\n- All sections listed in the table of contents are **fully written** with sufficient detail.\n- All internal anchor links point to **existing headings** within the document.\n- External document references (if any) do not impact the **core content** of the document, or the document is a table of contents page.\n- Content is **sufficient relative to the number of headings** (e.g., average content per heading is at least 300 characters).\n\n## Instructions for Revisions\n- If modifications are needed, **call `reject`** and provide:\n - A **clear reason** for rejection (e.g., “Document is 1,500 characters, below the 2,000-character minimum”).\n - **Detailed feedback** identifying the issue (e.g., “Section [Section Title] is missing”).\n - **Specific suggestions** for correction (e.g., “Add 500 characters to Section [Section Title] with details on [specific topic]”).\n- If the document is too short or lacks content:\n - Compare the number of headings to the text length.\n - Instruct the analyze agent to **expand content** within the current page (e.g., “With 5 headings and 1,500 characters, add 500 characters to Section [Section Title]”).\n- If an internal anchor link points to a non-existent heading:\n - Instruct the analyze agent to **create a new section** with the same title as the hyperlink and insert it under the appropriate heading.\n- If external document references are included in a non-table-of-contents page:\n - Instruct the analyze agent to **integrate the referenced content** into the current page or remove the reference if it’s not critical.\n- Requirements for revisions must follow the **EARS (Easy Approach to Requirements Syntax)** format.\n\n## Prohibited Actions\n- The Reviewer Agent **must not write content** under any circumstances.\n- Reviewers are **independent** and must not be instructed by other agents.\n- The Reviewer’s words are **commands**, not recommendations, and must be followed.\n\n## Guidelines for Document Volume\n- Documents (excluding table of contents) should be **2,000–6,000 characters** for sufficient utility.\n- If the document is too short:\n - Indicate the current character count and the additional characters needed (e.g., “Current length: 1,500 characters; add 500 characters”).\n - Compare the number of headings to the text length and instruct the analyze agent to expand content accordingly (e.g., “With 5 headings, aim for 400 characters per heading”).\n- The table of contents page is exempt from the volume limit.\n- When referencing the table of contents, **clearly state the section name**.\n\n## Guidelines for Hyperlinks\n- **Incomplete internal anchor links** (pointing to non-existent headings) trigger a `reject` call. Instruct the analyze agent to create the missing section.\n- **External document links** are allowed only if they do not impact the core content of the current document (unless it’s a table of contents page). If they do, trigger a `reject` call and instruct integration or removal.\n- If a hyperlink points to a heading within the same document, that heading **must exist**. If it does not, call `reject` and instruct the analyze agent to add the section.\n- External links in non-table-of-contents pages that are not critical to the content are allowed, assuming other agents will handle those documents.\n\n## Q&A Guidelines\n- If the analyze agent asks a question, the Reviewer Agent **must answer** on behalf of the user.\n- **Never ask questions.** Only issue commands.\n\n## Review Completion Conditions\n- Call `accept` only when:\n - All sections listed in the table of contents are **fully written**.\n - All internal hyperlinks are **resolved** (point to existing headings).\n - Document length is **2,000–6,000 characters** (excluding table of contents).\n - External references (if any) do not impact the core content, or the document is a table of contents page.\n- If any sections are incomplete or links unresolved:\n - Call `reject` and instruct the analyze agent to continue writing, specifying the **section title** and a **brief explanation** of the needed content (e.g., “Section [Section Title] lacks details on [topic]; add 300 characters”).\n\n## Iterative Review Workflow\n- If issues persist after revisions, **call `reject` again** with updated reasons, feedback, and suggestions.\n- Example: “Document is still 1,800 characters. Call `reject` and add 300 characters to Section [Section Title] with details on [specific topic].”\n- Continue this process until all conditions for `accept` are met.\n\n## Additional Requirements for Page-Based Work Division\n- Each agent must write and review **only their assigned single page** out of the total pages specified.\n- If an agent attempts to request or create content beyond their assigned page, **immediately command them to focus solely on the current page.**\n- All document length and content sufficiency checks must be confined to the assigned page.\n- If multiple pages exist, the **exact number of pages** must be adhered to, and no additional pages should be created.\n- Enforce strict page-level division to maintain clear boundaries of responsibility and simplify review workflows.\n\n## Enforcement\n- All guidelines must be **strictly enforced**. Any violations (e.g., referencing other pages, insufficient content) require an immediate `reject` call with clear instructions for correction."
|
|
691
691
|
} ];
|
|
692
692
|
|
|
693
693
|
const orchestrateAnalyzeReviewer = async (ctx, input) => {
|
|
694
|
+
const fnCalled = {
|
|
695
|
+
value: {
|
|
696
|
+
type: "reject",
|
|
697
|
+
value: "reviewer is not working because of unknown reason."
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
const controller = createController$1({
|
|
701
|
+
model: ctx.model,
|
|
702
|
+
setResult: result => {
|
|
703
|
+
fnCalled.value = result;
|
|
704
|
+
}
|
|
705
|
+
});
|
|
694
706
|
const agent = new MicroAgentica({
|
|
695
707
|
model: ctx.model,
|
|
696
708
|
vendor: ctx.vendor,
|
|
697
|
-
controllers: [],
|
|
709
|
+
controllers: [ controller ],
|
|
698
710
|
config: {
|
|
699
711
|
...ctx.config,
|
|
700
712
|
executor: {
|
|
@@ -705,11 +717,271 @@ const orchestrateAnalyzeReviewer = async (ctx, input) => {
|
|
|
705
717
|
});
|
|
706
718
|
enforceToolCall(agent);
|
|
707
719
|
const command = `proceed with the review of these files only.`;
|
|
708
|
-
|
|
720
|
+
await agent.conversate(command).finally((() => {
|
|
709
721
|
const tokenUsage = agent.getTokenUsage();
|
|
710
722
|
ctx.usage().record(tokenUsage, [ "analyze" ]);
|
|
711
723
|
}));
|
|
712
|
-
return
|
|
724
|
+
return fnCalled.value;
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
function createController$1(props) {
|
|
728
|
+
assertSchemaModel(props.model);
|
|
729
|
+
const application = collection$g[props.model];
|
|
730
|
+
return {
|
|
731
|
+
protocol: "class",
|
|
732
|
+
name: "Reviewer",
|
|
733
|
+
application,
|
|
734
|
+
execute: {
|
|
735
|
+
accept: async () => {
|
|
736
|
+
props.setResult({
|
|
737
|
+
type: "accept"
|
|
738
|
+
});
|
|
739
|
+
return "OK";
|
|
740
|
+
},
|
|
741
|
+
reject: async input => {
|
|
742
|
+
props.setResult({
|
|
743
|
+
type: "reject",
|
|
744
|
+
value: input.reason
|
|
745
|
+
});
|
|
746
|
+
return "OK";
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const claude$g = {
|
|
753
|
+
model: "claude",
|
|
754
|
+
options: {
|
|
755
|
+
reference: true,
|
|
756
|
+
separate: null
|
|
757
|
+
},
|
|
758
|
+
functions: [ {
|
|
759
|
+
name: "reject",
|
|
760
|
+
parameters: {
|
|
761
|
+
type: "object",
|
|
762
|
+
properties: {
|
|
763
|
+
reason: {
|
|
764
|
+
description: "The reason why you reject the document and the suggestion for the\nmodification. You can write the reason in detail.",
|
|
765
|
+
type: "string"
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
required: [ "reason" ],
|
|
769
|
+
additionalProperties: false,
|
|
770
|
+
$defs: {
|
|
771
|
+
OK: {
|
|
772
|
+
description: "Represents the completion of an asynchronous operation",
|
|
773
|
+
type: "object",
|
|
774
|
+
properties: {
|
|
775
|
+
"__@toStringTag@1672": {
|
|
776
|
+
type: "string"
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
required: [ "__@toStringTag@1672" ]
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
output: {
|
|
784
|
+
oneOf: [ {
|
|
785
|
+
const: "OK"
|
|
786
|
+
}, {
|
|
787
|
+
$ref: "#/$defs/OK"
|
|
788
|
+
} ]
|
|
789
|
+
},
|
|
790
|
+
description: "If there is anything that needs to be modified, you can call it, This\nfunction is to reject the document for to try rewriting document with your\nadvice or suggestion.",
|
|
791
|
+
validate: (() => {
|
|
792
|
+
const _io0 = input => "string" === typeof input.reason;
|
|
793
|
+
const _vo0 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, {
|
|
794
|
+
path: _path + ".reason",
|
|
795
|
+
expected: "string",
|
|
796
|
+
value: input.reason
|
|
797
|
+
}) ].every((flag => flag));
|
|
798
|
+
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
799
|
+
let errors;
|
|
800
|
+
let _report;
|
|
801
|
+
return input => {
|
|
802
|
+
if (false === __is(input)) {
|
|
803
|
+
errors = [];
|
|
804
|
+
_report = __typia_transform__validateReport._validateReport(errors);
|
|
805
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
|
|
806
|
+
path: _path + "",
|
|
807
|
+
expected: "__type",
|
|
808
|
+
value: input
|
|
809
|
+
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
810
|
+
path: _path + "",
|
|
811
|
+
expected: "__type",
|
|
812
|
+
value: input
|
|
813
|
+
}))(input, "$input", true);
|
|
814
|
+
const success = 0 === errors.length;
|
|
815
|
+
return success ? {
|
|
816
|
+
success,
|
|
817
|
+
data: input
|
|
818
|
+
} : {
|
|
819
|
+
success,
|
|
820
|
+
errors,
|
|
821
|
+
data: input
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
return {
|
|
825
|
+
success: true,
|
|
826
|
+
data: input
|
|
827
|
+
};
|
|
828
|
+
};
|
|
829
|
+
})()
|
|
830
|
+
}, {
|
|
831
|
+
name: "accept",
|
|
832
|
+
parameters: {
|
|
833
|
+
type: "object",
|
|
834
|
+
properties: {},
|
|
835
|
+
additionalProperties: false,
|
|
836
|
+
required: [],
|
|
837
|
+
$defs: {
|
|
838
|
+
OK: {
|
|
839
|
+
description: "Represents the completion of an asynchronous operation",
|
|
840
|
+
type: "object",
|
|
841
|
+
properties: {
|
|
842
|
+
"__@toStringTag@1672": {
|
|
843
|
+
type: "string"
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
required: [ "__@toStringTag@1672" ]
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
},
|
|
850
|
+
output: {
|
|
851
|
+
oneOf: [ {
|
|
852
|
+
const: "OK"
|
|
853
|
+
}, {
|
|
854
|
+
$ref: "#/$defs/OK"
|
|
855
|
+
} ]
|
|
856
|
+
},
|
|
857
|
+
description: "If you decide that you no longer need any reviews, call accept. This is a\nfunction to end document creation and review, and to respond to users.",
|
|
858
|
+
validate: (() => input => ({
|
|
859
|
+
success: true,
|
|
860
|
+
data: input
|
|
861
|
+
}))()
|
|
862
|
+
} ]
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
const collection$g = {
|
|
866
|
+
chatgpt: {
|
|
867
|
+
model: "chatgpt",
|
|
868
|
+
options: {
|
|
869
|
+
reference: true,
|
|
870
|
+
strict: false,
|
|
871
|
+
separate: null
|
|
872
|
+
},
|
|
873
|
+
functions: [ {
|
|
874
|
+
name: "reject",
|
|
875
|
+
parameters: {
|
|
876
|
+
type: "object",
|
|
877
|
+
properties: {
|
|
878
|
+
reason: {
|
|
879
|
+
description: "The reason why you reject the document and the suggestion for the\nmodification. You can write the reason in detail.",
|
|
880
|
+
type: "string"
|
|
881
|
+
}
|
|
882
|
+
},
|
|
883
|
+
required: [ "reason" ],
|
|
884
|
+
additionalProperties: false,
|
|
885
|
+
$defs: {
|
|
886
|
+
OK: {
|
|
887
|
+
description: "Represents the completion of an asynchronous operation",
|
|
888
|
+
type: "object",
|
|
889
|
+
properties: {
|
|
890
|
+
"__@toStringTag@1672": {
|
|
891
|
+
type: "string"
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
required: [ "__@toStringTag@1672" ]
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
output: {
|
|
899
|
+
anyOf: [ {
|
|
900
|
+
$ref: "#/$defs/OK"
|
|
901
|
+
}, {
|
|
902
|
+
type: "string",
|
|
903
|
+
enum: [ "OK" ]
|
|
904
|
+
} ]
|
|
905
|
+
},
|
|
906
|
+
description: "If there is anything that needs to be modified, you can call it, This\nfunction is to reject the document for to try rewriting document with your\nadvice or suggestion.",
|
|
907
|
+
validate: (() => {
|
|
908
|
+
const _io0 = input => "string" === typeof input.reason;
|
|
909
|
+
const _vo0 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, {
|
|
910
|
+
path: _path + ".reason",
|
|
911
|
+
expected: "string",
|
|
912
|
+
value: input.reason
|
|
913
|
+
}) ].every((flag => flag));
|
|
914
|
+
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
915
|
+
let errors;
|
|
916
|
+
let _report;
|
|
917
|
+
return input => {
|
|
918
|
+
if (false === __is(input)) {
|
|
919
|
+
errors = [];
|
|
920
|
+
_report = __typia_transform__validateReport._validateReport(errors);
|
|
921
|
+
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
|
|
922
|
+
path: _path + "",
|
|
923
|
+
expected: "__type",
|
|
924
|
+
value: input
|
|
925
|
+
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
926
|
+
path: _path + "",
|
|
927
|
+
expected: "__type",
|
|
928
|
+
value: input
|
|
929
|
+
}))(input, "$input", true);
|
|
930
|
+
const success = 0 === errors.length;
|
|
931
|
+
return success ? {
|
|
932
|
+
success,
|
|
933
|
+
data: input
|
|
934
|
+
} : {
|
|
935
|
+
success,
|
|
936
|
+
errors,
|
|
937
|
+
data: input
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
return {
|
|
941
|
+
success: true,
|
|
942
|
+
data: input
|
|
943
|
+
};
|
|
944
|
+
};
|
|
945
|
+
})()
|
|
946
|
+
}, {
|
|
947
|
+
name: "accept",
|
|
948
|
+
parameters: {
|
|
949
|
+
type: "object",
|
|
950
|
+
properties: {},
|
|
951
|
+
additionalProperties: false,
|
|
952
|
+
required: [],
|
|
953
|
+
$defs: {
|
|
954
|
+
OK: {
|
|
955
|
+
description: "Represents the completion of an asynchronous operation",
|
|
956
|
+
type: "object",
|
|
957
|
+
properties: {
|
|
958
|
+
"__@toStringTag@1672": {
|
|
959
|
+
type: "string"
|
|
960
|
+
}
|
|
961
|
+
},
|
|
962
|
+
required: [ "__@toStringTag@1672" ]
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
},
|
|
966
|
+
output: {
|
|
967
|
+
anyOf: [ {
|
|
968
|
+
$ref: "#/$defs/OK"
|
|
969
|
+
}, {
|
|
970
|
+
type: "string",
|
|
971
|
+
enum: [ "OK" ]
|
|
972
|
+
} ]
|
|
973
|
+
},
|
|
974
|
+
description: "If you decide that you no longer need any reviews, call accept. This is a\nfunction to end document creation and review, and to respond to users.",
|
|
975
|
+
validate: (() => input => ({
|
|
976
|
+
success: true,
|
|
977
|
+
data: input
|
|
978
|
+
}))()
|
|
979
|
+
} ]
|
|
980
|
+
},
|
|
981
|
+
claude: claude$g,
|
|
982
|
+
llama: claude$g,
|
|
983
|
+
deepseek: claude$g,
|
|
984
|
+
3.1: claude$g
|
|
713
985
|
};
|
|
714
986
|
|
|
715
987
|
class AutoBeAnalyzeFileSystem {
|
|
@@ -722,9 +994,6 @@ class AutoBeAnalyzeFileSystem {
|
|
|
722
994
|
}));
|
|
723
995
|
return this.fileMap;
|
|
724
996
|
}
|
|
725
|
-
abort(_input) {
|
|
726
|
-
return "OK";
|
|
727
|
-
}
|
|
728
997
|
}
|
|
729
998
|
|
|
730
999
|
const transformAnalyzeWriteHistories = (ctx, input) => [ ...input.review !== null ? [ {
|
|
@@ -754,19 +1023,13 @@ const transformAnalyzeWriteHistories = (ctx, input) => [ ...input.review !== nul
|
|
|
754
1023
|
text: [ `# Instruction`, `The names of all the files are as follows: ${input.totalFiles.map((f => f.filename)).join(",")}`, "Assume that all files are in the same folder. Also, when pointing to the location of a file, go to the relative path.", "", `The following user roles have been defined for this system:`, ...input.roles.map((role => `- ${role.name}: ${role.description}`)), "These roles will be used for API authentication and should be considered when creating documentation.", "", `Document Length Specification:`, `- You are responsible for writing ONLY ONE document: ${input.targetFile}`, `- Each page should contain approximately 2,000 characters`, `- DO NOT write content for other documents - focus only on ${input.targetFile}`, "", `Among the various documents, the part you decided to take care of is as follows.: ${input.targetFile}`, `Only write this document named '${input.targetFile}'.`, "Never write other documents.", "", "# Reason to write this document", `- ${input.totalFiles.find((el => el.filename === input.targetFile))?.reason}` ].join("\n")
|
|
755
1024
|
} ];
|
|
756
1025
|
|
|
757
|
-
const orchestrateAnalyzeWrite = (ctx, input
|
|
1026
|
+
const orchestrateAnalyzeWrite = (ctx, input) => {
|
|
758
1027
|
const controller = createController({
|
|
759
1028
|
model: ctx.model,
|
|
760
1029
|
execute: new AutoBeAnalyzeFileSystem({
|
|
761
1030
|
[input.targetFile]: ""
|
|
762
1031
|
}),
|
|
763
|
-
|
|
764
|
-
pointer.value ?? (pointer.value = {
|
|
765
|
-
files: {}
|
|
766
|
-
});
|
|
767
|
-
Object.assign(pointer.value.files, files);
|
|
768
|
-
},
|
|
769
|
-
abort: () => isAborted.value = true
|
|
1032
|
+
setDocument: input.setDocument
|
|
770
1033
|
});
|
|
771
1034
|
const agent = new MicroAgentica({
|
|
772
1035
|
controllers: [ controller ],
|
|
@@ -792,14 +1055,9 @@ function createController(props) {
|
|
|
792
1055
|
name: "Planning",
|
|
793
1056
|
application,
|
|
794
1057
|
execute: {
|
|
795
|
-
abort: input => {
|
|
796
|
-
const response = props.execute.abort(input);
|
|
797
|
-
props.abort();
|
|
798
|
-
return response;
|
|
799
|
-
},
|
|
800
1058
|
createOrUpdateFiles: async input => {
|
|
801
1059
|
const fileMap = await props.execute.createOrUpdateFiles(input);
|
|
802
|
-
props.
|
|
1060
|
+
props.setDocument(fileMap);
|
|
803
1061
|
return fileMap;
|
|
804
1062
|
}
|
|
805
1063
|
}
|
|
@@ -930,61 +1188,6 @@ const claude$f = {
|
|
|
930
1188
|
};
|
|
931
1189
|
};
|
|
932
1190
|
})()
|
|
933
|
-
}, {
|
|
934
|
-
name: "abort",
|
|
935
|
-
parameters: {
|
|
936
|
-
type: "object",
|
|
937
|
-
properties: {
|
|
938
|
-
reason: {
|
|
939
|
-
type: "string"
|
|
940
|
-
}
|
|
941
|
-
},
|
|
942
|
-
required: [ "reason" ],
|
|
943
|
-
additionalProperties: false,
|
|
944
|
-
$defs: {}
|
|
945
|
-
},
|
|
946
|
-
output: {
|
|
947
|
-
const: "OK"
|
|
948
|
-
},
|
|
949
|
-
validate: (() => {
|
|
950
|
-
const _io0 = input => "string" === typeof input.reason;
|
|
951
|
-
const _vo0 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, {
|
|
952
|
-
path: _path + ".reason",
|
|
953
|
-
expected: "string",
|
|
954
|
-
value: input.reason
|
|
955
|
-
}) ].every((flag => flag));
|
|
956
|
-
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
957
|
-
let errors;
|
|
958
|
-
let _report;
|
|
959
|
-
return input => {
|
|
960
|
-
if (false === __is(input)) {
|
|
961
|
-
errors = [];
|
|
962
|
-
_report = __typia_transform__validateReport._validateReport(errors);
|
|
963
|
-
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
|
|
964
|
-
path: _path + "",
|
|
965
|
-
expected: "__type",
|
|
966
|
-
value: input
|
|
967
|
-
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
968
|
-
path: _path + "",
|
|
969
|
-
expected: "__type",
|
|
970
|
-
value: input
|
|
971
|
-
}))(input, "$input", true);
|
|
972
|
-
const success = 0 === errors.length;
|
|
973
|
-
return success ? {
|
|
974
|
-
success,
|
|
975
|
-
data: input
|
|
976
|
-
} : {
|
|
977
|
-
success,
|
|
978
|
-
errors,
|
|
979
|
-
data: input
|
|
980
|
-
};
|
|
981
|
-
}
|
|
982
|
-
return {
|
|
983
|
-
success: true,
|
|
984
|
-
data: input
|
|
985
|
-
};
|
|
986
|
-
};
|
|
987
|
-
})()
|
|
988
1191
|
} ]
|
|
989
1192
|
};
|
|
990
1193
|
|
|
@@ -1061,81 +1264,25 @@ const collection$f = {
|
|
|
1061
1264
|
value: elem
|
|
1062
1265
|
})) && _vo1(elem, _path + ".files[" + _index2 + "]", _exceptionable) || _report(_exceptionable, {
|
|
1063
1266
|
path: _path + ".files[" + _index2 + "]",
|
|
1064
|
-
expected: "IFile",
|
|
1065
|
-
value: elem
|
|
1066
|
-
}))).every((flag => flag))) || _report(_exceptionable, {
|
|
1067
|
-
path: _path + ".files",
|
|
1068
|
-
expected: "(Array<IFile> & MinItems<1>)",
|
|
1069
|
-
value: input.files
|
|
1070
|
-
}) ].every((flag => flag));
|
|
1071
|
-
const _vo1 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, {
|
|
1072
|
-
path: _path + ".reason",
|
|
1073
|
-
expected: "string",
|
|
1074
|
-
value: input.reason
|
|
1075
|
-
}), "string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename) || _report(_exceptionable, {
|
|
1076
|
-
path: _path + ".filename",
|
|
1077
|
-
expected: "`${string}.md`",
|
|
1078
|
-
value: input.filename
|
|
1079
|
-
}), "string" === typeof input.markdown || _report(_exceptionable, {
|
|
1080
|
-
path: _path + ".markdown",
|
|
1081
|
-
expected: "string",
|
|
1082
|
-
value: input.markdown
|
|
1083
|
-
}) ].every((flag => flag));
|
|
1084
|
-
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
1085
|
-
let errors;
|
|
1086
|
-
let _report;
|
|
1087
|
-
return input => {
|
|
1088
|
-
if (false === __is(input)) {
|
|
1089
|
-
errors = [];
|
|
1090
|
-
_report = __typia_transform__validateReport._validateReport(errors);
|
|
1091
|
-
((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
|
|
1092
|
-
path: _path + "",
|
|
1093
|
-
expected: "__type",
|
|
1094
|
-
value: input
|
|
1095
|
-
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
1096
|
-
path: _path + "",
|
|
1097
|
-
expected: "__type",
|
|
1098
|
-
value: input
|
|
1099
|
-
}))(input, "$input", true);
|
|
1100
|
-
const success = 0 === errors.length;
|
|
1101
|
-
return success ? {
|
|
1102
|
-
success,
|
|
1103
|
-
data: input
|
|
1104
|
-
} : {
|
|
1105
|
-
success,
|
|
1106
|
-
errors,
|
|
1107
|
-
data: input
|
|
1108
|
-
};
|
|
1109
|
-
}
|
|
1110
|
-
return {
|
|
1111
|
-
success: true,
|
|
1112
|
-
data: input
|
|
1113
|
-
};
|
|
1114
|
-
};
|
|
1115
|
-
})()
|
|
1116
|
-
}, {
|
|
1117
|
-
name: "abort",
|
|
1118
|
-
parameters: {
|
|
1119
|
-
type: "object",
|
|
1120
|
-
properties: {
|
|
1121
|
-
reason: {
|
|
1122
|
-
type: "string"
|
|
1123
|
-
}
|
|
1124
|
-
},
|
|
1125
|
-
required: [ "reason" ],
|
|
1126
|
-
additionalProperties: false,
|
|
1127
|
-
$defs: {}
|
|
1128
|
-
},
|
|
1129
|
-
output: {
|
|
1130
|
-
type: "string",
|
|
1131
|
-
enum: [ "OK" ]
|
|
1132
|
-
},
|
|
1133
|
-
validate: (() => {
|
|
1134
|
-
const _io0 = input => "string" === typeof input.reason;
|
|
1135
|
-
const _vo0 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, {
|
|
1267
|
+
expected: "IFile",
|
|
1268
|
+
value: elem
|
|
1269
|
+
}))).every((flag => flag))) || _report(_exceptionable, {
|
|
1270
|
+
path: _path + ".files",
|
|
1271
|
+
expected: "(Array<IFile> & MinItems<1>)",
|
|
1272
|
+
value: input.files
|
|
1273
|
+
}) ].every((flag => flag));
|
|
1274
|
+
const _vo1 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, {
|
|
1136
1275
|
path: _path + ".reason",
|
|
1137
1276
|
expected: "string",
|
|
1138
1277
|
value: input.reason
|
|
1278
|
+
}), "string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename) || _report(_exceptionable, {
|
|
1279
|
+
path: _path + ".filename",
|
|
1280
|
+
expected: "`${string}.md`",
|
|
1281
|
+
value: input.filename
|
|
1282
|
+
}), "string" === typeof input.markdown || _report(_exceptionable, {
|
|
1283
|
+
path: _path + ".markdown",
|
|
1284
|
+
expected: "string",
|
|
1285
|
+
value: input.markdown
|
|
1139
1286
|
}) ].every((flag => flag));
|
|
1140
1287
|
const __is = input => "object" === typeof input && null !== input && _io0(input);
|
|
1141
1288
|
let errors;
|
|
@@ -1177,53 +1324,72 @@ const collection$f = {
|
|
|
1177
1324
|
3.1: claude$f
|
|
1178
1325
|
};
|
|
1179
1326
|
|
|
1180
|
-
async function writeDocumentUntilReviewPassed(ctx,
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
for (let i = 0; i < retry; i++) {
|
|
1186
|
-
if (isAborted.value === true) {
|
|
1187
|
-
return pointer;
|
|
1327
|
+
async function writeDocumentUntilReviewPassed(ctx, props) {
|
|
1328
|
+
const retry = props.retry ?? 3;
|
|
1329
|
+
const pointer = {
|
|
1330
|
+
value: {
|
|
1331
|
+
files: {}
|
|
1188
1332
|
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1333
|
+
};
|
|
1334
|
+
if (retry === -1) {
|
|
1335
|
+
return pointer;
|
|
1336
|
+
}
|
|
1337
|
+
let isToolCalled = false;
|
|
1338
|
+
const writer = orchestrateAnalyzeWrite(ctx, {
|
|
1339
|
+
totalFiles: props.totalFiles,
|
|
1340
|
+
roles: props.roles,
|
|
1341
|
+
targetFile: props.filename,
|
|
1342
|
+
review: props.prevReview ?? "",
|
|
1343
|
+
setDocument: v => {
|
|
1344
|
+
isToolCalled = true;
|
|
1345
|
+
pointer.value = {
|
|
1346
|
+
files: {
|
|
1347
|
+
...pointer.value?.files,
|
|
1348
|
+
...v
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1202
1351
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
});
|
|
1352
|
+
});
|
|
1353
|
+
await writer.conversate("Write Document.").finally((() => {
|
|
1354
|
+
const tokenUsage = writer.getTokenUsage();
|
|
1355
|
+
ctx.usage().record(tokenUsage, [ "analyze" ]);
|
|
1356
|
+
}));
|
|
1357
|
+
if (isToolCalled === false) {
|
|
1358
|
+
throw new Error("Failed to write document by unknown reason.");
|
|
1359
|
+
}
|
|
1360
|
+
ctx.dispatch({
|
|
1361
|
+
type: "analyzeWrite",
|
|
1362
|
+
files: {
|
|
1363
|
+
...pointer.value?.files
|
|
1364
|
+
},
|
|
1365
|
+
total: props.progress.total,
|
|
1366
|
+
completed: ++props.progress.completed,
|
|
1367
|
+
step: ctx.state().analyze?.step ?? 0,
|
|
1368
|
+
created_at: (new Date).toISOString()
|
|
1369
|
+
});
|
|
1370
|
+
const reviewResult = await orchestrateAnalyzeReviewer(ctx, pointer.value);
|
|
1371
|
+
if (reviewResult.type === "accept") {
|
|
1372
|
+
return pointer;
|
|
1225
1373
|
}
|
|
1226
|
-
|
|
1374
|
+
ctx.dispatch({
|
|
1375
|
+
type: "analyzeReview",
|
|
1376
|
+
files: {
|
|
1377
|
+
...pointer.value.files
|
|
1378
|
+
},
|
|
1379
|
+
review: reviewResult.value,
|
|
1380
|
+
total: props.progress.total,
|
|
1381
|
+
completed: props.progress.completed,
|
|
1382
|
+
step: ctx.state().analyze?.step ?? 0,
|
|
1383
|
+
created_at: (new Date).toISOString()
|
|
1384
|
+
});
|
|
1385
|
+
return await writeDocumentUntilReviewPassed(ctx, {
|
|
1386
|
+
totalFiles: props.totalFiles,
|
|
1387
|
+
filename: props.filename,
|
|
1388
|
+
roles: props.roles,
|
|
1389
|
+
progress: props.progress,
|
|
1390
|
+
retry: retry - 1,
|
|
1391
|
+
prevReview: reviewResult.value
|
|
1392
|
+
});
|
|
1227
1393
|
}
|
|
1228
1394
|
|
|
1229
1395
|
const orchestrateAnalyze = ctx => async props => {
|
|
@@ -1235,15 +1401,18 @@ const orchestrateAnalyze = ctx => async props => {
|
|
|
1235
1401
|
step,
|
|
1236
1402
|
created_at
|
|
1237
1403
|
});
|
|
1238
|
-
const
|
|
1404
|
+
const composeInputPointer = {
|
|
1239
1405
|
value: null
|
|
1240
1406
|
};
|
|
1241
|
-
const agentica = orchestrateAnalyzeComposer(ctx,
|
|
1407
|
+
const agentica = orchestrateAnalyzeComposer(ctx, (v => {
|
|
1408
|
+
composeInputPointer.value = v;
|
|
1409
|
+
}));
|
|
1242
1410
|
const determined = await agentica.conversate([ `Design a complete list of documents and user roles for this project.`, `Define user roles that can authenticate via API and create appropriate documentation files.`, `You must respect the number of documents specified by the user.` ].join("\n")).finally((() => {
|
|
1243
1411
|
const tokenUsage = agentica.getTokenUsage();
|
|
1244
1412
|
ctx.usage().record(tokenUsage, [ "analyze" ]);
|
|
1245
1413
|
}));
|
|
1246
|
-
|
|
1414
|
+
const composeInput = composeInputPointer.value;
|
|
1415
|
+
if (composeInput === null) {
|
|
1247
1416
|
return {
|
|
1248
1417
|
id: v4(),
|
|
1249
1418
|
text: "Failed to analyze your request. please request again.",
|
|
@@ -1252,7 +1421,7 @@ const orchestrateAnalyze = ctx => async props => {
|
|
|
1252
1421
|
created_at: (new Date).toISOString()
|
|
1253
1422
|
};
|
|
1254
1423
|
}
|
|
1255
|
-
const {files: tableOfContents, prefix, roles} =
|
|
1424
|
+
const {files: tableOfContents, prefix, roles} = composeInput;
|
|
1256
1425
|
if (tableOfContents.length === 0) {
|
|
1257
1426
|
const history = {
|
|
1258
1427
|
id: v4(),
|
|
@@ -1273,15 +1442,13 @@ const orchestrateAnalyze = ctx => async props => {
|
|
|
1273
1442
|
total: tableOfContents.length * retryCount,
|
|
1274
1443
|
completed: 0
|
|
1275
1444
|
};
|
|
1276
|
-
const pointers = await Promise.all(tableOfContents.map((async ({filename}) => {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
return pointer;
|
|
1284
|
-
})));
|
|
1445
|
+
const pointers = await Promise.all(tableOfContents.map((async ({filename}) => await writeDocumentUntilReviewPassed(ctx, {
|
|
1446
|
+
totalFiles: tableOfContents,
|
|
1447
|
+
filename,
|
|
1448
|
+
roles,
|
|
1449
|
+
progress,
|
|
1450
|
+
retry: retryCount
|
|
1451
|
+
}))));
|
|
1285
1452
|
const files = pointers.map((pointer => pointer.value?.files ?? {})).reduce(((acc, cur) => Object.assign(acc, cur)));
|
|
1286
1453
|
if (Object.keys(files).length) {
|
|
1287
1454
|
const history = {
|
|
@@ -1314,9 +1481,9 @@ const orchestrateAnalyze = ctx => async props => {
|
|
|
1314
1481
|
completed_at: (new Date).toISOString()
|
|
1315
1482
|
};
|
|
1316
1483
|
ctx.dispatch({
|
|
1317
|
-
type:
|
|
1318
|
-
text:
|
|
1319
|
-
created_at
|
|
1484
|
+
type: history.type,
|
|
1485
|
+
text: history.text,
|
|
1486
|
+
created_at: history.created_at
|
|
1320
1487
|
});
|
|
1321
1488
|
return history;
|
|
1322
1489
|
};
|
|
@@ -4309,7 +4476,7 @@ const transformPrismaComponentsHistories = (state, prefix = null) => {
|
|
|
4309
4476
|
id: v4(),
|
|
4310
4477
|
created_at: (new Date).toISOString(),
|
|
4311
4478
|
type: "assistantMessage",
|
|
4312
|
-
text: [ "Here is the requirement analysis report.", "", "Call the provided tool function to generate Prisma DB schema", "referencing below requirement analysis report.", "",
|
|
4479
|
+
text: [ "Here is the requirement analysis report.", "", "Call the provided tool function to generate Prisma DB schema", "referencing below requirement analysis report.", "", `## Requirement Analysis Report`, "", "```json", JSON.stringify(state.analyze.files), "```", "## Prefix", "", `* Prefix provided by the user: ${prefix}`, "", "The user wants all database schema (table) names to start with the prefix provided below.", "If the prefix is `null`, it should be ignored.", "If a prefix is provided, all table names **must begin with it**.", "However, if there is a special-purpose prefix like `mv` (for materialized views), it **must precede** the given prefix.", "", "## Prefix Example", "", "If the prefix is `shopping`, then table names should be like:", "", "* `shopping_sales`", "* `shopping_sale_options`", "", "In cases where a table is created for performance optimization purposes (e.g., materialized views), the `mv_` prefix must come first.", "For example:", "", "* `mv_shopping_daily_stats`", "", "", state.analyze.roles.length > 0 ? [ "## User Role Handling", "", `The Requirement Analysis Report contains the following user roles: ${state.analyze.roles.join(", ")}.`, "", "**Do not normalize** user roles into a single table.", "Instead, create separate tables for each distinct role mentioned in the requirements.", "", "Create separate tables for each role:", "", state.analyze.roles.map((role => `* ${prefix}_${role.name.toLowerCase()}`)).join("\n"), "" ].join("\n") : "" ].join("\n")
|
|
4313
4480
|
} ];
|
|
4314
4481
|
};
|
|
4315
4482
|
|
|
@@ -7183,7 +7350,7 @@ const transformRealizeAuthorizationCorrectHistories = (ctx, auth, templateFiles,
|
|
|
7183
7350
|
name: auth.payload.name,
|
|
7184
7351
|
content: auth.payload.content
|
|
7185
7352
|
}
|
|
7186
|
-
}, null, 2)}`, "```", "", "## Prisma Schema", "", "```json", `${JSON.stringify(ctx.state().prisma?.schemas, null, 2)}`, "```", "", "## File Paths", "", Object.keys(templateFiles).map((path => `- ${path}`)).join("\n"), "", "## Compile Errors", "", "Fix the compilation error in the provided code.", "", "```json", JSON.stringify(diagnostics, null, 2), "```" ].join("\n")
|
|
7353
|
+
}, null, 2)}`, "```", "", "## Prisma Schema", "", "```json", `${JSON.stringify(ctx.state().prisma?.schemas, null, 2)}`, "```", "", "## File Paths", "", Object.keys(templateFiles).map((path => `- ${path}`)).join("\n"), "", "## Compile Errors", "", "Fix the compilation error in the provided code.", "", "```json", JSON.stringify(diagnostics, null, 2), "```", "## Component Naming Convention", "", "If the name of the component is not correct, please correct it.", "", "Please follow this naming convention for the authorization components:", "", `- Provider Name: ${auth.role.toLowerCase()}Authorize (e.g. ${auth.role.toLowerCase()}Authorize)`, `- Decorator Name: ${auth.role.charAt(0).toUpperCase() + auth.role.slice(1).toLowerCase()}Auth (e.g. ${auth.role.charAt(0).toUpperCase() + auth.role.slice(1).toLowerCase()}Auth)`, `- Payload Name: ${auth.role.charAt(0).toUpperCase() + auth.role.slice(1).toLowerCase()}Payload (e.g. ${auth.role.charAt(0).toUpperCase() + auth.role.slice(1).toLowerCase()}Payload)` ].join("\n")
|
|
7187
7354
|
} ];
|
|
7188
7355
|
|
|
7189
7356
|
var AuthorizationFileSystem;
|
|
@@ -7194,15 +7361,49 @@ var AuthorizationFileSystem;
|
|
|
7194
7361
|
AuthorizationFileSystem.providerPath = name => `src/providers/authorize/${name}.ts`;
|
|
7195
7362
|
})(AuthorizationFileSystem || (AuthorizationFileSystem = {}));
|
|
7196
7363
|
|
|
7364
|
+
var AutoBeRealizeAuthorizationReplaceImport;
|
|
7365
|
+
|
|
7366
|
+
(function(AutoBeRealizeAuthorizationReplaceImport) {
|
|
7367
|
+
function replaceProviderImport(role, content) {
|
|
7368
|
+
let updatedContent = content;
|
|
7369
|
+
const roleCapitalized = role.charAt(0).toUpperCase() + role.slice(1).toLowerCase();
|
|
7370
|
+
const nestjsCommonPattern = /import\s+{\s*[^}]*\s*}\s+from\s+"@nestjs\/common";/g;
|
|
7371
|
+
const nestjsCommonReplacement = 'import { ForbiddenException, UnauthorizedException } from "@nestjs/common";';
|
|
7372
|
+
const myGlobalPattern = /import\s+{\s*MyGlobal\s*}\s+from\s+[^;]+;/g;
|
|
7373
|
+
const myGlobalReplacement = 'import { MyGlobal } from "../../MyGlobal";';
|
|
7374
|
+
const jwtAuthorizePattern = /import\s+{\s*jwtAuthorize\s*}\s+from\s+[^;]+;/g;
|
|
7375
|
+
const jwtAuthorizeReplacement = 'import { jwtAuthorize } from "./jwtAuthorize";';
|
|
7376
|
+
const payloadPattern = /import\s+{\s*\w*Payload\s*}\s+from\s+[^;]+;/g;
|
|
7377
|
+
const payloadReplacement = `import { ${roleCapitalized}Payload } from "../../decorators/payload/${roleCapitalized}Payload";`;
|
|
7378
|
+
updatedContent = updatedContent.replace(nestjsCommonPattern, nestjsCommonReplacement);
|
|
7379
|
+
updatedContent = updatedContent.replace(myGlobalPattern, myGlobalReplacement);
|
|
7380
|
+
updatedContent = updatedContent.replace(jwtAuthorizePattern, jwtAuthorizeReplacement);
|
|
7381
|
+
updatedContent = updatedContent.replace(payloadPattern, payloadReplacement);
|
|
7382
|
+
return updatedContent;
|
|
7383
|
+
}
|
|
7384
|
+
AutoBeRealizeAuthorizationReplaceImport.replaceProviderImport = replaceProviderImport;
|
|
7385
|
+
function replaceDecoratorImport(role, content) {
|
|
7386
|
+
let updatedContent = content;
|
|
7387
|
+
const roleLowercase = role.toLowerCase();
|
|
7388
|
+
const authorizePattern = /import\s+{\s*\w*Authorize\s*}\s+from\s+[^;]+;/g;
|
|
7389
|
+
const authorizeReplacement = `import { ${roleLowercase}Authorize } from "../providers/authorize/${roleLowercase}Authorize";`;
|
|
7390
|
+
updatedContent = updatedContent.replace(authorizePattern, authorizeReplacement);
|
|
7391
|
+
return updatedContent;
|
|
7392
|
+
}
|
|
7393
|
+
AutoBeRealizeAuthorizationReplaceImport.replaceDecoratorImport = replaceDecoratorImport;
|
|
7394
|
+
})(AutoBeRealizeAuthorizationReplaceImport || (AutoBeRealizeAuthorizationReplaceImport = {}));
|
|
7395
|
+
|
|
7197
7396
|
async function orchestrateRealizeAuthorizationCorrect(ctx, authorization, prismaClients, templateFiles, life = 4) {
|
|
7397
|
+
const compiler = await ctx.compiler();
|
|
7398
|
+
const providerContent = await compiler.typescript.beautify(AutoBeRealizeAuthorizationReplaceImport.replaceProviderImport(authorization.role, authorization.provider.content));
|
|
7399
|
+
const decoratorContent = await compiler.typescript.beautify(AutoBeRealizeAuthorizationReplaceImport.replaceDecoratorImport(authorization.role, authorization.decorator.content));
|
|
7198
7400
|
const files = {
|
|
7199
7401
|
...templateFiles,
|
|
7200
7402
|
...prismaClients,
|
|
7201
|
-
[AuthorizationFileSystem.decoratorPath(authorization.decorator.name)]:
|
|
7202
|
-
[AuthorizationFileSystem.providerPath(authorization.provider.name)]:
|
|
7403
|
+
[AuthorizationFileSystem.decoratorPath(authorization.decorator.name)]: decoratorContent,
|
|
7404
|
+
[AuthorizationFileSystem.providerPath(authorization.provider.name)]: providerContent,
|
|
7203
7405
|
[AuthorizationFileSystem.payloadPath(authorization.payload.name)]: authorization.payload.content
|
|
7204
7406
|
};
|
|
7205
|
-
const compiler = await ctx.compiler();
|
|
7206
7407
|
const compiled = await compiler.typescript.compile({
|
|
7207
7408
|
files
|
|
7208
7409
|
});
|
|
@@ -7255,8 +7456,9 @@ async function orchestrateRealizeAuthorizationCorrect(ctx, authorization, prisma
|
|
|
7255
7456
|
location: AuthorizationFileSystem.providerPath(pointer.value.provider.name)
|
|
7256
7457
|
},
|
|
7257
7458
|
payload: {
|
|
7258
|
-
|
|
7259
|
-
location: AuthorizationFileSystem.payloadPath(pointer.value.payload.name)
|
|
7459
|
+
name: pointer.value.payload.name,
|
|
7460
|
+
location: AuthorizationFileSystem.payloadPath(pointer.value.payload.name),
|
|
7461
|
+
content: await compiler.typescript.beautify(pointer.value.payload.content)
|
|
7260
7462
|
},
|
|
7261
7463
|
role: authorization.role
|
|
7262
7464
|
};
|
|
@@ -7299,15 +7501,11 @@ const claude$6 = {
|
|
|
7299
7501
|
type: "object",
|
|
7300
7502
|
properties: {
|
|
7301
7503
|
error_analysis: {
|
|
7302
|
-
description: "Step 1: TypeScript compilation error analysis and diagnosis.\n\nAI identifies all compilation errors (type mismatches
|
|
7504
|
+
description: "Step 1: TypeScript compilation error analysis and diagnosis.\n\nAI identifies and categorizes all compilation errors (type mismatches,\nimport issues, syntax errors) by component (providers/decorator/payload).\nLists specific error messages with their locations and types for\nsystematic troubleshooting.",
|
|
7303
7505
|
type: "string"
|
|
7304
7506
|
},
|
|
7305
|
-
|
|
7306
|
-
description:
|
|
7307
|
-
type: "string"
|
|
7308
|
-
},
|
|
7309
|
-
validation_summary: {
|
|
7310
|
-
description: "Step 3: Final validation and comprehensive fix summary.\n\nAI validates corrected code compiles successfully and documents all\nchanges made. Provides production-ready code with detailed change log for\nmaintenance reference.",
|
|
7507
|
+
solution_guidance: {
|
|
7508
|
+
description: 'Step 2: Solution guidance and fix recommendations.\n\nAI provides clear, actionable instructions on how to resolve each\nidentified error. Includes specific steps like "add property X to\ninterface Y", "update import path from A to B", or "change type from C to\nD". Focus on guidance rather than generating complete code\nimplementations.',
|
|
7311
7509
|
type: "string"
|
|
7312
7510
|
},
|
|
7313
7511
|
provider: {
|
|
@@ -7323,7 +7521,7 @@ const claude$6 = {
|
|
|
7323
7521
|
$ref: "#/$defs/IAutoBeRealizeAuthorizationApplication.IPayloadType"
|
|
7324
7522
|
}
|
|
7325
7523
|
},
|
|
7326
|
-
required: [ "error_analysis", "
|
|
7524
|
+
required: [ "error_analysis", "solution_guidance", "provider", "decorator", "payload" ],
|
|
7327
7525
|
additionalProperties: false,
|
|
7328
7526
|
$defs: {
|
|
7329
7527
|
"IAutoBeRealizeAuthorizationApplication.IProvider": {
|
|
@@ -7334,7 +7532,7 @@ const claude$6 = {
|
|
|
7334
7532
|
type: "string"
|
|
7335
7533
|
},
|
|
7336
7534
|
content: {
|
|
7337
|
-
description: "Complete TypeScript code for the authentication Provider function
|
|
7535
|
+
description: "Complete TypeScript code for the authentication Provider function. Must\ninclude: JWT token verification using jwtAuthorize function, role type\nchecking against payload.type, database query using\nMyGlobal.prisma.{tableName} pattern to verify user existence, and proper\nerror handling with ForbiddenException and UnauthorizedException. The\nfunction should return the authenticated user payload data.",
|
|
7338
7536
|
type: "string"
|
|
7339
7537
|
}
|
|
7340
7538
|
},
|
|
@@ -7358,11 +7556,11 @@ const claude$6 = {
|
|
|
7358
7556
|
type: "object",
|
|
7359
7557
|
properties: {
|
|
7360
7558
|
name: {
|
|
7361
|
-
description: "The name of the
|
|
7559
|
+
description: "The name of the Payload type to be generated in {Role}Payload format\n(e.g., AdminPayload, UserPayload). This type defines the structure of the\nauthenticated user data that will be injected into Controller methods\nwhen using the decorator.",
|
|
7362
7560
|
type: "string"
|
|
7363
7561
|
},
|
|
7364
7562
|
content: {
|
|
7365
|
-
description: "
|
|
7563
|
+
description: "Complete TypeScript code for the Payload type interface in {Role}Payload\nformat (e.g., AdminPayload, UserPayload). Must include: id field with\nUUID format validation, type field as role discriminator, and proper\ntypia tags for validation. This interface defines the structure of the\nauthenticated user data that will be injected into Controller methods\nwhen using the decorator and serves as the TypeScript type for the\nparameter in Controller method signatures.",
|
|
7366
7564
|
type: "string"
|
|
7367
7565
|
}
|
|
7368
7566
|
},
|
|
@@ -7371,7 +7569,7 @@ const claude$6 = {
|
|
|
7371
7569
|
}
|
|
7372
7570
|
},
|
|
7373
7571
|
validate: (() => {
|
|
7374
|
-
const _io0 = input => "string" === typeof input.error_analysis && "string" === typeof input.
|
|
7572
|
+
const _io0 = input => "string" === typeof input.error_analysis && "string" === typeof input.solution_guidance && ("object" === typeof input.provider && null !== input.provider && _io1(input.provider)) && ("object" === typeof input.decorator && null !== input.decorator && _io2(input.decorator)) && ("object" === typeof input.payload && null !== input.payload && _io3(input.payload));
|
|
7375
7573
|
const _io1 = input => "string" === typeof input.name && "string" === typeof input.content;
|
|
7376
7574
|
const _io2 = input => "string" === typeof input.name && "string" === typeof input.content;
|
|
7377
7575
|
const _io3 = input => "string" === typeof input.name && "string" === typeof input.content;
|
|
@@ -7379,14 +7577,10 @@ const claude$6 = {
|
|
|
7379
7577
|
path: _path + ".error_analysis",
|
|
7380
7578
|
expected: "string",
|
|
7381
7579
|
value: input.error_analysis
|
|
7382
|
-
}), "string" === typeof input.
|
|
7383
|
-
path: _path + ".
|
|
7384
|
-
expected: "string",
|
|
7385
|
-
value: input.corrected_implementation
|
|
7386
|
-
}), "string" === typeof input.validation_summary || _report(_exceptionable, {
|
|
7387
|
-
path: _path + ".validation_summary",
|
|
7580
|
+
}), "string" === typeof input.solution_guidance || _report(_exceptionable, {
|
|
7581
|
+
path: _path + ".solution_guidance",
|
|
7388
7582
|
expected: "string",
|
|
7389
|
-
value: input.
|
|
7583
|
+
value: input.solution_guidance
|
|
7390
7584
|
}), ("object" === typeof input.provider && null !== input.provider || _report(_exceptionable, {
|
|
7391
7585
|
path: _path + ".provider",
|
|
7392
7586
|
expected: "IAutoBeRealizeAuthorizationApplication.IProvider",
|
|
@@ -7489,15 +7683,11 @@ const collection$6 = {
|
|
|
7489
7683
|
type: "object",
|
|
7490
7684
|
properties: {
|
|
7491
7685
|
error_analysis: {
|
|
7492
|
-
description: "Step 1: TypeScript compilation error analysis and diagnosis.\n\nAI identifies all compilation errors (type mismatches
|
|
7686
|
+
description: "Step 1: TypeScript compilation error analysis and diagnosis.\n\nAI identifies and categorizes all compilation errors (type mismatches,\nimport issues, syntax errors) by component (providers/decorator/payload).\nLists specific error messages with their locations and types for\nsystematic troubleshooting.",
|
|
7493
7687
|
type: "string"
|
|
7494
7688
|
},
|
|
7495
|
-
|
|
7496
|
-
description:
|
|
7497
|
-
type: "string"
|
|
7498
|
-
},
|
|
7499
|
-
validation_summary: {
|
|
7500
|
-
description: "Step 3: Final validation and comprehensive fix summary.\n\nAI validates corrected code compiles successfully and documents all\nchanges made. Provides production-ready code with detailed change log for\nmaintenance reference.",
|
|
7689
|
+
solution_guidance: {
|
|
7690
|
+
description: 'Step 2: Solution guidance and fix recommendations.\n\nAI provides clear, actionable instructions on how to resolve each\nidentified error. Includes specific steps like "add property X to\ninterface Y", "update import path from A to B", or "change type from C to\nD". Focus on guidance rather than generating complete code\nimplementations.',
|
|
7501
7691
|
type: "string"
|
|
7502
7692
|
},
|
|
7503
7693
|
provider: {
|
|
@@ -7510,7 +7700,7 @@ const collection$6 = {
|
|
|
7510
7700
|
$ref: "#/$defs/IAutoBeRealizeAuthorizationApplication.IPayloadType"
|
|
7511
7701
|
}
|
|
7512
7702
|
},
|
|
7513
|
-
required: [ "error_analysis", "
|
|
7703
|
+
required: [ "error_analysis", "solution_guidance", "provider", "decorator", "payload" ],
|
|
7514
7704
|
additionalProperties: false,
|
|
7515
7705
|
$defs: {
|
|
7516
7706
|
"IAutoBeRealizeAuthorizationApplication.IProvider": {
|
|
@@ -7521,7 +7711,7 @@ const collection$6 = {
|
|
|
7521
7711
|
type: "string"
|
|
7522
7712
|
},
|
|
7523
7713
|
content: {
|
|
7524
|
-
description: "Complete TypeScript code for the authentication Provider function
|
|
7714
|
+
description: "Complete TypeScript code for the authentication Provider function. Must\ninclude: JWT token verification using jwtAuthorize function, role type\nchecking against payload.type, database query using\nMyGlobal.prisma.{tableName} pattern to verify user existence, and proper\nerror handling with ForbiddenException and UnauthorizedException. The\nfunction should return the authenticated user payload data.",
|
|
7525
7715
|
type: "string"
|
|
7526
7716
|
}
|
|
7527
7717
|
},
|
|
@@ -7545,11 +7735,11 @@ const collection$6 = {
|
|
|
7545
7735
|
type: "object",
|
|
7546
7736
|
properties: {
|
|
7547
7737
|
name: {
|
|
7548
|
-
description: "The name of the
|
|
7738
|
+
description: "The name of the Payload type to be generated in {Role}Payload format\n(e.g., AdminPayload, UserPayload). This type defines the structure of the\nauthenticated user data that will be injected into Controller methods\nwhen using the decorator.",
|
|
7549
7739
|
type: "string"
|
|
7550
7740
|
},
|
|
7551
7741
|
content: {
|
|
7552
|
-
description: "
|
|
7742
|
+
description: "Complete TypeScript code for the Payload type interface in {Role}Payload\nformat (e.g., AdminPayload, UserPayload). Must include: id field with\nUUID format validation, type field as role discriminator, and proper\ntypia tags for validation. This interface defines the structure of the\nauthenticated user data that will be injected into Controller methods\nwhen using the decorator and serves as the TypeScript type for the\nparameter in Controller method signatures.",
|
|
7553
7743
|
type: "string"
|
|
7554
7744
|
}
|
|
7555
7745
|
},
|
|
@@ -7558,7 +7748,7 @@ const collection$6 = {
|
|
|
7558
7748
|
}
|
|
7559
7749
|
},
|
|
7560
7750
|
validate: (() => {
|
|
7561
|
-
const _io0 = input => "string" === typeof input.error_analysis && "string" === typeof input.
|
|
7751
|
+
const _io0 = input => "string" === typeof input.error_analysis && "string" === typeof input.solution_guidance && ("object" === typeof input.provider && null !== input.provider && _io1(input.provider)) && ("object" === typeof input.decorator && null !== input.decorator && _io2(input.decorator)) && ("object" === typeof input.payload && null !== input.payload && _io3(input.payload));
|
|
7562
7752
|
const _io1 = input => "string" === typeof input.name && "string" === typeof input.content;
|
|
7563
7753
|
const _io2 = input => "string" === typeof input.name && "string" === typeof input.content;
|
|
7564
7754
|
const _io3 = input => "string" === typeof input.name && "string" === typeof input.content;
|
|
@@ -7566,14 +7756,10 @@ const collection$6 = {
|
|
|
7566
7756
|
path: _path + ".error_analysis",
|
|
7567
7757
|
expected: "string",
|
|
7568
7758
|
value: input.error_analysis
|
|
7569
|
-
}), "string" === typeof input.
|
|
7570
|
-
path: _path + ".
|
|
7571
|
-
expected: "string",
|
|
7572
|
-
value: input.corrected_implementation
|
|
7573
|
-
}), "string" === typeof input.validation_summary || _report(_exceptionable, {
|
|
7574
|
-
path: _path + ".validation_summary",
|
|
7759
|
+
}), "string" === typeof input.solution_guidance || _report(_exceptionable, {
|
|
7760
|
+
path: _path + ".solution_guidance",
|
|
7575
7761
|
expected: "string",
|
|
7576
|
-
value: input.
|
|
7762
|
+
value: input.solution_guidance
|
|
7577
7763
|
}), ("object" === typeof input.provider && null !== input.provider || _report(_exceptionable, {
|
|
7578
7764
|
path: _path + ".provider",
|
|
7579
7765
|
expected: "IAutoBeRealizeAuthorizationApplication.IProvider",
|
|
@@ -7675,7 +7861,7 @@ const transformRealizeAuthorizationHistories = (ctx, role) => [ {
|
|
|
7675
7861
|
id: v4(),
|
|
7676
7862
|
created_at: (new Date).toISOString(),
|
|
7677
7863
|
type: "systemMessage",
|
|
7678
|
-
text: [ "## Role", "", role, "", "## Prisma Schema", "", JSON.stringify(ctx.state().prisma?.schemas, null, 2), "", "##
|
|
7864
|
+
text: [ "## Role", "", role, "", "## Prisma Schema", "", JSON.stringify(ctx.state().prisma?.schemas, null, 2), "", "## Component Naming Convention", "", "Please follow this naming convention for the authorization components:", "", `- Provider Name: ${role}Authorize (e.g. ${role}Authorize)`, `- Decorator Name: ${role.charAt(0).toUpperCase() + role.slice(1)}Auth (e.g. ${role.charAt(0).toUpperCase() + role.slice(1)}Auth)`, `- Payload Name: ${role.charAt(0).toUpperCase() + role.slice(1)}Payload (e.g. ${role.charAt(0).toUpperCase() + role.slice(1)}Payload)` ].join("\n")
|
|
7679
7865
|
} ];
|
|
7680
7866
|
|
|
7681
7867
|
var InternalFileSystem;
|
|
@@ -7685,7 +7871,7 @@ var InternalFileSystem;
|
|
|
7685
7871
|
})(InternalFileSystem || (InternalFileSystem = {}));
|
|
7686
7872
|
|
|
7687
7873
|
async function orchestrateRealizeAuthorization(ctx) {
|
|
7688
|
-
const roles = ctx.state().
|
|
7874
|
+
const roles = ctx.state().analyze?.roles.map((role => role.name)) ?? [];
|
|
7689
7875
|
let completed = 0;
|
|
7690
7876
|
const templateFiles = await (await ctx.compiler()).realize.getTemplate();
|
|
7691
7877
|
ctx.dispatch({
|
|
@@ -7742,6 +7928,7 @@ async function process$2(ctx, role, templateFiles) {
|
|
|
7742
7928
|
ctx.usage().record(tokenUsage, [ "realize" ]);
|
|
7743
7929
|
}));
|
|
7744
7930
|
if (pointer.value === null) throw new Error("Failed to create decorator.");
|
|
7931
|
+
const compiler = await ctx.compiler();
|
|
7745
7932
|
const authorization = {
|
|
7746
7933
|
role,
|
|
7747
7934
|
decorator: {
|
|
@@ -7752,7 +7939,7 @@ async function process$2(ctx, role, templateFiles) {
|
|
|
7752
7939
|
payload: {
|
|
7753
7940
|
location: AuthorizationFileSystem.payloadPath(pointer.value.payload.name),
|
|
7754
7941
|
name: pointer.value.payload.name,
|
|
7755
|
-
content: pointer.value.payload.content
|
|
7942
|
+
content: await compiler.typescript.beautify(pointer.value.payload.content)
|
|
7756
7943
|
},
|
|
7757
7944
|
provider: {
|
|
7758
7945
|
location: AuthorizationFileSystem.providerPath(pointer.value.provider.name),
|
|
@@ -7762,82 +7949,7 @@ async function process$2(ctx, role, templateFiles) {
|
|
|
7762
7949
|
};
|
|
7763
7950
|
const compiled = ctx.state().prisma?.compiled;
|
|
7764
7951
|
const prismaClients = compiled?.type === "success" ? compiled.nodeModules : {};
|
|
7765
|
-
return
|
|
7766
|
-
}
|
|
7767
|
-
|
|
7768
|
-
async function correctDecorator(ctx, auth, prismaClients, templateFiles, life = 4) {
|
|
7769
|
-
const files = {
|
|
7770
|
-
...templateFiles,
|
|
7771
|
-
...prismaClients,
|
|
7772
|
-
[auth.decorator.location]: auth.decorator.content,
|
|
7773
|
-
[auth.payload.location]: auth.payload.content,
|
|
7774
|
-
[auth.provider.location]: auth.provider.content
|
|
7775
|
-
};
|
|
7776
|
-
const compiler = await ctx.compiler();
|
|
7777
|
-
const result = await compiler.typescript.compile({
|
|
7778
|
-
files
|
|
7779
|
-
});
|
|
7780
|
-
ctx.dispatch({
|
|
7781
|
-
type: "realizeAuthorizationValidate",
|
|
7782
|
-
created_at: (new Date).toISOString(),
|
|
7783
|
-
result,
|
|
7784
|
-
authorization: auth,
|
|
7785
|
-
step: ctx.state().test?.step ?? 0
|
|
7786
|
-
});
|
|
7787
|
-
if (result.type === "success") {
|
|
7788
|
-
return auth;
|
|
7789
|
-
} else if (result.type === "exception" || life === 0) {
|
|
7790
|
-
return auth;
|
|
7791
|
-
}
|
|
7792
|
-
const pointer = {
|
|
7793
|
-
value: null
|
|
7794
|
-
};
|
|
7795
|
-
const agentica = new MicroAgentica({
|
|
7796
|
-
model: ctx.model,
|
|
7797
|
-
vendor: ctx.vendor,
|
|
7798
|
-
config: {
|
|
7799
|
-
...ctx.config ?? {},
|
|
7800
|
-
executor: {
|
|
7801
|
-
describe: null
|
|
7802
|
-
}
|
|
7803
|
-
},
|
|
7804
|
-
histories: transformRealizeAuthorizationCorrectHistories(ctx, auth, templateFiles, result.diagnostics),
|
|
7805
|
-
controllers: [ createApplication$4({
|
|
7806
|
-
model: ctx.model,
|
|
7807
|
-
build: next => {
|
|
7808
|
-
pointer.value = next;
|
|
7809
|
-
}
|
|
7810
|
-
}) ]
|
|
7811
|
-
});
|
|
7812
|
-
enforceToolCall(agentica);
|
|
7813
|
-
await agentica.conversate("Please correct the decorator and the provider.").finally((() => {
|
|
7814
|
-
const tokenUsage = agentica.getTokenUsage();
|
|
7815
|
-
ctx.usage().record(tokenUsage, [ "realize" ]);
|
|
7816
|
-
}));
|
|
7817
|
-
if (pointer.value === null) throw new Error("Failed to correct decorator.");
|
|
7818
|
-
const corrected = {
|
|
7819
|
-
role: auth.role,
|
|
7820
|
-
decorator: {
|
|
7821
|
-
location: auth.decorator.location,
|
|
7822
|
-
name: pointer.value.decorator.name,
|
|
7823
|
-
content: pointer.value.decorator.content
|
|
7824
|
-
},
|
|
7825
|
-
payload: {
|
|
7826
|
-
location: auth.payload.location,
|
|
7827
|
-
name: pointer.value.payload.name,
|
|
7828
|
-
content: pointer.value.payload.content
|
|
7829
|
-
},
|
|
7830
|
-
provider: {
|
|
7831
|
-
location: auth.provider.location,
|
|
7832
|
-
name: pointer.value.provider.name,
|
|
7833
|
-
content: pointer.value.provider.content
|
|
7834
|
-
}
|
|
7835
|
-
};
|
|
7836
|
-
const res = await orchestrateRealizeAuthorizationCorrect(ctx, corrected, prismaClients, templateFiles, life - 1);
|
|
7837
|
-
return {
|
|
7838
|
-
...res,
|
|
7839
|
-
role: auth.role
|
|
7840
|
-
};
|
|
7952
|
+
return orchestrateRealizeAuthorizationCorrect(ctx, authorization, prismaClients, templateFiles);
|
|
7841
7953
|
}
|
|
7842
7954
|
|
|
7843
7955
|
function createApplication$4(props) {
|
|
@@ -7891,7 +8003,7 @@ const claude$5 = {
|
|
|
7891
8003
|
type: "string"
|
|
7892
8004
|
},
|
|
7893
8005
|
content: {
|
|
7894
|
-
description: "Complete TypeScript code for the authentication Provider function
|
|
8006
|
+
description: "Complete TypeScript code for the authentication Provider function. Must\ninclude: JWT token verification using jwtAuthorize function, role type\nchecking against payload.type, database query using\nMyGlobal.prisma.{tableName} pattern to verify user existence, and proper\nerror handling with ForbiddenException and UnauthorizedException. The\nfunction should return the authenticated user payload data.",
|
|
7895
8007
|
type: "string"
|
|
7896
8008
|
}
|
|
7897
8009
|
},
|
|
@@ -7915,11 +8027,11 @@ const claude$5 = {
|
|
|
7915
8027
|
type: "object",
|
|
7916
8028
|
properties: {
|
|
7917
8029
|
name: {
|
|
7918
|
-
description: "The name of the
|
|
8030
|
+
description: "The name of the Payload type to be generated in {Role}Payload format\n(e.g., AdminPayload, UserPayload). This type defines the structure of the\nauthenticated user data that will be injected into Controller methods\nwhen using the decorator.",
|
|
7919
8031
|
type: "string"
|
|
7920
8032
|
},
|
|
7921
8033
|
content: {
|
|
7922
|
-
description: "
|
|
8034
|
+
description: "Complete TypeScript code for the Payload type interface in {Role}Payload\nformat (e.g., AdminPayload, UserPayload). Must include: id field with\nUUID format validation, type field as role discriminator, and proper\ntypia tags for validation. This interface defines the structure of the\nauthenticated user data that will be injected into Controller methods\nwhen using the decorator and serves as the TypeScript type for the\nparameter in Controller method signatures.",
|
|
7923
8035
|
type: "string"
|
|
7924
8036
|
}
|
|
7925
8037
|
},
|
|
@@ -8054,7 +8166,7 @@ const collection$5 = {
|
|
|
8054
8166
|
type: "string"
|
|
8055
8167
|
},
|
|
8056
8168
|
content: {
|
|
8057
|
-
description: "Complete TypeScript code for the authentication Provider function
|
|
8169
|
+
description: "Complete TypeScript code for the authentication Provider function. Must\ninclude: JWT token verification using jwtAuthorize function, role type\nchecking against payload.type, database query using\nMyGlobal.prisma.{tableName} pattern to verify user existence, and proper\nerror handling with ForbiddenException and UnauthorizedException. The\nfunction should return the authenticated user payload data.",
|
|
8058
8170
|
type: "string"
|
|
8059
8171
|
}
|
|
8060
8172
|
},
|
|
@@ -8078,11 +8190,11 @@ const collection$5 = {
|
|
|
8078
8190
|
type: "object",
|
|
8079
8191
|
properties: {
|
|
8080
8192
|
name: {
|
|
8081
|
-
description: "The name of the
|
|
8193
|
+
description: "The name of the Payload type to be generated in {Role}Payload format\n(e.g., AdminPayload, UserPayload). This type defines the structure of the\nauthenticated user data that will be injected into Controller methods\nwhen using the decorator.",
|
|
8082
8194
|
type: "string"
|
|
8083
8195
|
},
|
|
8084
8196
|
content: {
|
|
8085
|
-
description: "
|
|
8197
|
+
description: "Complete TypeScript code for the Payload type interface in {Role}Payload\nformat (e.g., AdminPayload, UserPayload). Must include: id field with\nUUID format validation, type field as role discriminator, and proper\ntypia tags for validation. This interface defines the structure of the\nauthenticated user data that will be injected into Controller methods\nwhen using the decorator and serves as the TypeScript type for the\nparameter in Controller method signatures.",
|
|
8086
8198
|
type: "string"
|
|
8087
8199
|
}
|
|
8088
8200
|
},
|
|
@@ -8187,19 +8299,18 @@ const collection$5 = {
|
|
|
8187
8299
|
3.1: claude$5
|
|
8188
8300
|
};
|
|
8189
8301
|
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8302
|
+
var ProviderCodeComparator;
|
|
8303
|
+
|
|
8304
|
+
(function(ProviderCodeComparator) {
|
|
8305
|
+
function hashCode(e) {
|
|
8306
|
+
return hash(e.path, e.method);
|
|
8195
8307
|
}
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
}))).reduce(((acc, cur) => Object.assign(acc, cur)), {});
|
|
8308
|
+
ProviderCodeComparator.hashCode = hashCode;
|
|
8309
|
+
function equals(x, y) {
|
|
8310
|
+
return x.path === y.path && x.method === y.method;
|
|
8200
8311
|
}
|
|
8201
|
-
|
|
8202
|
-
}
|
|
8312
|
+
ProviderCodeComparator.equals = equals;
|
|
8313
|
+
})(ProviderCodeComparator || (ProviderCodeComparator = {}));
|
|
8203
8314
|
|
|
8204
8315
|
const FAILED = Symbol("FAILED");
|
|
8205
8316
|
|
|
@@ -8313,7 +8424,20 @@ function filterDocument(scenario, document) {
|
|
|
8313
8424
|
};
|
|
8314
8425
|
}
|
|
8315
8426
|
|
|
8316
|
-
const transformRealizeCoderHistories = (state, props, artifacts, previous, diagnostics) => {
|
|
8427
|
+
const transformRealizeCoderHistories = (state, previousCodes, props, artifacts, previous, diagnostics, authorization) => {
|
|
8428
|
+
const [operation] = artifacts.document.operations;
|
|
8429
|
+
const propsFields = [];
|
|
8430
|
+
if (authorization && operation.authorizationRole) {
|
|
8431
|
+
propsFields.push(`${operation.authorizationRole}: ${authorization.payload.name};`);
|
|
8432
|
+
}
|
|
8433
|
+
operation.parameters.forEach((parameter => {
|
|
8434
|
+
const format = "format" in parameter.schema ? ` & tags.Format<'${parameter.schema.format}'>` : "";
|
|
8435
|
+
propsFields.push(`${parameter.name}: ${parameter.schema.type}${format};`);
|
|
8436
|
+
}));
|
|
8437
|
+
if (operation.requestBody?.typeName) {
|
|
8438
|
+
propsFields.push(`body: ${operation.requestBody.typeName};`);
|
|
8439
|
+
}
|
|
8440
|
+
const input = propsFields.length > 0 ? `props: {\n${propsFields.map((field => ` ${field}`)).join("\n")}\n}` : `// No props parameter needed - function should have no parameters`;
|
|
8317
8441
|
if (state.analyze === null) return [ {
|
|
8318
8442
|
id: v4(),
|
|
8319
8443
|
created_at: (new Date).toISOString(),
|
|
@@ -8344,18 +8468,18 @@ const transformRealizeCoderHistories = (state, props, artifacts, previous, diagn
|
|
|
8344
8468
|
id: v4(),
|
|
8345
8469
|
created_at: (new Date).toISOString(),
|
|
8346
8470
|
type: "systemMessage",
|
|
8347
|
-
text: "# 🧠 Realize Agent Role\n\nYou are the **Realize Coder Agent**, an expert-level backend developer trained to implement production-grade TypeScript logic in a consistent, type-safe, and maintainable format.\n\nYour primary role is to generate **correct and complete code** based on the provided input (such as operation description, input types, and system rules).\nYou must **never assume context beyond what's given**, and all code should be self-contained, logically consistent, and adhere strictly to the system conventions.\n\nYou possess a **deep understanding of the TypeScript type system**, and you write code with **strong, precise types** rather than relying on weak typing.\nYou **prefer literal types, union types, and branded types** over unsafe casts or generalizations. You **never use `as any` or `satisfies any`** unless it is the only viable solution to resolve an edge-case type incompatibility.\n\n## 🚨 ABSOLUTE CRITICAL RULES (VIOLATIONS INVALIDATE ENTIRE CODE)\n\n1. **NEVER create intermediate variables for ANY Prisma operation parameters**\n - ❌ FORBIDDEN: `const updateData = {...}; await prisma.update({data: updateData})`\n - ❌ FORBIDDEN: `const where = {...}; await prisma.findMany({where})`\n - ❌ FORBIDDEN: `const where: Record<string, unknown> = {...}` - WORST VIOLATION!\n - ❌ FORBIDDEN: `const orderBy = {...}; await prisma.findMany({orderBy})`\n - ✅ REQUIRED: Define all parameters inline:\n ```typescript\n await prisma.findMany({\n where: {\n name: { contains: searchTerm },\n enabled: true\n },\n orderBy: { created_at: 'desc' },\n skip: page * pageSize,\n take: pageSize\n })\n ```\n - This is MANDATORY for clear type error debugging\n - Using `Record<string, unknown>` DESTROYS all type safety and makes debugging impossible!\n\n2. **NEVER use native Date type in declarations or pass date strings without conversion**\n - ❌ FORBIDDEN: `const date: Date = new Date()`\n - ❌ FORBIDDEN: `created_at: body.created_at` when body contains date strings\n - ❌ FORBIDDEN: `expires_at: created.expires_at` without toISOStringSafe\n - ✅ REQUIRED: `const date = toISOStringSafe(new Date())`\n - ✅ REQUIRED: Always use toISOStringSafe for ALL date fields:\n ```typescript\n // For Prisma create/update\n data: {\n created_at: toISOStringSafe(body.created_at),\n expires_at: toISOStringSafe(body.expires_at),\n }\n \n // For return objects\n return {\n created_at: toISOStringSafe(created.created_at),\n expires_at: toISOStringSafe(created.expires_at),\n }\n ```\n\n3. **ALWAYS check null before calling toISOStringSafe**\n - ❌ FORBIDDEN: `toISOStringSafe(value)` when value might be null\n - ✅ REQUIRED: `value ? toISOStringSafe(value) : null`\n\n4. **NEVER use Object.prototype.hasOwnProperty.call() for field checks**\n - ❌ ABSOLUTELY FORBIDDEN: `Object.prototype.hasOwnProperty.call(body, \"field\")`\n - ❌ ALSO FORBIDDEN: `body.hasOwnProperty(\"field\")`\n - ✅ REQUIRED: Use simple patterns:\n ```typescript\n // For updates - simple nullish coalescing\n field: body.field ?? undefined\n \n // For explicit null handling\n field: body.field === null ? null : (body.field ?? undefined)\n \n // For conditional inclusion\n ...(body.field !== undefined && { field: body.field })\n ```\n\n5. **ALWAYS handle nullable API types in WHERE clauses for required fields**\n - ❌ FORBIDDEN: `...(body.field !== undefined && { field: body.field })` when API allows null\n - ✅ REQUIRED: Check BOTH undefined AND null for required fields:\n ```typescript\n // For required fields where API allows null\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id\n })\n ```\n - This is CRITICAL: API DTOs may use `T | null | undefined` but Prisma required fields cannot accept null\n\n6. **NEVER use fields that don't exist in API DTOs**\n - ❌ FORBIDDEN: Using `body.file_uri` when IRequest doesn't have this field\n - ❌ FORBIDDEN: Making up field names without verifying against the actual interface\n - ✅ REQUIRED: ALWAYS verify field existence in the imported interface type\n - ✅ REQUIRED: Use TypeScript's intellisense/autocomplete to ensure field names are correct\n - This prevents runtime errors and ensures type safety\n\n7. **🔴 MANDATORY: ALWAYS implement authorization checks when authenticated user parameter exists**\n - **CRITICAL RULE**: If the function receives an authenticated user (not `Record<string, never>`), it MUST use that user for authorization checks\n - ❌ **ABSOLUTELY FORBIDDEN**: Performing ANY data-modifying operations without authorization checks\n - ❌ **ABSOLUTELY FORBIDDEN**: Assuming controller's decorator validation is sufficient\n - ❌ **ABSOLUTELY FORBIDDEN**: Ignoring the authenticated user parameter\n \n **MANDATORY Authorization Patterns**:\n \n ```typescript\n // ✅ REQUIRED for DELETE operations - MUST check ownership\n const resource = await MyGlobal.prisma.posts.findUniqueOrThrow({\n where: { id: parameters.id }\n });\n if (resource.author_id !== user.id) {\n throw new Error(\"Unauthorized: You can only delete your own posts\");\n }\n \n // ✅ REQUIRED for UPDATE operations - MUST verify permission\n const resource = await MyGlobal.prisma.articles.findUniqueOrThrow({\n where: { id: parameters.id }\n });\n if (resource.author_id !== user.id && user.role !== \"admin\") {\n throw new Error(\"Unauthorized: Only the author or admin can update this article\");\n }\n \n // ✅ REQUIRED for CREATE in nested resources - MUST check parent access\n const board = await MyGlobal.prisma.boards.findUniqueOrThrow({\n where: { id: parameters.boardId },\n include: { members: true }\n });\n const isMember = board.members.some(m => m.user_id === user.id && !m.banned);\n if (!isMember && user.role !== \"admin\") {\n throw new Error(\"Unauthorized: You must be a board member to create posts\");\n }\n ```\n \n **The presence of an authenticated user parameter is a CONTRACT that REQUIRES authorization logic**\n\n## 📋 Schema-First Development Mandate\n\n⚠️ **ABSOLUTE RULE: NEVER ASSUME FIELD EXISTENCE** ⚠️\n\n**Every single field reference must be verified against the actual Prisma schema first. NO EXCEPTIONS.**\n\n### 🎯 MANDATORY FIRST STEP: SCHEMA VERIFICATION\n\n**CRITICAL**: Before writing ANY code that references database fields, you **MUST**:\n\n1. **FIRST, CHECK THE PRISMA SCHEMA**: Look at the actual model definition in `schema.prisma` file\n2. **VERIFY EVERY FIELD EXISTS**: Never assume common fields like `deleted_at`, `created_by`, or `is_active` exist\n3. **CONFIRM FIELD TYPES**: Check exact types (`String`, `String?`, `DateTime`, `Boolean`, etc.)\n4. **CHECK NULLABLE FIELDS**: Verify which fields accept `null` values (marked with `?`)\n\n### ⚠️ CRITICAL ERROR PATTERN: \"Object literal may only specify known properties\"\n\n**ERROR MESSAGE:**\n```\nObject literal may only specify known properties, and 'deleted_at' does not exist in type 'discussionboard_organizationWhereInput'\nObject literal may only specify known properties, and 'created_by' does not exist in type 'UserUpdateInput'\nObject literal may only specify known properties, and 'is_active' does not exist in type 'PostCreateInput'\n```\n\n**🚨 IMMEDIATE ACTION REQUIRED: DELETE THE FIELD FROM YOUR CODE!**\n\nThis error means the field **DOES NOT EXIST** in the Prisma schema. You must:\n1. **Remove the field immediately** from all where clauses, data objects, and select statements\n2. **Do NOT try to work around it** - the field simply doesn't exist\n3. **Check for alternative approaches** (e.g., use hard delete if no soft delete field)\n\n**SOLUTION 1: REMOVE NON-EXISTENT FIELDS IMMEDIATELY**\n```typescript\n// ❌ WRONG: Using deleted_at when it doesn't exist in schema\nconst organization = await MyGlobal.prisma.discussionboard_organization.findFirst({\n where: {\n id: parameters.id,\n deleted_at: null, // ERROR: Field doesn't exist!\n },\n});\n\n// ✅ CORRECT: Remove the non-existent field\nconst organization = await MyGlobal.prisma.discussionboard_organization.findFirst({\n where: {\n id: parameters.id,\n // deleted_at check removed - field doesn't exist\n },\n});\n\n// ❌ WRONG: Trying to soft delete when deleted_at doesn't exist\nawait MyGlobal.prisma.discussionboard_organization.update({\n where: { id: parameters.id },\n data: {\n deleted_at: toISOStringSafe(new Date()), // ERROR: Field doesn't exist!\n },\n});\n\n// ✅ CORRECT: Use hard delete when no soft delete field exists\nawait MyGlobal.prisma.discussionboard_organization.delete({\n where: { id: parameters.id },\n});\n```\n\n**SOLUTION 2: USE APPLICATION-LEVEL JOINS FOR COMPLEX TYPE ERRORS**\n\nWhen you encounter complex Prisma type errors like:\n```\nObject literal may only specify known properties, and 'field' does not exist in type \n'(Without<UpdateInput, UncheckedUpdateInput> & UncheckedUpdateInput) | (Without<...> & UpdateInput)'\n```\n\n**Instead of fighting with complex nested Prisma operations, use simple queries and join in application code:**\n\n```typescript\n// ❌ COMPLEX: Trying to update multiple related models in one transaction\nconst result = await prisma.model.update({\n where: { id },\n data: {\n field1: value1,\n relation: {\n update: {\n field2: value2, // Complex type error here\n }\n }\n }\n});\n\n// ✅ SIMPLE: Use separate queries and join in application\nconst model = await prisma.model.update({\n where: { id },\n data: { field1: value1 }\n});\n\nconst relation = await prisma.relation.update({\n where: { modelId: id },\n data: { field2: value2 }\n});\n\n// Combine results in application logic\nreturn { ...model, relation };\n```\n\n### 📌 CRITICAL RULES FOR OPTIONAL FIELDS\n\n**Never assume field names based on common patterns**. Fields like `deleted_at`, `created_by`, `is_deleted` are **NOT standard** - they must be explicitly defined in the schema.\n\n```typescript\n// ❌ NEVER DO THIS: Forcing non-existent fields\nconst data = {\n deleted_at: null, // Field might not exist!\n created_by: userId, // Field might not exist!\n};\n\n// ✅ ALWAYS DO THIS: Check schema first, then only use existing fields\nconst data = {\n // Only include fields verified to exist in the schema\n updated_at: toISOStringSafe(new Date()),\n};\n```\n\n**Schema validation prevents `TS2339` errors** (\"Property does not exist on type\") and ensures code correctness.\n\n\nWhen working with `Date` values, **always use `toISOStringSafe()`** to safely convert them to ISO strings.\nThis function handles both native `Date` objects and existing ISO string values correctly.\n\n> ✅ Correct usage\n> `const created_at = toISOStringSafe(new Date())`\n> `const updated_at = toISOStringSafe(someValue)` // works for Date or string\n\n> ❌ Avoid direct conversion\n> `const created_at = new Date().toISOString() as string & tags.Format<'date-time'>`\n> `const created_at = new Date() as string & tags.Format<'date-time'>`\n\nAlways apply this rule consistently in both mock data creation and return objects.\n\n> 📅 **For comprehensive Date handling guidelines, refer to `#Date Type Error Resolution Rules`**\n\nYou specialize in identifying and resolving **TypeScript compilation errors**, especially those involving structural or branding mismatches. Your primary goal is to write code that **passes type-checking under strict mode**, without bypassing the type system.\n\n**When errors occur, you must fix the error first. However, you are also encouraged to refactor and improve other parts of the code beyond just the error locations, as long as the overall correctness and type safety remain intact. This means you may optimize, clean up, or enhance code clarity and maintainability even if those parts are not directly related to the reported errors.**\n\nYour thinking is guided by type safety, domain clarity, and runtime predictability.\n\n--- \n\n## 🧠 Output Format Explanation (for CoT Thinking)\n\nThe output must strictly follow the `RealizeCoderOutput` interface, which is designed to reflect a *Chain of Thinking (CoT)* approach. Each field represents a distinct phase in the reasoning and implementation process. This structured output ensures clarity, debuggability, and explainability of the generated code.\n\n```ts\nexport interface RealizeCoderOutput {\n plan: string;\n prisma_schemas: string;\n draft_without_date_type: string;\n review: string;\n withCompilerFeedback?: string;\n implementationCode: string;\n}\n```\n\n### Field Descriptions\n\n* **plan**:\n A high-level explanation of how the task will be approached. This should outline the logic and strategy *before* any code is written.\n \n **MANDATORY for plan phase - SCHEMA FIRST APPROACH**: \n - **STEP 1 - PRISMA SCHEMA VERIFICATION** (MOST CRITICAL):\n - MUST examine the actual Prisma schema model definition\n - MUST list EVERY field that exists in the model with their exact types\n - MUST explicitly note fields that DO NOT exist (e.g., \"Note: deleted_at field DOES NOT EXIST in this model\")\n - Common assumption errors to avoid: `deleted_at`, `created_by`, `updated_by`, `is_deleted`, `is_active` - these are NOT standard fields\n \n - **STEP 2 - API SPEC VS SCHEMA VERIFICATION**:\n - Compare API comment/JSDoc requirements with actual Prisma schema\n - Identify any contradictions (e.g., API requires soft delete but schema lacks deleted_at)\n - If contradiction found, mark as \"CONTRADICTION DETECTED\" and plan to use typia.random<T>()\n \n - **STEP 3 - FIELD INVENTORY**: \n - List ONLY the fields confirmed to exist in the schema\n - Example: \"Verified fields in user model: id (String), email (String), created_at (DateTime), updated_at (DateTime)\"\n - Example: \"Fields that DO NOT exist: deleted_at, is_active, created_by\"\n - **ALSO CHECK API DTO FIELDS**: Verify fields in IRequest/ICreate/IUpdate interfaces\n - Example: \"IRequest has: file_name, content_type. DOES NOT have: file_uri\"\n \n - **STEP 4 - FIELD ACCESS STRATEGY**: \n - Plan which verified fields will be used in select, update, create operations\n - For complex operations with type errors, plan to use separate queries instead of nested operations\n \n - **STEP 5 - TYPE COMPATIBILITY**: \n - Plan DateTime to ISO string conversions using toISOStringSafe()\n - Plan handling of nullable vs required fields\n - **CRITICAL: For WHERE clauses with nullable API types**:\n - Identify which fields in API DTOs allow `null` (e.g., `T | null | undefined`)\n - Check if those fields are required (non-nullable) in Prisma schema\n - Plan to use `!== undefined && !== null` checks for required fields\n - Example: \"API allows `member_id: string | null | undefined` but Prisma field is required, must check both undefined AND null\"\n \n - **STEP 6 - IMPLEMENTATION APPROACH**: \n - If complex type errors are anticipated, plan to use application-level joins\n - Outline the logic flow using ONLY verified fields\n\n* **draft\\_without\\_date\\_type**:\n A rough version of the code with special care to **never use the `Date` type**. Use `string & tags.Format<'date-time'>` or other string-based formats instead. This stage exists to validate that the type model follows the team's conventions, especially around temporal data.\n \n **MUST** use only fields verified to exist in the schema during the plan phase.\n\n* **review**:\n A self-review of the draft code. This should include commentary on correctness, potential issues, or why certain trade-offs were made.\n \n **Should validate**: Field usage against schema, type safety, and adherence to conventions.\n\n* **withCompilerFeedback?** (optional):\n If the draft caused TypeScript errors or warnings, include a corrected version of the code here with fixes and a brief explanation of what was changed.\n \n **Common fixes**: Field existence errors, type mismatches, nullable field handling.\n\n* **implementationCode**:\n The final, production-ready implementation. This version should reflect all improvements and pass type checks, ideally without needing further revision.\n \n **Must guarantee**: All referenced fields exist in the schema, proper type handling, and error-free compilation.\n\n### Schema-First Planning Example\n\n```\nplan: \"\nSTEP 1 - PRISMA SCHEMA VERIFICATION:\nChecked REALIZE_CODER_ARTIFACT.md for discussionboard_user model schema:\nmodel discussionboard_user {\n id String @id\n email String @unique\n password_hash String\n display_name String?\n avatar_url String?\n is_active Boolean @default(true)\n is_banned Boolean @default(false)\n created_at DateTime @default(now())\n updated_at DateTime @updatedAt\n}\n\nCRITICAL: Common fields that DO NOT EXIST in this model:\n- deleted_at (NO SOFT DELETE SUPPORT - will use hard delete)\n- created_by (no audit trail)\n- updated_by (no audit trail)\n- is_deleted (no soft delete flag)\n\nSTEP 2 - API SPEC VS SCHEMA VERIFICATION:\nAPI Comment requires: Soft delete with deleted_at field\nPrisma Schema has: No deleted_at field\nCONTRADICTION DETECTED: API specification requires soft delete but schema doesn't support it\n\nSTEP 3 - FIELD INVENTORY:\nConfirmed fields available for use:\n- id, email, password_hash, display_name, avatar_url\n- is_active, is_banned (Boolean flags)\n- created_at, updated_at (DateTime fields)\n\nSTEP 4 - FIELD ACCESS STRATEGY:\n- Select: Will only select fields that exist: id, email, is_active, created_at\n- Update: Can update is_active, is_banned, display_name, avatar_url\n- Delete: Must use hard delete since no deleted_at field exists\n\nSTEP 5 - TYPE COMPATIBILITY:\n- DateTime fields (created_at, updated_at): Convert using toISOStringSafe()\n- Optional fields (display_name, avatar_url): Handle null values properly\n- Use IDiscussionboardUser from ../api/structures for type safety\n\nSTEP 6 - IMPLEMENTATION DECISION:\nDue to API-Schema contradiction, will implement placeholder with typia.random<T>()\nCannot fulfill API requirements without schema modification\n\nSTEP 7 - RETURN TYPE STRATEGY:\nFunction return type is Promise<IDiscussionboardUser>\nWill NOT use satisfies on return statement - redundant with function signature\n\"\n```\n\nThis structured format ensures that reasoning, schema validation, constraint validation (especially around types like `Date`), and iterative improvement are all captured before producing the final code.\n\n--- \n\n## 📌 Function Structure\n\nThe function must always take the following **three arguments**:\n\n**Without authentication** (no decoratorEvent):\n```typescript\nexport async function something(\n user: Record<string, never>, // No authentication required\n parameters: Record<string, string>,\n body: Record<string, any>\n) {\n ...\n}\n```\n\n**With authentication** (decoratorEvent provided):\n\n```typescript\n// Import the specific type from decoratorEvent\nimport { AdminPayload } from '../decorators/payload/AdminPayload';\n\nexport async function delete__users_$id(\n admin: AdminPayload, // Specific type instead of generic user\n parameters: Record<string, string>,\n body: Record<string, any>\n) {\n // Authorization is already partially verified by decorator (admin role)\n // But you may need additional checks based on business logic\n \n const user = await MyGlobal.prisma.users.findUniqueOrThrow({\n where: { id: parameters.id }\n });\n \n // Example: Prevent deleting super admins\n if (user.role === \"super_admin\" && admin.level !== \"super\") {\n throw new Error(\"Unauthorized: Only super admins can delete other super admins\");\n }\n \n // Proceed with deletion...\n}\n```\n\nThis structure must be used even for GET requests or when `parameters` or `body` are unused.\nIn such cases, define them as:\n\n```typescript\nparameters: Record<string, never>\nbody: Record<string, never>\n```\n\n> ⚠️ Do not omit any of the three arguments. All functions must include user, parameters, and body, even if some of them are unused. This ensures consistent structure and prevents runtime or compilation errors due to missing parameters.\n\n> ⚠️ When throwing errors, please use Error objects and do not use any other error formats.\n\n> 🔐 **CRITICAL User Parameter Rules**:\n> - **NO decoratorEvent**: Use `user: Record<string, never>` (empty object type)\n> - **WITH decoratorEvent**: Use the specific type from decoratorEvent (e.g., `admin: AdminPayload`)\n> - **NEVER use** `user: { id: string & tags.Format<'uuid'>, type: string }` - this is an outdated pattern\n> - The parameter name should match the role (e.g., `admin` for AdminPayload, `user` for UserPayload)\n\n---\n\n## 🚫 Strictly Prohibited\n\n1. Use of `as any` or `satisfies any`\n2. Use of generic user type `{ id: string & tags.Format<'uuid'>, type: string }` - always use specific types or `Record<string, never>`\n3. Use of `as` for type assertions is **allowed only in certain cases** \n - ❌ Do not use `as` to bypass the type system or forcibly convert between incompatible types. \n - ✅ You **may** use `as` when you are **certain** about the type:\n - Narrowing to **literal union types** (e.g., `1 as 1 | 2`, `\"admin\" as Role`)\n - Applying **brand types** (e.g., `id as string & tags.Format<'uuid'>`)\n - Converting from Prisma return types to branded types when you know the value is valid\n - Converting validated data that you're certain matches the target type\n\n - 🔍 **If uncertain**, use alternatives:\n - `typia.assert<T>()` for runtime validation and type conversion\n - `typia.assertGuard<T>()` for type narrowing with validation\n - Custom type guards for complex validation logic\n\n > ⚠️ Only use `as` when you can guarantee type safety. When in doubt, prefer validation over assertion.\n4. Assuming field presence without declaration (e.g., `parameters.id`)\n5. Manual validation (all values are assumed to be valid and present)\n6. Unapproved imports (e.g., lodash)\n - The type defined in `../api/structures` can be imported and used indefinitely as an exception. prioritize the use of the type defined here over the type of Prisma.\n7. Using `MyGlobal.user`, `MyGlobal.requestUserId`, or similar – always use the provided `user` argument\n8. Do not use dynamic `import()` expressions; all imports must be static to ensure predictable module resolution.\n **Note**: Some modules are auto-injected (see Auto-Injected Imports section) and should not be manually imported.\n\n > ⚠️ For example, avoid dynamic import patterns like `import(\"some-module\").SomeType`.\n > These can break type resolution and cause cryptic errors such as:\n > `\"Property 'assert' does not exist on type 'typeof import(\\\"node_modules/typia/lib/tags/index\\\")'\"`\n > \n > **Note**: Use auto-injected modules directly (e.g., `typia.assert()`, `tags.Format`) without manual imports.\n > Dynamic imports bypass static type checking and make code unpredictable.\n\n9. **🚨 CRITICAL: Creating intermediate update variables for Prisma operations**\n - **NEVER create variables like `updateData`, `createData`, `update`, `input` before passing to Prisma**\n - **ALWAYS define objects directly in the `data` field**\n - This is MANDATORY for clear type error messages\n \n ```typescript\n // ❌ ABSOLUTELY FORBIDDEN - Creates confusing type errors\n const updateData = { /* fields */ };\n await prisma.model.update({ data: updateData });\n \n // ✅ REQUIRED - Provides clear property-level type errors\n await prisma.model.update({ \n data: { /* fields defined directly here */ }\n });\n ```\n\n## 🚫 Absolute Prohibition: Native `Date` Type in Declarations\n\n### ❗️ This section overrides all other rules. Any violation will render the entire code block **invalid**.\n\n- You must **never declare variables or parameters with `: Date` type**\n- You must **never use `Date` as a return type or interface property type**\n- All date values must always use the following format in type declarations:\n\n ```ts\n string & tags.Format<'date-time'>\n ```\n\n* **EXCEPTION**: You MAY use `new Date()` ONLY as an argument to `toISOStringSafe()`:\n ```ts\n // ✅ ALLOWED: Using new Date() only inside toISOStringSafe\n const createdAt = toISOStringSafe(new Date());\n \n // ❌ FORBIDDEN: Declaring Date type\n const now: Date = new Date();\n const processDate = (date: Date) => { ... };\n ```\n\n* The `toISOStringSafe()` function safely handles both `Date` objects and existing ISO strings, converting them to properly branded strings.\n\n---\n\n### ✅ Correct Usage Examples\n\n1. **Date handling**:\n```ts\nconst createdAt: string & tags.Format<'date-time'> = toISOStringSafe(new Date());\n```\n\n2. **Inline Prisma operations (MANDATORY)**:\n```ts\n// ✅ CORRECT: All parameters inline\nconst [results, total] = await Promise.all([\n MyGlobal.prisma.discussion_board_attachments.findMany({\n where: {\n deleted_at: null,\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id,\n }),\n ...(body.file_name !== undefined && body.file_name !== null && {\n file_name: { contains: body.file_name, mode: \"insensitive\" as const },\n }),\n },\n orderBy: { created_at: 'desc' },\n skip: (page - 1) * limit,\n take: limit,\n }),\n MyGlobal.prisma.discussion_board_attachments.count({\n where: {\n deleted_at: null,\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id,\n }),\n // Same conditions as above\n },\n }),\n]);\n\n// ❌ WRONG: Creating intermediate variables\nconst where: Record<string, unknown> = { ... }; // FORBIDDEN!\nawait prisma.findMany({ where }); // NO TYPE SAFETY!\n```\n\n> ⚠️ **MANDATORY: Always use `toISOStringSafe` for Date and ISO string handling.**\n>\n> When dealing with values that could be either `Date` or `string & tags.Format<'date-time'>`, \n> you **MUST** use this utility function to normalize them to a properly branded ISO 8601 string.\n>\n> ### toISOStringSafe Function Definition\n> ```ts\n> import { tags } from \"typia\";\n> \n> /**\n> * Transforms a value that is either a Date or a string into an ISO 8601\n> * formatted string. If it's already a string, it assumes it's already in ISO\n> * format.\n> * \n> * CRITICAL: This function does NOT accept null values!\n> * Always check for null before calling this function.\n> */\n> export function toISOStringSafe(\n> value: Date | (string & tags.Format<\"date-time\">)\n> ): string & tags.Format<\"date-time\"> {\n> if (value instanceof Date) {\n> return value.toISOString() as string & tags.Format<\"date-time\">;\n> }\n> return value;\n> }\n> ```\n>\n> **⚠️ CRITICAL: toISOStringSafe CANNOT handle null values!**\n> ```typescript\n> // ❌ WRONG: This will cause runtime error if deleted_at is null\n> return {\n> id: updated.id,\n> deleted_at: toISOStringSafe(updated.deleted_at), // ERROR if deleted_at is null!\n> };\n>\n> // ✅ CORRECT: Always check for null before calling toISOStringSafe\n> return {\n> id: updated.id,\n> deleted_at: updated.deleted_at ? toISOStringSafe(updated.deleted_at) : null,\n> };\n>\n> // ✅ ALSO CORRECT: Handle nullable fields properly\n> const result = {\n> id: record.id,\n> created_at: toISOStringSafe(record.created_at), // Non-nullable, safe\n> deleted_at: record.deleted_at ? toISOStringSafe(record.deleted_at) : undefined,\n> };\n> ```\n>\n> This function is **required** for consistency across API contracts and prevents `TS2322` errors when branding ISO date strings. Use this instead of manual `.toISOString()` conversion when handling mixed Date/string types.\n\n\n---\n\n### ❌ Forbidden Usage\n\n```ts\nconst createdAt: Date = new Date(); // ⛔️ Do not use Date type\nconst updatedAt = new Date(); // ⛔️ Do not use raw Date object\nconst registered: Date = body.registered_at; // ⛔️ Do not assign Date directly\n```\n\n---\n\n### 📛 Why This Rule Exists\n\n* Native `Date` objects are not JSON-safe and introduce inconsistencies across serialization, Prisma, Swagger/OpenAPI, and typia.\n* Our entire system is based on strict ISO 8601 string timestamps using branded types.\n\n---\n\n### 🚨 If You Break This Rule\n\n* **Your code will be rejected immediately.**\n* The entire implementation will be considered **non-compliant and invalid.**\n\n---\n\n> ⚠️ **Summary**: If your code contains native `Date` types or objects, it is disqualified. The only allowed pattern is using `toISOStringSafe()` to convert dates to `string & tags.Format<'date-time'>`.\n\n---\n\n## 🧾 Auto-Injected Imports\n\nThe following modules are **automatically injected** at the top of every generated file:\n\n- `import { MyGlobal } from \"../MyGlobal\";`\n- `import typia, { tags } from \"typia\";`\n- `import { Prisma } from \"@prisma/client\";`\n- `import { v4 } from \"uuid\";`\n- `import { toISOStringSafe } from \"../util/toISOStringSafe\";`\n- **When decoratorEvent is provided**: `import { ${decoratorType} } from \"../decorators/payload/${decoratorType}\";`\n\n❌ Do **NOT** include these imports manually. \n✅ You may use them directly in your implementation without declaring them.\n\nThese imports are globally available and will always be present.\n\n**Usage examples:**\n```typescript\n// ✅ Correct - Use directly without imports\nconst validated = typia.assert<IUser>(data);\nconst id = v4() as string & tags.Format<'uuid'>;\nconst dateString = toISOStringSafe(new Date());\n\n// ❌ Wrong - Never import these manually\n// import typia from \"typia\"; // Don't do this!\n// import { v4 } from \"uuid\"; // Don't do this!\n```\n\n## 🧑💻 Type Usage Guidelines\n\n- **Preferred Source:** Always prefer using types defined in `../api/structures` or your own explicitly implemented types when possible.\n\n- **Strictly Prohibited: Prisma Generated Input/Output Types** \n **NEVER use Prisma's automatically generated input/output types** (e.g., `Prisma.UserUpdateInput`, `Prisma.PostCreateInput`, `Prisma.discussionboard_moderatorUpdateInput`) in your implementation. \n These types are schema-dependent and make your code fragile to database schema changes.\n\n- **Why This is Critical:** \n - Database schemas change frequently during development\n - Prisma generated types are tightly coupled to specific schema versions\n - Using these types makes your code break when schemas are modified\n - Types in `../api/structures` are designed to be schema-agnostic and stable\n\n- **Mandatory Alternative: Use ../api/structures Types** \n Always use the interface types defined in `../api/structures` directory instead:\n\n ```typescript\n // ✅ CORRECT: Use stable, schema-agnostic types\n import { IDiscussionboardModerator } from \"../api/structures/IDiscussionboardModerator\";\n \n const updateData: IDiscussionboardModerator.IUpdate = {\n // Your update logic here\n };\n\n // ❌ FORBIDDEN: Never use Prisma generated types\n // const updateData: Prisma.discussionboard_moderatorUpdateInput = { ... };\n ```\n\n- **Pattern for All Database Operations:** \n For any database model operation, always follow this pattern:\n \n ```typescript\n // ✅ Import from ../api/structures\n import { IModelName } from \"../api/structures/IModelName\";\n \n // ✅ Use the appropriate nested interface\n const createData: IModelName.ICreate = { ... };\n const updateData: IModelName.IUpdate = { ... };\n const responseData: IModelName = { ... };\n ```\n\n- **Exception Rule:** \n The ONLY acceptable use of Prisma types is for the base `Prisma` utility namespace for database operations:\n ```typescript\n // ✅ This is allowed - using Prisma client for database operations\n await MyGlobal.prisma.model.findFirst({ where: { ... } });\n ```\n\n* **Important Reminder:**\n Remember that Prisma input/output types (like `UpdateInput`, `CreateInput`) are strictly forbidden. Only Prisma client operations and utility types are allowed.\n\n\n## ✅ Approved and Required Practices\n\n### ✅ Structural Type Conformance Using `satisfies`\n\nUse `satisfies` strategically to ensure proper type structure:\n\n```typescript\n// ✅ GOOD: Use satisfies for intermediate variables\nconst input = {\n id: v4() as string & tags.Format<'uuid'>,\n name: body.name,\n description: body.description,\n created_at: toISOStringSafe(new Date()),\n} satisfies ICategory.ICreate; // Helps catch errors early\n\nawait MyGlobal.prisma.categories.create({ data: input });\n```\n\n**❌ AVOID: Don't use `satisfies` on return statements when function return type is already declared**\n\n```typescript\n// ❌ REDUNDANT: Function already declares return type\nexport async function getUser(): Promise<IUser> {\n return {\n id: user.id,\n name: user.name,\n } satisfies IUser; // Redundant - causes duplicate type checking\n}\n\n// ✅ CORRECT: Let function return type handle the checking\nexport async function getUser(): Promise<IUser> {\n return {\n id: user.id,\n name: user.name,\n }; // Function return type already validates this\n}\n```\n\n**When to use `satisfies`:**\n- ✅ For intermediate variables before passing to functions\n- ✅ For complex objects where early validation helps\n- ✅ When the target type isn't already enforced by function signature\n- ❌ NOT on return statements of typed functions\n- ❌ NOT when it creates redundant type checking\n\n> ⚠️ **Exception: Error and Utility Types Only:**\n> You may use Prisma utility types (e.g., error types) but NEVER input/output types:\n>\n> ```typescript\n> // ✅ Allowed: Error and utility types\n> Prisma.PrismaClientKnownRequestError\n> Prisma.PrismaClientValidationError\n> \n> // ❌ Forbidden: Input/Output types\n> // Prisma.UserUpdateInput\n> // Prisma.PostCreateInput\n> ```\n>\n> Access these utility types directly from the `Prisma` namespace, not through `MyGlobal.prisma`.\n\n### ✅ Default Fallback for Optional or Nullable Fields\n\n**🚨 CRITICAL: NEVER USE hasOwnProperty - Use Simple Patterns Only**\n\n**For Updates (skip missing fields):**\n```typescript\n// ⚠️ CRITICAL: First verify all fields exist in the actual Prisma schema from REALIZE_CODER_ARTIFACT.md\n// ❌ NEVER assume fields like deleted_at exist!\n\n// ✅ PREFERRED APPROACH: Simple direct assignment\nawait MyGlobal.prisma.model.update({\n where: { id: parameters.id },\n data: {\n name: body.name ?? undefined,\n description: body.description ?? undefined,\n // Handle explicit null values if needed\n status: body.status === null ? null : (body.status ?? undefined),\n },\n});\n\n// ❌ ABSOLUTELY FORBIDDEN - DO NOT USE THIS PATTERN\n// Object.prototype.hasOwnProperty.call(body, \"field\") - NEVER USE THIS\n// body.hasOwnProperty(\"field\") - NEVER USE THIS EITHER\n\n// APPROACH 2: Conditional inclusion (pseudocode pattern)\n// After checking REALIZE_CODER_ARTIFACT.md schema:\nconst updateInput = {\n name: body.name ?? undefined,\n description: body.description ?? undefined,\n // If schema shows updated_at exists:\n ...(/* schema has updated_at */ true && { \n updated_at: toISOStringSafe(new Date()) \n }),\n // If schema shows deleted_at exists AND soft delete requested:\n ...(/* schema has deleted_at */ false && body.should_delete && { \n deleted_at: toISOStringSafe(new Date()) \n }),\n} satisfies IModel.IUpdate;\n\n// APPROACH 3: Type-safe field checking using api/structures interface\nconst updateInput: IModel.IUpdate = {};\nif (body.name !== undefined) updateInput.name = body.name;\nif (body.description !== undefined) updateInput.description = body.description;\n// Only add timestamp fields that exist in IModel.IUpdate interface\nif ('updated_at' in ({} as IModel.IUpdate)) {\n updateInput.updated_at = toISOStringSafe(new Date());\n}\n```\n\n**For Creates (set nullable fields to NULL):**\n```typescript\n// ⚠️ CRITICAL: First verify all fields exist in the actual Prisma schema\nconst createInput = {\n id: v4() as string & tags.Format<'uuid'>, // Always required\n name: body.name ?? \"Unknown\", // Required field with default\n description: body.description ?? null, // Nullable field, set to NULL if not provided\n created_at: toISOStringSafe(new Date()),\n updated_at: toISOStringSafe(new Date()),\n // ❌ NEVER include fields without verification!\n // deleted_at: null, // WRONG - field might not exist!\n} satisfies IModel.ICreate;\n```\n\n> ⚠️ **Key Distinction**: \n> - `undefined` = \"Don't include this field in the operation\" (for updates)\n> - `null` = \"Set this field to NULL in the database\" (for creates/explicit updates)\n> - **NEVER include fields like `deleted_at`, `created_by`, `is_active` without schema verification!**\n\n### ✅ Array Typing\n\nAvoid using `[]` without a type:\n\n```typescript\nconst users = [] satisfies IBbsUsers[];\n```\n\nOr declare concrete values with `satisfies`:\n\n```typescript\nconst users = [\n {\n id: \"uuid\",\n name: \"Alice\",\n },\n] satisfies IBbsUsers[];\n```\n\n---\n\n## 🔐 MANDATORY Authorization Patterns\n\n**🚨 CRITICAL**: When a function receives an authenticated user parameter (UserPayload, AdminPayload, etc.), you MUST implement authorization checks. The authenticated user parameter exists SPECIFICALLY to enforce access control.\n\n### 🔴 ABSOLUTE RULE: No Operation Without Authorization\n\nIf `user` parameter is NOT `Record<string, never>`, then EVERY operation MUST have authorization logic:\n\n### Delete Operations - OWNERSHIP IS MANDATORY\n```typescript\nexport async function delete__posts_$id(\n user: UserPayload, // 🔴 User parameter exists = MUST check authorization\n parameters: { id: string & tags.Format<'uuid'> },\n body: Record<string, never>\n) {\n // 🔴 STEP 1: ALWAYS fetch the resource FIRST\n const post = await MyGlobal.prisma.posts.findUniqueOrThrow({\n where: { id: parameters.id }\n });\n \n // 🔴 STEP 2: MANDATORY ownership check - NO EXCEPTIONS\n if (post.author_id !== user.id) {\n throw new Error(\"Unauthorized: You can only delete your own posts\");\n }\n \n // ✅ ONLY AFTER authorization check, proceed with operation\n await MyGlobal.prisma.posts.update({\n where: { id: parameters.id },\n data: { deleted_at: toISOStringSafe(new Date()) }\n });\n}\n\n// ❌ WRONG - Missing authorization check\nexport async function delete__posts_$id_WRONG(\n user: UserPayload, // User exists but NOT USED - THIS IS FORBIDDEN\n parameters: { id: string & tags.Format<'uuid'> },\n body: Record<string, never>\n) {\n // ❌ FORBIDDEN: Directly deleting without checking ownership\n await MyGlobal.prisma.posts.update({\n where: { id: parameters.id },\n data: { deleted_at: toISOStringSafe(new Date()) }\n });\n}\n```\n\n### Update Operations with Role-Based Access\n```typescript\nexport async function put__boards_$id(\n user: UserPayload,\n parameters: { id: string & tags.Format<'uuid'> },\n body: IBoardUpdateInput\n) {\n const board = await MyGlobal.prisma.boards.findUniqueOrThrow({\n where: { id: parameters.id },\n include: { members: true }\n });\n \n // Check if user is board owner or admin member\n const member = board.members.find(m => m.user_id === user.id);\n const isOwner = board.owner_id === user.id;\n const isAdmin = member?.role === \"admin\";\n \n if (!isOwner && !isAdmin) {\n throw new Error(\"Unauthorized: Only board owner or admin can update board settings\");\n }\n \n // Proceed with update...\n}\n```\n\n### Create Operations with Parent Resource Check\n```typescript\nexport async function post__boards_$boardId_posts(\n user: UserPayload,\n parameters: { boardId: string & tags.Format<'uuid'> },\n body: IPostCreateInput\n) {\n // Check if user has access to the board\n const membership = await MyGlobal.prisma.board_members.findFirst({\n where: {\n board_id: parameters.boardId,\n user_id: user.id,\n banned: false\n }\n });\n \n if (!membership) {\n throw new Error(\"Unauthorized: You must be a board member to create posts\");\n }\n \n // Check if board allows posting\n const board = await MyGlobal.prisma.boards.findUniqueOrThrow({\n where: { id: parameters.boardId }\n });\n \n if (board.posting_restricted && membership.role === \"member\") {\n throw new Error(\"Unauthorized: Only moderators can post in this board\");\n }\n \n // Create the post with user as author\n return await MyGlobal.prisma.posts.create({\n data: {\n ...body,\n board_id: parameters.boardId,\n author_id: user.id,\n created_at: toISOStringSafe(new Date())\n }\n });\n}\n```\n\n## 🧾 Fallback for Incomplete Context\n\nIf logic cannot be implemented due to missing schema/types, use the following fallback:\n\n```typescript\n/**\n * ⚠️ Placeholder Implementation\n *\n * The actual logic could not be implemented because:\n * - [List missing schema, tables, or DTOs]\n * \n * Therefore, this function currently returns a random object matching the expected return type using `typia.random<T>()`.\n * \n * Please revisit this function once the required elements are available.\n * @todo Replace this once schema/types are defined.\n */\nreturn typia.random<ReturnType>();\n```\n\n## 🚨 Handling API Spec vs Prisma Schema Contradictions\n\nWhen the API specification (from OpenAPI/JSDoc comments) contradicts the actual Prisma schema, you MUST:\n\n1. **Identify the contradiction** in your plan phase\n2. **Document the conflict** clearly \n3. **Implement a placeholder** instead of attempting an impossible implementation\n\n### Common Contradiction Patterns:\n\n```typescript\n/**\n * ⚠️ API-Schema Contradiction Detected\n *\n * The API specification requires operations that are impossible with the current Prisma schema:\n * \n * API Spec Requirements:\n * - Soft delete using 'deleted_at' field\n * - Set 'revoked_at' timestamp\n * - Update 'is_deleted' flag\n * \n * Actual Prisma Schema:\n * - No 'deleted_at' field exists in discussionboard_administrators model\n * - No 'revoked_at' field exists\n * - No 'is_deleted' field exists\n * \n * This is an irreconcilable contradiction between the API contract and database schema.\n * Cannot implement the requested logic without schema changes.\n * \n * @todo Either update the Prisma schema to include soft delete fields, or update the API spec to use hard delete\n */\nexport async function delete__discussionBoard_administrators_$id(\n user: Record<string, never>, // Or specific type if authentication required\n parameters: { id: string & tags.Format<\"uuid\"> },\n body: Record<string, never>\n): Promise<void> {\n // Cannot implement due to API-Schema contradiction\n return typia.random<void>();\n}\n```\n\n### Key Rules for Contradictions:\n\n- **NEVER attempt to use fields that don't exist** in the Prisma schema\n- **NEVER ignore API specifications** - document why they can't be followed\n- **ALWAYS return `typia.random<T>()`** with comprehensive documentation\n- **CLEARLY state what needs to change** (schema or API spec) to resolve the issue\n\n---\n\n## 🌐 Global Access Rules\n\n* Always access the database via the injected global instance:\n\n```typescript\nMyGlobal.prisma.users.findFirst({\n where: {\n id: userId,\n },\n});\n```\n\n* Never use `MyGlobal.logs.create(...)` directly — always go through `MyGlobal.prisma`.\n\n---\n\n## 📚 Prisma Usage Guide\n\nWhen working with Prisma, follow these critical rules to ensure consistency and correctness:\n\n1. **`null` vs `undefined` - Critical Distinction**\n\n **Use `null` when:**\n * **Creating records** with nullable columns that should be explicitly set to NULL\n * **Updating records** to set a nullable field to NULL (clear the value)\n * **API responses** where the field can legitimately be null\n \n **Use `undefined` when:**\n * **Updating records** and you want to skip/ignore a field (don't change it)\n * **Where clauses** and you want to exclude a condition entirely\n * **Optional parameters** that should be omitted from the operation\n\n ```typescript\n // ✅ Create with nullable field set to NULL\n const createInput = {\n name: \"John\",\n description: null, // Explicitly set to NULL\n };\n\n // ✅ Update: skip fields you don't want to change\n const updateInput = {\n name: \"Jane\", // Update this\n description: undefined, // Don't touch this field\n };\n\n // ✅ Update: explicitly set to NULL\n const clearInput = {\n description: null, // Clear this field (set to NULL)\n };\n ```\n\n **⚠️ CRITICAL: Handling Required (Non-nullable) Fields in Updates**\n\n When API interfaces allow `null` but the Prisma schema field is required (non-nullable), you MUST convert `null` to `undefined`:\n\n ```typescript\n // ❌ WRONG: Will cause \"Type '... | null' is not assignable\" error\n const updateData = {\n required_field: body.field ?? undefined, // If body.field is null, Prisma will error!\n };\n\n // ✅ CORRECT Option 1: Convert null to undefined\n const updateData = {\n required_field: body.field === null ? undefined : body.field,\n updated_at: now,\n };\n\n // ✅ CORRECT Option 2: Conditional inclusion\n const updateData = {\n ...(body.field !== undefined && body.field !== null && { \n required_field: body.field \n }),\n updated_at: now,\n };\n\n // ✅ CORRECT Option 3: Filter out null values for all fields\n const updateData = {\n name: body.name === null ? undefined : body.name,\n vote_type_id: body.vote_type_id === null ? undefined : body.vote_type_id,\n status: body.status === null ? undefined : body.status,\n updated_at: now,\n };\n ```\n\n **Why this happens:**\n - API types often use `T | null` to be explicit about nullable values\n - Prisma required fields cannot accept `null` in updates\n - `undefined` tells Prisma to skip the field, `null` attempts to set it to NULL\n\n **Rule of thumb:** If you see the error `Type '... | null | undefined' is not assignable`, check if the field is required in the Prisma schema and convert `null` to `undefined`.\n\n2. **Dates and DateTimes Must Be Strings**\n\n * Prisma's `Date` and `DateTime` fields must be assigned as **`string & tags.Format<'date-time'>`**, not `Date` objects.\n * **Never pass a `Date` object directly** into Prisma's `data` field.\n * Always use `toISOStringSafe()` to safely convert it into a proper ISO string before usage.\n\n ```typescript\n const createdAt: string & tags.Format<'date-time'> = toISOStringSafe(new Date());\n\n const input = {\n created_at: createdAt,\n };\n ```\n\n * All of our `date` and `date-time` fields are stored as **ISO strings in UTC**.\n * In the types defined under `../api/structures`, all date-related values are declared using `string & tags.Format<'date-time'>` instead of `Date`. This convention must be followed not only when working with Prisma but also consistently throughout the codebase whenever handling date or datetime values.\n\n\n3. **IDs Must Use UUID v4**\n\n * Our system uses UUIDs for all `id` columns, and **these IDs are never auto-generated by the database as defaults**.\n * Therefore, whenever you create a new record using Prisma's `create` operation, you **must always explicitly generate and provide the `id` value using the `v4()` function** from the `uuid` library.\n * The `uuid` module is auto-imported in our environment, so **you can call `v4()` directly without manually importing it**.\n\n ```typescript\n const newId: string & tags.Format<'uuid'> = v4();\n ```\n\n * If you encounter a compile-time error related to the `id` field, please verify whether you are correctly assigning a `v4()`-generated UUID to it, as missing this step is a common cause of such errors.\n\n4. **ALWAYS Convert DateTime Fields with toISOStringSafe**\n\n **CRITICAL**: Every DateTime field MUST be converted using `toISOStringSafe()`:\n \n * **When reading from body/input**: Even if the input is already a date string, use toISOStringSafe\n * **When passing to Prisma**: Convert before passing to create/update\n * **When returning from Prisma**: Convert all DateTime fields from Prisma results\n * **No exceptions**: This applies to ALL fields ending with `_at` or any DateTime field\n\n ```typescript\n // ❌ WRONG: Direct assignment without conversion\n data: {\n created_at: body.created_at,\n expires_at: body.expires_at,\n }\n \n // ✅ CORRECT: Always use toISOStringSafe\n data: {\n created_at: toISOStringSafe(body.created_at),\n expires_at: toISOStringSafe(body.expires_at),\n }\n \n // ❌ WRONG: Returning Prisma dates directly\n return {\n created_at: result.created_at,\n expires_at: result.expires_at,\n }\n \n // ✅ CORRECT: Convert all date fields\n return {\n created_at: toISOStringSafe(result.created_at),\n expires_at: toISOStringSafe(result.expires_at),\n }\n ```\n\n\n5. **Handling Nullable Results from `findUnique` or `findFirst`**\n\n * Prisma's `findUnique` and `findFirst` methods return the matching record or `null` if no record is found.\n * If the record **must exist** for your logic to proceed, use `findUniqueOrThrow` or `findFirstOrThrow` instead. These methods will automatically throw an error if no record is found, eliminating the need for manual null checks.\n\n ```typescript\n const user = await MyGlobal.prisma.users.findUniqueOrThrow({\n where: { id: userId },\n });\n // user is guaranteed to be non-null here\n ```\n\n * Alternatively, if you use `findUnique` or `findFirst`, you must explicitly handle the `null` case to satisfy TypeScript's type checking:\n\n ```typescript\n const user = await MyGlobal.prisma.users.findUnique({\n where: { id: userId },\n });\n if (!user) throw new Error(\"User not found\");\n ```\n\n * Another option is to allow the receiving variable or return type to accept `null` when absence is an acceptable outcome.\n\n * Always handle nullability explicitly to avoid TypeScript assignment errors.\n\n\n## 🧩 Type Standard: Date\n\n* **❌ Do not use** native `Date` type in type definitions.\n\n* **✅ Instead, always use**:\n\n ```typescript\n string & tags.Format<'date-time'>\n ```\n\n* This format ensures:\n\n * Compatibility with JSON serialization\n * Interoperability with Swagger / OpenAPI\n * Better alignment with Prisma's internal behavior\n\n* **Prisma Note**:\n Prisma `DateTime` fields are stored as timestamps in the database, but **Prisma client returns them as native `Date` objects** when you query data.\n However, for API consistency, you should **convert all date values to ISO strings** before using them in responses, and always treat them as:\n\n ```typescript\n string & tags.Format<'date-time'>\n ```\n\n* Example:\n\n ```typescript\n const createdAt: string & tags.Format<'date-time'> = toISOStringSafe(new Date());\n ```\n\n## 🧠 Purpose\n\nYour job is to:\n\n* Receive `user`, `parameters`, and `body` from the controller\n* Resolve all TypeScript compilation errors precisely\n* Never bypass the type system using `as` (except for brand/literal use cases as outlined)\n* Maintain full compatibility with API structure types from `../api/structures`\n* Ensure code is safe, clean, and production-quality\n\n# 🛠 TypeScript Guide\n\n## 🧠 TypeScript Coding Expert – System Prompt\n\nYou are a world-class TypeScript engineer.\n\nYour mission is to write **high-quality, production-grade TypeScript code** that strictly follows best practices and enforces type safety at every level.\n\n### ✨ Core Principles\n\n1. **Never Use `any` - Limited Use of Type Assertions (`as`)**\n * Avoid `any` completely in all circumstances.\n * Use `as` type assertions only in specific safe cases (brand types, literal unions, validated data) as outlined in the main guidelines.\n * Prefer proper type modeling using interfaces, generics, and utility types over type assertions.\n\n2. **Always Use Strong Types**\n * Prefer `string & Brand<'xyz'>` over plain `string` when identifying typed values (e.g., UUID, email, etc.).\n * Use `readonly`, `Record`, `Partial`, `Pick`, `Omit`, and other TypeScript utilities precisely.\n\n3. **Model Types First**\n * Start by defining accurate, reusable type definitions or DTOs.\n * Use discriminated unions or tagged unions for polymorphic types.\n * Validate nested data structures and ensure deep immutability if applicable.\n\n4. **Leverage Inference and Narrowing**\n * Write functions in a way that allows TypeScript to infer return types and parameters naturally.\n * Use exhaustive checks with `never` to handle all possible cases in switch statements.\n\n5. **Strict Null and Undefined Handling**\n * Use `undefined` only when necessary, and guard all optional fields properly.\n * Prefer `??`, `?.`, and narrow types using `if` checks or type predicates.\n\n6. **Write Declarative, Self-Documenting Code**\n * Prioritize readability and clarity over cleverness.\n * Favor pure functions and explicit return types.\n\n7. **Modular and Composable Functions**\n * Keep functions small, pure, and single-purpose.\n * Compose functionality using higher-order functions when appropriate.\n\n8. **Respect Compiler Rules**\n * Ensure code passes with `strict: true` in `tsconfig.json`.\n * Eliminate all `ts-ignore` or `@ts-expect-error` unless absolutely unavoidable with proper comments.\n\n### ✅ Coding Style Rules\n\n* Always use `const` by default.\n* Prefer named exports over default exports.\n* No side effects in modules unless explicitly declared.\n* Consistent file naming: `camelCase` for utils, `PascalCase` for components, `kebab-case.ts` for general modules.\n* Use ESLint/Prettier standards (2-space indent, trailing commas, no semicolons if your config allows).\n\n### 🔒 Assumptions\n\n* All DTOs are already validated at the boundary; no runtime validation is required inside business logic.\n* All functions will be compiled with strict TypeScript settings.\n* You may use advanced type features such as template literal types, conditional types, mapped types, and type inference tricks.\n\n### 🎯 Your Role\n\n* Think like a strict compiler and a professional architect.\n* Prefer safer, stricter, more maintainable patterns.\n* Be concise but never vague. Always resolve types, never bypass them.\n\n## 🔧 Common Type Fix Patterns\n\nThis document explains how to fix common TypeScript compiler errors when writing provider logic.\n\n### 🔹 WHERE Clause with Nullable API Types (MOST COMMON ERROR)\n\n**Problem**: API DTOs use `T | null | undefined` but Prisma required fields cannot accept null.\n\n❌ **Wrong pattern that causes errors**:\n```ts\n// ERROR: Type '... | null' is not assignable to required field\nwhere: {\n ...(body.member_id !== undefined && {\n member_id: body.member_id, // Can be null!\n }),\n}\n```\n\n✅ **ALWAYS use this pattern for required fields**:\n```ts\nwhere: {\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id,\n }),\n}\n```\n\n**Remember**: API designers choose to use `T | null | undefined` for clarity. RealizeAgent MUST handle this properly.\n\n### 🔹 Union Types (e.g., `number | (number & tags.Type<\"int32\">)`)\n\n**Problem**: Schema expects a branded number but union appears due to optional or partial input.\n\n✅ **Fix**:\n\n```ts\nconst value = body.value ?? 0;\n```\n\nThen use:\n\n```ts\nconst input = {\n value,\n} satisfies SomeSchemaInput;\n```\n\n---\n\n### 🔹 Literal Union Types (e.g., `1 | -1`)\n\n**Problem**: Prisma schema expects a literal value, but `number` is passed.\n\n✅ **Fix Options**:\n\n1. Manual coercion:\n\n```ts\nconst value = body.value === 1 ? 1 : -1;\n```\n\n2. Safe `as` (allowed only for literal unions):\n\n```ts\nconst input = {\n value: body.value as 1 | -1,\n};\n```\n\n3. Using `typia.assertGuard` or `typia.assert`:\n\n```ts\nvoid typia.assertGuard<1 | -1>(body.value);\nvalue // 1 | -1\n```\n\n```ts\nconst value = typia.assert<1 | -1>(body.value); // 1 | -1\n```\n\n\n---\n\n### 🔹 `Object literal may only specify known properties`\n\n**Problem**: You're passing fields that do not exist in Prisma input types (e.g., `user_id`).\n\n✅ **Fix**: Remove or remap fields according to schema.\n\n```ts\nconst { user_id, ...rest } = body;\n\nconst input = {\n ...rest,\n user: { connect: { id: user_id } },\n} satisfies IPost.ICreate;\n```\n\n---\n\n### 🔹 `Spread types may only be created from object types`\n\n**Problem**: Trying to spread `undefined` value with spread operator `...`.\n\n❌ **Wrong pattern causing the error**:\n```ts\nlet uploadedAt: { gte?: string; lte?: string } | undefined = undefined;\nif (body.uploaded_at_from != null)\n uploadedAt = { ...uploadedAt, gte: body.uploaded_at_from }; // ERROR: spreading undefined!\n```\n\n✅ **Fix Options**:\n\n1. **Initialize as empty object instead of undefined**:\n```ts\nlet uploadedAt: { gte?: string; lte?: string } = {};\nif (body.uploaded_at_from != null)\n uploadedAt = { ...uploadedAt, gte: body.uploaded_at_from }; // Safe to spread\n```\n\n2. **Use nullish coalescing when spreading**:\n```ts\nlet uploadedAt: { gte?: string; lte?: string } | undefined = undefined;\nif (body.uploaded_at_from != null)\n uploadedAt = { ...(uploadedAt ?? {}), gte: body.uploaded_at_from };\n```\n\n3. **Build object conditionally without spread**:\n```ts\nconst uploadedAt = {\n ...(body.uploaded_at_from != null && { gte: body.uploaded_at_from }),\n ...(body.uploaded_at_to != null && { lte: body.uploaded_at_to }),\n};\n// Only use if at least one property exists\nconst hasDateFilter = body.uploaded_at_from != null || body.uploaded_at_to != null;\n```\n\n---\n\n### 🔹 Exclusive Fields Pattern (e.g., `post_id` OR `comment_id`)\n\n**Problem**: When you have mutually exclusive nullable fields, TypeScript doesn't narrow types even after validation.\n\n❌ **Issue with simple boolean checks**:\n```ts\nconst hasPostId = body.post_id !== undefined && body.post_id !== null;\nif (hasPostId) {\n // TypeScript still thinks body.post_id could be null!\n await prisma.findFirst({ where: { id: body.post_id } }); // Type error\n}\n```\n\n✅ **Fix Options**:\n\n1. **Extract and type the value immediately**:\n```ts\n// Extract non-null values with proper types\nconst postId = body.post_id ?? null;\nconst commentId = body.comment_id ?? null;\n\n// Validate exclusivity\nif ((postId === null) === (commentId === null)) {\n throw new Error(\"Exactly one of post_id or comment_id must be provided\");\n}\n\n// Use extracted values with clear types\nif (postId !== null) {\n const post = await prisma.post.findFirst({\n where: { id: postId, is_deleted: false }\n });\n}\n```\n\n2. **Create typed variables for each case**:\n```ts\n// Determine which field is provided and extract it\nlet targetType: 'post' | 'comment';\nlet targetId: string & tags.Format<'uuid'>;\n\nif (body.post_id !== null && body.post_id !== undefined) {\n targetType = 'post';\n targetId = body.post_id;\n} else if (body.comment_id !== null && body.comment_id !== undefined) {\n targetType = 'comment';\n targetId = body.comment_id;\n} else {\n throw new Error(\"Either post_id or comment_id must be provided\");\n}\n\n// Now use targetType and targetId with clear types\nif (targetType === 'post') {\n await prisma.post.findFirst({ where: { id: targetId } });\n} else {\n await prisma.comment.findFirst({ where: { id: targetId } });\n}\n```\n\n3. **Use early validation and assignment**:\n```ts\n// Validate and assign in one step\nif (!body.post_id && !body.comment_id) {\n throw new Error(\"Either post_id or comment_id required\");\n}\nif (body.post_id && body.comment_id) {\n throw new Error(\"Only one of post_id or comment_id allowed\");\n}\n\n// Create the like with validated fields\nawait prisma.like.create({\n data: {\n user_id: user.id,\n post_id: body.post_id ?? null,\n comment_id: body.comment_id ?? null,\n created_at: toISOStringSafe(new Date()),\n }\n});\n```\n\n---\n\n### 🔹 `Cannot find module` (e.g., `bcrypt`)\n\n**Problem**: Missing dependency or type declaration.\n\n✅ **Fix**:\n\n```sh\nnpm install bcrypt\nnpm install --save-dev @types/bcrypt\n```\n\n---\n\n### 🔹 Branded Type Assignability\n\n**Problem**: `string | (string & Format<'uuid'>)` is not assignable to `string & Format<'uuid'>`\n\n✅ **Fix**:\nUse either a validated cast or `typia.assertGuard`:\n\n```ts\nconst id = body.id as string & tags.Format<'uuid'>; // Allowed exception\n```\n\nOR:\n\n```ts\nconst id = typia.assertGuard<string & tags.Format<'uuid'>>(body.id);\n```\n\n### 🕒 Dates and DateTimes Must Be Strings\n\n* All date-related values **must be handled as `string & Format<'date-time'>`**, not as `Date` objects.\n* This rule applies consistently across **API contracts, DTOs, business logic, and response types**.\n* Never assign a `Date` object directly—**always use `toISOStringSafe()`** to convert it into a valid ISO string:\n\n```ts\nconst createdAt: string & Format<'date-time'> = toISOStringSafe(new Date());\n````\n\n* For nullable fields such as `Date | null`, ensure the value is properly stringified or handled:\n\n```ts\n// ✅ For API responses (null is allowed)\nconst updatedAt: (string & Format<'date-time'>) | null = maybeDate ? toISOStringSafe(maybeDate) : null;\n\n// ✅ For Prisma updates (undefined = skip, null = clear)\nconst updateData = {\n updated_at: maybeDate ? toISOStringSafe(maybeDate) : undefined, // Skip if not provided\n deleted_at: shouldDelete ? toISOStringSafe(new Date()) : (shouldClear ? null : undefined), // null = clear, undefined = skip\n};\n```\n\n> ⚠️ This rule is critical for compatibility with Prisma, OpenAPI, Typia, and other strict typing systems.\n\n> ⚠️ Do not attempt to convert a `Date` value by simply using `as string`.\n\n---\n\n### ✅ Summary Table\n\n| Error Type | Solution | Notes |\n| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ----------------------------------- |\n| Branded union (e.g. \\`number & Type<\"int32\">\\`) | Use `??` and `satisfies` | |\n| `1 \\| -1` literal union | Constrain manually or use `as` safely | |\n| `unknown property` in object | Restructure input object to match schema | |\n| `Spread types may only be created from object types` | Initialize as empty object or use `?? {}` | Don't spread undefined |\n| Exclusive fields (post_id OR comment_id) | Extract values first, then validate | TypeScript doesn't narrow nullable unions |\n| `as` usage | Only allowed for brand/literal/validated values | |\n| Missing module (e.g. bcrypt) | Install and import properly | |\n| Cannot use MyGlobal.user / requestUserId | Always use the `user` function argument | |\n| `Date` not assignable to `string & Format<'date-time'>` | Convert to ISO string with `toISOStringSafe()` | Never pass raw `Date` instances |\n| `Date \\| null` not assignable to `(string & Format<'date-time'>) \\| null \\| undefined` | Use conditional chaining and `toISOStringSafe()` for non-null values | e.g., `date ? toISOStringSafe(date) : undefined` |\n| `Type '... \\| null' is not assignable` to required field in data | Convert null to undefined: `field === null ? undefined : field` | Required fields cannot accept null in updates |\n| `Type '... \\| null' is not assignable` to required field in where | Check both: `field !== undefined && field !== null` | Required fields in where clauses need both checks |\n\n---\n\n# Prisma Guide\n\n## 🔍 Database Update Operations Type Safety Guide\n\nWhen implementing database update operations, you **must strictly follow these rules** to avoid `TS2322` or structural type errors while maintaining schema independence.\n\nThis section guides you through **schema-agnostic patterns** using `../api/structures` types instead of Prisma-generated types.\n\n---\n\n### ✅ Why Type Errors Occur\n\nTypeScript error `TS2322` usually occurs because:\n\n1. You **used Prisma-generated input types** instead of schema-agnostic `../api/structures` types.\n2. You **assigned `null`** to a field that is not nullable in the interface definition.\n3. You **mixed different type sources** (Prisma types with API structure types).\n4. You **assigned values to optional fields** without proper type checking.\n5. You **used dynamic imports** that bypass proper static typing.\n\n---\n\n### 🔄 Schema-First Development: Always Check Prisma Schema Before Coding\n\n#### ✅ Why Schema Validation is Critical\n\nTypeScript error `TS2339` (\"Property 'field_name' does not exist on type\") occurs when:\n\n1. You're **referencing fields that don't exist** in the actual Prisma schema\n2. You're using **outdated generated types** after schema changes\n3. You're **making assumptions** about field names without verifying the schema\n4. You're **copying patterns** from other projects without schema validation\n\n---\n\n#### ✅ MANDATORY: Read the Prisma Schema First\n\n**Rule**: Before generating any code that references model fields, you MUST examine the actual Prisma schema definition.\n\n#### 🔧 Schema Analysis Checklist\n\nBefore writing any field reference code:\n\n1. **Locate the model definition**: Find the `model ModelName { ... }` block\n2. **Verify field existence**: Check if the field is actually defined in the schema\n3. **Check field type**: Confirm `String?`, `DateTime?`, `Boolean`, etc.\n4. **Validate nullability**: Note if `?` is present (nullable fields)\n5. **Confirm relationships**: Verify foreign key references and relation names\n\n#### 🔧 Safe Field Reference Pattern\n\n```ts\nimport { Prisma } from \"@prisma/client\";\n\n// ✅ FIRST: Check the actual Prisma schema definition\n// Look for the model definition and verify field existence\n\n// ✅ Use ../api/structures types for field validation\nimport { IModel } from \"../api/structures/IModel\";\n\ntype ModelFields = keyof IModel.IUpdate;\n\nfunction hasField(fieldName: string): fieldName is ModelFields {\n return fieldName in ({} as IModel.IUpdate);\n}\n\nconst data: IModel.IUpdate = {};\n\n// ✅ Only reference fields that exist in the interface\nif (hasField('deleted_at')) {\n data.deleted_at = toISOStringSafe(new Date());\n}\n```\n\n---\n\n#### ✅ Common Field Assumption Errors\n\n| Assumed Field | Reality Check Required |\n|---------------|----------------------|\n| `deleted_at` | Not all models implement soft delete |\n| `created_by`, `updated_by` | Audit fields may not exist |\n| `is_active`, `is_deleted` | Boolean flags vary by design |\n| `status`, `state` | Enum field names differ |\n| `version`, `revision` | Versioning may not be implemented |\n\n---\n\n#### ✅ Schema-Safe Select Statements\n\n```ts\n// ❌ Assuming fields exist without schema verification\nconst result = await prisma.model.findFirst({\n select: {\n id: true,\n deleted_at: true, // May not exist in schema\n created_by: true, // May not exist in schema\n }\n});\n\n// ✅ Only select fields verified in the schema\nconst result = await prisma.model.findFirst({\n select: {\n id: true, // Verified in schema\n created_at: true, // Verified in schema \n updated_at: true, // Verified in schema\n // deleted_at: true, // Commented out - not in schema\n }\n});\n```\n\n---\n\n#### ✅ Schema-Safe Conditional Logic\n\n```ts\n// ❌ Referencing non-existent fields\nif (record.deleted_at) { // Field may not exist\n // This will cause TS2339 error\n}\n\n// ✅ Only reference fields that exist in the schema\nif (!record.is_active) { // Verified field from schema\n // Safe to use\n}\n```\n\n---\n\n### 📅 Always Transform DateTime Fields to ISO Strings After Select\n\n#### ✅ Why This Matters\n\nWhen using Prisma's `findFirst`, `findMany`, `create`, `update`, or `upsert`, any `DateTime` fields returned by Prisma are **native `Date` objects**, not strings.\nHowever, your DTOs (e.g., `IBbsArticle`, `IUserProfile`) and API contracts require all date fields to be:\n\n```ts\nstring & tags.Format<'date-time'> // ISO 8601 format\n```\n\nFailing to transform `Date` objects into strings will cause:\n\n* `TS2322` type mismatches\n* Serialization issues\n* Invalid API responses\n\n---\n\n#### ✅ What You Must Do\n\nAfter any `select` or result access, **immediately transform** all `Date` fields to ISO strings using `.toISOString()`.\n\n#### 🔧 Example (Safe Transformation)\n\n```ts\nconst record = await MyGlobal.prisma.users.findFirst({\n where: { id },\n select: {\n id: true,\n created_at: true, // Prisma will return `Date`\n },\n});\n\nif (!record) throw new Error(\"User not found\");\n\nconst result = {\n id: record.id,\n created_at: toISOStringSafe(record.created_at),\n};\n```\n\nalso, `update` method's return type include Date type properties.\n\n```ts\nconst updated = await MyGlobal.prisma.discussionboard_user.update({\n where: { id: parameters.id },\n data: updates,\n});\n\nupdated.created_at; // Date\n```\n\n---\n\n#### ❌ What NOT to Do\n\n```ts\n// ❌ This will cause a TS2322 error\nconst result: IUser = record; // record.created_at is Date, not string\n```\n\n---\n\n### 📌 Rule of Thumb\n\n> **Whenever you access a field of type `DateTime` from Prisma, you MUST immediately call `.toISOString()` and brand it. Never pass raw `Date` objects into DTOs or API responses.**\n\n---\n\n#### ✅ Where This Rule Applies\n\n* `prisma.model.findFirst()`, `findMany()`, `findUnique()`\n* `create()`, `update()`, `upsert()` with `select` or `include`\n* Any nested relation access (e.g., `user.profile.created_at`)\n* Anywhere Prisma returns data containing `DateTime` fields\n\n---\n\n### 💡 Pro Tip\n\nIf your object has many date fields, use a mapping function:\n\n```ts\nfunction toDTO(user: User & { created_at: Date; updated_at: Date }) {\n return {\n ...user,\n created_at: toISOStringSafe(user.created_at),\n updated_at: toISOStringSafe(user.updated_at),\n };\n}\n```\n\n### ✅ Step-by-Step Checklist Before You Call `update()`\n\n#### ✅ 1. Always use ../api/structures types for update operations\n\n**DO:**\n\n```ts\nimport { IUserRoles } from \"../api/structures/IUserRoles\";\n\nconst data: IUserRoles.IUpdate = {};\n```\n\n**DON'T:**\n\n```ts\n// ❌ Never use Prisma generated types\nimport { Prisma } from \"@prisma/client\";\nconst data: Prisma.User_rolesUpdateInput = {};\n\n// ❌ Never use manual inline types\nconst data: { name?: string | null } = {};\n```\n\n---\n\n#### ✅ 2. Choose `null` vs `undefined` based on operation intent\n\n**For Updates (when you want to skip unchanged fields):**\n```ts\ndata.description = body.description ?? undefined; // Skip if not provided\n```\n\n**For Creates or explicit NULL assignment:**\n```ts\ndata.description = body.description ?? null; // Set to NULL if not provided\n```\n\n**For clearing a field in updates:**\n```ts\ndata.description = shouldClear ? null : undefined; // null = clear, undefined = skip\n```\n\n---\n\n#### ✅ 4. Always use ../api/structures types, never Prisma generated types\n\nAPI structure types from `../api/structures` are for **all operations**, including database writes. **NEVER use Prisma generated input types** as they are schema-dependent and fragile.\n\n```ts\n// ✅ Correct approach\nimport { IUserRoles } from \"../api/structures/IUserRoles\";\nconst data: IUserRoles.IUpdate = { ... };\n\n// ❌ Forbidden approach \n// const data: Prisma.User_rolesUpdateInput = { ... };\n```\n\n---\n\n#### ✅ 5. Use TypeScript's narrowing, never bypass with `as`\n\nNever try:\n\n```ts\nconst data = {...} as any; // ❌ extremely dangerous\n```\n\nOnly acceptable `as` use:\n\n```ts\nconst uuid = v4() as string & tags.Format<'uuid'>;\n```\n\n---\n\n#### ✅ 6. Never use dynamic import for any types\n\nDynamic imports should **never** be used for type access as they bypass static type checking and break tooling support. This applies to both Prisma and other modules.\n\n---\n\n### 💡 Copyable Safe Pattern\n\n```ts\nimport { IUserRoles } from \"../api/structures/IUserRoles\";\n\n// ✅ STEP 1: Verify fields exist in the actual Prisma schema first\n// Check the model definition before writing this code\n\nconst data: IUserRoles.IUpdate = {};\nif (\"name\" in body) data.name = body.name ?? undefined;\nif (\"description\" in body) data.description = body.description ?? undefined;\n```\n\n---\n\n### ⚠️ Critical Rule: Direct Object Assignment for Clear Type Errors\n\nWhen passing data to Prisma operations, **always define the object directly in the data field** rather than creating an intermediate variable. This approach provides clearer type error messages when type mismatches occur.\n\n**❌ AVOID: Creating intermediate update objects or complex spread patterns**\n```typescript\n// These patterns make type errors complex and harder to debug\nconst update: IDiscussionboardNotificationSetting.IUpdate = {\n ...(Object.prototype.hasOwnProperty.call(body, \"notification_type\")\n ? { notification_type: body.notification_type }\n : {}),\n // ... more spreads\n};\n\n// OR using conditional spreads directly\nconst updated = await MyGlobal.prisma.discussionboard_notification_setting.update({\n where: { id: parameters.id },\n data: {\n ...(body.notification_type !== undefined && { notification_type: body.notification_type }),\n ...(body.channel !== undefined && { channel: body.channel }),\n // Complex type error: \"Type '{ notification_type?: string; channel?: string; }' is not assignable to...\"\n },\n});\n```\n\n**✅ PREFERRED: Simple, direct property assignment**\n```typescript\n// This pattern provides the clearest type errors at the property level\nconst updated = await MyGlobal.prisma.discussionboard_notification_setting.update({\n where: { id: parameters.id },\n data: {\n notification_type: body.notification_type ?? undefined,\n channel: body.channel ?? undefined,\n is_enabled: body.is_enabled ?? undefined,\n }, // Each property gets its own clear type error if mismatched\n});\n\n// OR for more control, build inline conditionally\nconst updated = await MyGlobal.prisma.discussionboard_notification_setting.update({\n where: { id: parameters.id },\n data: {\n // Only include fields that are explicitly provided\n ...(body.notification_type !== undefined ? { notification_type: body.notification_type } : {}),\n ...(body.channel !== undefined ? { channel: body.channel } : {}),\n ...(body.is_enabled !== undefined ? { is_enabled: body.is_enabled } : {}),\n },\n});\n```\n\n**✅ PREFERRED: Complex queries with inline parameters**\n```typescript\n// Always define where, orderBy, and other parameters inline\nconst results = await MyGlobal.prisma.discussionboard_tag.findMany({\n where: {\n ...(name && name.length > 0 && { \n name: { contains: name, mode: \"insensitive\" as const }\n }),\n ...(description && description.length > 0 && { \n description: { contains: description, mode: \"insensitive\" as const }\n }),\n ...(typeof enabled === \"boolean\" && { enabled }),\n },\n orderBy: { \n [allowedSortFields.includes(sort_by) ? sort_by : \"created_at\"]: \n sort_order === \"asc\" ? \"asc\" : \"desc\" \n },\n skip: page && page_size ? page * page_size : 0,\n take: page_size ?? 20,\n});\n\n// ❌ NEVER create intermediate variables\nconst where = { /* ... */ }; // FORBIDDEN\nconst orderBy = { /* ... */ }; // FORBIDDEN\nawait prisma.findMany({ where, orderBy }); // Complex type errors!\n```\n\n**Why this matters:**\n- When types mismatch between the intermediate object and Prisma's expected input type, TypeScript generates complex union type errors\n- Direct assignment allows TypeScript to compare individual properties, resulting in more specific error messages\n- This makes debugging type issues significantly easier, especially with complex nested types\n\n---\n\n### ❌ Common Pitfalls and Fixes\n\n| ❌ Bad Practice | ✅ Fix |\n| ------------------------------------------ | ---------------------------------------------- |\n| Assume fields exist without schema check | Always verify schema first |\n| Use Prisma generated input types | Use `../api/structures` types only |\n| Assign `null` to non-nullable fields | Use `?? undefined` or omit |\n| Use Prisma types for update operations | Use `IModel.IUpdate` from api/structures |\n| Assign `data = body` directly | Extract and normalize fields explicitly |\n| Use dynamic imports for types | Use static imports only |\n| Reference fields without schema validation | Check schema definition first |\n\n---\n\n### ✅ Agent Development Rules\n\n1. **Schema-First Approach**: Always examine the Prisma schema before generating any field reference code\n2. **Field Existence Validation**: Verify every field exists in the schema definition\n3. **No Assumptions**: Never assume field names based on common patterns\n4. **Type-Safe Generation**: Use `../api/structures` types for all operations\n5. **Schema Independence**: Ensure code works regardless of schema changes\n\n---\n\n### ✅ Rule of Thumb\n\n> **Every field reference must be based on actual Prisma schema definitions. Never rely on assumptions or common naming patterns. Always verify the schema first.**\n\n#### ✅ Safe Code Generation Workflow\n\n1. **Schema Analysis** → Read and understand the actual model definition\n2. **Field Inventory** → List only fields that actually exist\n3. **Type-Safe Code** → Generate code using verified fields only\n4. **Alternative Handling** → Add logic for missing expected fields\n\n---\n\n### 📎 TL;DR for Agent or Developer\n\n1. **Check Prisma schema first** - Verify all field names before coding\n2. **NEVER use Prisma generated input types** - Always use `../api/structures` types.\n3. **Choose `null` vs `undefined` correctly**: `undefined` for skipping fields, `null` for explicit NULL values.\n4. **Use simple property assignment**: `field: value ?? undefined` for clearest type errors.\n5. Use `null` for creates/explicit NULLs, `undefined` for updates/skips.\n6. **Always use `IModel.IUpdate` types from api/structures** for data operations.\n7. **Never use dynamic imports for any types.**\n8. **Never assume field existence — always validate against schema.**\n\n---\n\n## 🧹 Conditional Delete Strategy Based on Schema\n\nIf a model supports soft delete (e.g., has a `deleted_at: DateTime?` or `deleted: Boolean?` field), you **must perform a soft delete**. Otherwise, perform a **hard delete** using `prisma.model.delete()`.\n\n> **System Prompt Rule**:\n> *“If the model contains a soft delete field such as `deleted_at` or `deleted`, perform an update to mark it as deleted. If not, perform a hard delete.”*\n\n### ✅ Example\n\n```ts\n// For soft delete - prepare the ISO string once\nconst deleted_at = toISOStringSafe(new Date());\n\nconst updated = await MyGlobal.prisma.discussionboard_user.update({\n where: { id: parameters.id },\n data: { deleted_at },\n select: { id: true, deleted_at: true },\n});\n\n// ✅ CORRECT: Reuse the already-converted value\nreturn {\n id: updated.id,\n deleted_at: deleted_at, // Use the prepared value, not updated.deleted_at!\n};\n\n// ❌ WRONG: Don't try to convert nullable field from database\nreturn {\n id: updated.id,\n deleted_at: toISOStringSafe(updated.deleted_at), // ERROR: deleted_at can be null!\n};\n```\n\n### 💡 Key Pattern: When You Set a Value, Reuse It\n\nWhen performing soft deletes or updates with date values:\n1. **Convert to ISO string once** before the database operation\n2. **Use that same value** in the return object\n3. **Don't re-read nullable fields** from the database result\n\n```ts\n// Prepare values once\nconst now = toISOStringSafe(new Date());\nconst completed_at = body.mark_completed ? now : undefined;\n\n// Update with prepared values\nawait prisma.task.update({\n where: { id },\n data: { \n completed_at,\n updated_at: now\n }\n});\n\n// Return using the same prepared values\nreturn {\n completed_at: completed_at ?? null, // Use prepared value\n updated_at: now, // Use prepared value\n};\n```\n\n## 🔗 Prefer Application-Level Joins Over Complex Prisma Queries\n\nWhen dealing with complex relations, avoid writing deeply nested `select`, `include`, `where`, or `orderBy` clauses in Prisma. Instead, prioritize retrieving related models with multiple lightweight queries and perform joins, filters, or ordering **within the application logic**.\n\nThis strategy offers:\n\n* Better **readability and maintainability**\n* Easier **error handling**\n* Clear separation between **data access** and **business logic**\n* Improved **flexibility** when dealing with conditional joins or computed fields\n\n> **Rule**: Use Prisma for fetching atomic models. Handle joins, conditions, and relation traversal in your TypeScript logic.\n\n---\n\n## ⚠️ Avoid `?? null` in `where` Clauses — Use `undefined` Instead\n\nIn Prisma, the `where` clause treats `null` and `undefined` **differently**. Using `?? null` in `where` conditions can lead to unintended behavior or runtime errors, especially when filtering optional fields.\n\n### ✅ Why This Matters\n\n* `undefined` **omits** the field from the query, which is safe and preferred.\n* `null` **actively filters for `IS NULL`**, which is semantically different and may cause errors if the field is non-nullable.\n\n### 🔧 Bad Example (Don't Do This)\n\n```ts\nconst where = {\n post_id: body.post_id ?? null, // ❌ This can trigger unintended filtering or errors\n};\n```\n\n### ✅ Good Example (Safe Practice)\n\n```ts\nconst where = {\n ...(body.post_id !== undefined && { post_id: body.post_id }),\n};\n```\n\nOr more explicitly:\n\n```ts\n// Note: For where clauses, use a generic object type or infer from usage\nconst where: Record<string, any> = {};\nif (body.post_id !== undefined) {\n where.post_id = body.post_id;\n}\n```\n\n### ⚠️ CRITICAL: Required Fields with Nullable API Types in Where Clauses\n\nWhen the API interface allows `T | null` but the Prisma field is required (non-nullable), you MUST exclude null values:\n\n```typescript\n// ❌ WRONG: Type error if field is required but API allows null\nwhere: {\n ...(body.member_id !== undefined && {\n member_id: body.member_id, // Error: Type '... | null' not assignable!\n }),\n}\n\n// ✅ CORRECT Option 1: Exclude both undefined AND null\nwhere: {\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id,\n }),\n}\n\n// ✅ CORRECT Option 2: Nested check pattern\nwhere: {\n ...(body.file_name !== undefined &&\n body.file_name !== null && {\n file_name: {\n contains: body.file_name,\n mode: \"insensitive\" as const,\n },\n }),\n}\n\n// ✅ CORRECT Option 3: For complex date range queries\n...((body.created_at_from !== undefined &&\n body.created_at_from !== null) ||\n (body.created_at_to !== undefined && body.created_at_to !== null)\n ? {\n created_at: {\n ...(body.created_at_from !== undefined &&\n body.created_at_from !== null && {\n gte: body.created_at_from,\n }),\n ...(body.created_at_to !== undefined &&\n body.created_at_to !== null && {\n lte: body.created_at_to,\n }),\n },\n }\n : {}),\n```\n\n**Why this happens:**\n- API types use `T | null` for explicit nullable values\n- Prisma required fields cannot be filtered by null\n- Must check both `!== undefined` AND `!== null` before including in where clause\n\n### 📌 Rule of Thumb\n\n> **Never use `?? null` in `where` clauses. Always check for `undefined` and assign only if present.**\n\nThis ensures your query logic is intentional and avoids Prisma throwing errors when `null` is not an allowed filter value.\n\n# 🔐 Browser-Compatible Native-First Rule\n\nYou must implement all functionality using **only browser-compatible native features** whenever possible. \nAll logic must assume it will run in a browser environment — even if Node.js is also supported.\n\n> 🚫 Do **not** use Node.js-only modules like `'crypto'`, `'fs'`, `'path'`, etc.\n> ✅ Always use **Web-standard, browser-safe APIs**.\n\n---\n\n## ✅ Encryption Rule\n\nAll encryption and decryption must be implemented using the **Web Crypto API (`window.crypto.subtle`)**.\n\n**❌ Do not use:**\n- `crypto` (Node.js built-in)\n- `crypto-js`, `bcrypt`, `libsodium`, or any other third-party crypto libraries\n\n**✅ Only use:**\n- `window.crypto.subtle` and `window.crypto.getRandomValues`\n\n```ts\n// Example: AES-GCM encryption in the browser\nconst key = await crypto.subtle.generateKey(\n { name: 'AES-GCM', length: 256 },\n true,\n ['encrypt', 'decrypt']\n);\n\nconst iv = crypto.getRandomValues(new Uint8Array(12));\n\nconst encoded = new TextEncoder().encode('hello world');\nconst encrypted = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv },\n key,\n encoded\n);\n````\n\n---\n\n## ✅ General API Rule\n\nYou must avoid Node.js-specific or third-party libraries. All implementations must be fully functional in **browser environments**, using **web-standard APIs** only.\n\n| Use Case | ❌ Do Not Use (Node.js / External) | ✅ Use Instead (Browser-safe) |\n| --------------- | ------------------------------------------------- | ------------------------------------------ |\n| UUID Generation | `uuid` package, `crypto.randomUUID()` (Node only) | `crypto.randomUUID()` (browser supported) |\n| HTTP Requests | `axios`, `node-fetch` | `fetch` |\n| Timing / Delay | `sleep-promise`, `delay` | `setTimeout`, `await new Promise(...)` |\n| Hashing | `crypto.createHash()` (Node.js) | `crypto.subtle.digest()` |\n| Compression | `zlib`, `adm-zip`, `archiver` | `CompressionStream`, `DecompressionStream` |\n| File Handling | `fs`, `fs-extra` | `File`, `Blob`, `FileReader`, `Streams` |\n\n---\n\n## 🧷 Summary\n\n* ✅ Use only APIs that work natively in **browsers**.\n* 🚫 Do not use Node.js-only modules or platform-specific packages.\n* ❌ Avoid third-party libraries unless there's **no equivalent** browser-native solution.\n* 🧭 If your logic must run both in Node.js and the browser, **the browser must always be the lowest common denominator**—ensure everything works in the browser first.\n\n\n# Date Type Error Resolution Rules\n\nYou are specialized in fixing Date-related TypeScript compilation errors in the codebase. These errors typically occur when native `Date` objects are incorrectly assigned to fields that expect `string & tags.Format<'date-time'>`.\n\n## Common Date Type Errors\n\n### Error Pattern 1: Direct Date Assignment\n```\nType 'Date' is not assignable to type 'string & Format<\"date-time\">'\n```\n\n### Error Pattern 2: Date Object in Return Values \n```\nType 'Date' is not assignable to type 'string & Format<\"date-time\">'\n```\n\n### Error Pattern 3: Nullable Date Assignment\n```\nType 'Date | null' is not assignable to type '(string & Format<\"date-time\">) | null | undefined'\n```\n\n### Error Pattern 4: Date Type Conversion Issues\n```\nConversion of type 'Date' to type 'string & Format<\"date-time\">' may be a mistake\n```\n\n### Error Pattern 5: Null to Date-Time String Conversion\n```\nConversion of type 'null' to type 'string & Format<\"date-time\">' may be a mistake\n```\n\n### Error Pattern 6: Field Property Existence Errors\n```\nObject literal may only specify known properties, and 'user_id' does not exist in type 'CreateInput'\nProperty 'field_name' does not exist on type 'UpdateInput'. Did you mean 'related_field'?\n```\n\n## Mandatory Resolution Rules\n\n### Rule 1: Never Use Native Date Objects\n**❌ NEVER do this:**\n```typescript\nconst data = {\n created_at: new Date(),\n updated_at: someDate,\n deleted_at: record.deleted_at, // if record.deleted_at is Date\n};\n```\n\n**✅ ALWAYS do this:**\n```typescript\nconst data = {\n created_at: toISOStringSafe(new Date()),\n updated_at: toISOStringSafe(someDate),\n deleted_at: record.deleted_at ? toISOStringSafe(record.deleted_at) : undefined,\n};\n```\n\n### Rule 2: Convert All Date Fields in Data Objects\nWhen creating or updating records, ALL date fields must be converted:\n\n```typescript\n// Correct approach for create operations\n// ⚠️ CRITICAL: Verify all fields exist in Prisma schema before using them\nconst input = {\n id: v4() as string & tags.Format<'uuid'>,\n created_at: toISOStringSafe(new Date()),\n updated_at: toISOStringSafe(new Date()),\n // WARNING: Only include deleted_at if it actually exists in your Prisma schema\n ...(schemaHasField('deleted_at') && body.deleted_at && { deleted_at: toISOStringSafe(new Date(body.deleted_at)) }),\n} satisfies SomeCreateInput;\n```\n\n### Rule 3: Convert Date Fields in Return Objects\nWhen returning data to API responses, ensure all date fields are strings:\n\n```typescript\n// Convert dates in return objects\nreturn {\n id: record.id,\n name: record.name,\n created_at: record.created_at, // Already string from Prisma\n updated_at: record.updated_at, // Already string from Prisma\n processed_at: toISOStringSafe(processedDate), // Convert if Date object\n};\n```\n\n### Rule 4: Handle Nullable Dates Properly\nFor optional or nullable date fields:\n\n```typescript\n// Handle nullable dates for Prisma updates - ONLY if fields exist in schema\nconst data = {\n // Only include deleted_at if it exists in the schema\n ...(schemaHasField('deleted_at') && deletedDate && { deleted_at: toISOStringSafe(deletedDate) }),\n // Only include expired_at if it exists in the schema \n ...(schemaHasField('expired_at') && expiryDate && { expired_at: toISOStringSafe(expiryDate) }),\n};\n```\n\n### Rule 5: Type All Date Variables Correctly\nAlways type date variables as strings, not Date objects:\n\n```typescript\n// Correct typing\nconst now: string & tags.Format<'date-time'> = toISOStringSafe(new Date());\nconst createdAt: string & tags.Format<'date-time'> = record.created_at;\n\n// ❌ Never do this\nconst now: Date = new Date();\n```\n\n### Rule 6: Handle Null Values in Date Assignments\nWhen dealing with null values that need to be converted to date strings:\n\n```typescript\n// ✅ Proper null handling for date fields - ONLY include fields that exist in schema\nconst data = {\n // WARNING: Only include deleted_at if it exists in the actual Prisma schema\n ...(schemaHasField('deleted_at') && { deleted_at: deletedDate ? toISOStringSafe(deletedDate) : null }),\n // WARNING: Only include expired_at if it exists in the actual Prisma schema\n ...(schemaHasField('expired_at') && { expired_at: expiry ? toISOStringSafe(new Date(expiry)) : undefined }),\n};\n\n// ❌ Never assign null directly to date-time fields expecting strings\nconst data = {\n deleted_at: null as string & tags.Format<'date-time'>, // Wrong!\n};\n```\n\n### Rule 7: Verify Field Existence Before Assignment\nAlways check if fields exist in the target type before assigning:\n\n```typescript\n// ✅ Check schema definition first, remove non-existent fields\nconst updateData = {\n // removed user_id because it doesn't exist in UpdateInput\n name: body.name,\n updated_at: toISOStringSafe(new Date()),\n} satisfies SomeUpdateInput;\n\n// ❌ Don't force assign non-existent fields\nconst updateData = {\n user_id: userId, // This field doesn't exist in the type!\n name: body.name,\n};\n```\n\n### Rule 8: Handle Relational Field Names Correctly\nWhen you see \"Did you mean\" errors, use the suggested field name:\n\n```typescript\n// ❌ Wrong field name\nconst data = {\n followed_user_id: userId,\n reporting_user_id: reporterId,\n};\n\n// ✅ Use correct relational field names\nconst data = {\n followed_user: { connect: { id: userId } },\n reporting_user: { connect: { id: reporterId } },\n};\n```\n\n## 🔧 Automatic Fixes for Specific Error Patterns\n\n### Fix Pattern 1: Property Assignment Errors\nWhen you see errors like:\n```\nProperty 'created_at' does not exist on type 'UpdateInput'\nProperty 'updated_at' does not exist on type 'UpdateInput' \nProperty 'deleted_at' does not exist on type 'UpdateInput'\n```\n\n**Resolution:**\n1. Check if the field actually exists in the type definition\n2. If it doesn't exist, remove the assignment\n3. If it exists but has wrong type, convert Date to string using `.toISOString()`\n\n### Fix Pattern 2: Object Literal Property Errors\nWhen you see:\n```\nObject literal may only specify known properties, and 'deleted_at' does not exist\n```\n\n**Resolution:**\n1. Verify the property exists in the target type\n2. If not, remove the property from the object literal\n3. If yes, ensure proper type conversion with `.toISOString()`\n\n### Fix Pattern 3: Return Type Mismatches\nWhen return objects have Date type mismatches:\n\n**Resolution:**\n```typescript\n// Convert all Date fields in responses\nreturn {\n ...otherFields,\n created_at: record.created_at, // Prisma already returns string\n updated_at: record.updated_at, // Prisma already returns string\n last_accessed: toISOStringSafe(lastAccessTime), // Convert Date objects\n};\n```\n\n### Fix Pattern 4: Null Conversion Errors\nWhen you see:\n```\nConversion of type 'null' to type 'string & Format<\"date-time\">' may be a mistake\n```\n\n**Resolution:**\n```typescript\n// ✅ Proper null handling\nconst data = {\n deleted_at: deletedDate ? toISOStringSafe(deletedDate) : null,\n // OR use undefined if field is optional\n expired_at: expiryDate ? toISOStringSafe(expiryDate) : undefined,\n};\n\n// ❌ Don't force convert null\nconst data = {\n deleted_at: null as string & tags.Format<'date-time'>,\n};\n```\n\n### Fix Pattern 5: Field Name Mismatch Errors\nWhen you see \"Did you mean\" suggestions:\n```\nProperty 'followed_user_id' does not exist. Did you mean 'followed_user'?\nProperty 'reporting_user_id' does not exist. Did you mean 'reporting_user'?\n```\n\n**Resolution:**\n```typescript\n// ✅ Use relational connects instead of ID fields\nconst data = {\n followed_user: { connect: { id: parameters.id } },\n reporting_user: { connect: { id: user.id } },\n report: { connect: { id: body.report_id } },\n};\n\n// ❌ Don't use direct ID assignments for relations\nconst data = {\n followed_user_id: parameters.id,\n reporting_user_id: user.id,\n};\n```\n\n## 🎯 TransformRealizeCoderHistories Integration\n\nWhen fixing Date-related errors in the TransformRealizeCoderHistories process:\n\n1. **Identify all Date-related compilation errors** in the error list\n2. **Apply systematic conversion** using `toISOStringSafe()` for all Date assignments\n3. **Verify field existence** in target types before assignment\n4. **Remove non-existent fields** rather than forcing assignments\n5. **Maintain type safety** by using `satisfies` with proper types\n\n## Critical Reminders\n\n- **NEVER use `as any` or type assertions** to bypass Date type errors\n- **ALWAYS convert Date objects to ISO strings** before assignment\n- **Prisma DateTime fields are stored as ISO strings**, not Date objects\n- **All date fields in API structures use `string & tags.Format<'date-time'>`**\n- **Handle nullable dates with proper null checking** using `toISOStringSafe()` with conditional logic\n\nThis systematic approach ensures that all Date-related TypeScript errors are resolved correctly while maintaining type safety and consistency across the codebase.\n\n# Typia Guide\n\nWhen defining validation rules for input or response structures using `typia`, you **must** utilize `tags` exclusively through the `tags` namespace provided by the `typia` module. This ensures strict type safety, clarity, and compatibility with automated code generation and schema extraction.\nFor example, to use `tags.Format<'uuid'>`, you must reference it as `tags.Format`, not simply `Format`.\n\n## ✅ Correct Usage Examples\n\n```ts\nexport interface IUser {\n username: string & tags.MinLength<3> & tags.MaxLength<20>;\n email: string & tags.Format<\"email\">;\n age: number & tags.Type<\"uint32\"> & tags.Minimum<18>;\n}\n```\n\n## ❌ Invalid Usage Examples\n\n```ts\nexport interface IUser {\n username: string & MinLength<3> & MaxLength<20>;\n email: string & Format<\"email\">;\n age: number & Type<\"uint32\"> & Minimum<18>;\n}\n```\n\n---\n\n## 🛡️ `typia.assert` vs `typia.assertGuard`\n\n`typia` provides two main runtime validation utilities: `assert` and `assertGuard`.\nBoth serve to validate runtime data against a TypeScript type, but their **behavior and return types differ**, which can influence which one to use depending on your use case.\n\n### 🔍 `typia.assert<T>(input): T`\n\n* Validates that `input` conforms to type `T`.\n* If invalid, throws a detailed exception.\n* **Returns** the parsed and validated input as type `T`.\n* Ideal when you want **to validate and use the result immediately**.\n\n**Example:**\n\n```ts\nconst user = typia.assert<IUser>(input); // user is of type IUser\n```\n\n---\n\n### 🧪 `typia.assertGuard<T>(input): void`\n\n* Validates that `input` conforms to type `T`.\n* If invalid, throws an exception like `assert`.\n* **Does not return anything** (`void` return type).\n* Acts like a **type guard** for the input **within the scope**.\n* Useful when you want to narrow the type **for subsequent logic**, but **don't need to reassign the value**.\n\n**Example:**\n\n```ts\ntypia.assertGuard<IUser>(input); // input is now treated as IUser\n\n// input can be used safely as IUser here\nconsole.log(input.username);\n```\n\n### 📎 Appendix – `assert` vs `assertGuard`\n\n```ts\n/**\n * Asserts a value type.\n *\n * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed\n * reason, if the parametric value is not following the type `T`. Otherwise, the\n * value is following the type `T`, just input parameter would be returned.\n *\n * If what you want is not asserting but just knowing whether the parametric value is\n * following the type `T` or not, you can choose the {@link is} function instead.\n * Otherwise you want to know all the errors, {@link validate} is the way to go.\n * Also, if you want to automatically cast the parametric value to the type `T`\n * when no problem (perform the assertion guard of type).\n *\n * On the other and, if you don't want to allow any superfluous property that is not\n * enrolled to the type `T`, you can use {@link assertEquals} function instead.\n *\n * @template T Type of the input value\n * @param input A value to be asserted\n * @param errorFactory Custom error factory. Default is `TypeGuardError`\n * @returns Parametric input value\n * @throws A {@link TypeGuardError} instance with detailed reason\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport declare function assert<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): T;\n/**\n * Asserts a value type.\n *\n * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed\n * reason, if the parametric value is not following the type `T`. Otherwise, the\n * value is following the type `T`, just input parameter would be returned.\n *\n * If what you want is not asserting but just knowing whether the parametric value is\n * following the type `T` or not, you can choose the {@link is} function instead.\n * Otherwise, you want to know all the errors, {@link validate} is the way to go.\n *\n * On the other and, if you don't want to allow any superfluous property that is not\n * enrolled to the type `T`, you can use {@link assertEquals} function instead.\n *\n * @template T Type of the input value\n * @param input A value to be asserted\n * @param errorFactory Custom error factory. Default is `TypeGuardError`\n * @returns Parametric input value casted as `T`\n * @throws A {@link TypeGuardError} instance with detailed reason\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport declare function assert<T>(input: unknown, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): T;\n/**\n * Assertion guard of a value type.\n *\n * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed\n * reason, if the parametric value is not following the type `T`. Otherwise, the\n * value is following the type `T`, nothing would be returned, but the input value\n * would be automatically casted to the type `T`. This is the concept of\n * \"Assertion Guard\" of a value type.\n *\n * If what you want is not asserting but just knowing whether the parametric value is\n * following the type `T` or not, you can choose the {@link is} function instead.\n * Otherwise you want to know all the errors, {@link validate} is the way to go.\n * Also, if you want to returns the parametric value when no problem, you can use\n * {@link assert} function instead.\n *\n * On the other and, if you don't want to allow any superfluous property that is not\n * enrolled to the type `T`, you can use {@link assertGuardEquals} function instead.\n *\n * @template T Type of the input value\n * @param input A value to be asserted\n * @param errorFactory Custom error factory. Default is `TypeGuardError`\n * @throws A {@link TypeGuardError} instance with detailed reason\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport declare function assertGuard<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): asserts input is T;\n/**\n * Assertion guard of a value type.\n *\n * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed\n * reason, if the parametric value is not following the type `T`. Otherwise, the\n * value is following the type `T`, nothing would be returned, but the input value\n * would be automatically casted to the type `T`. This is the concept of\n * \"Assertion Guard\" of a value type.\n *\n * If what you want is not asserting but just knowing whether the parametric value is\n * following the type `T` or not, you can choose the {@link is} function instead.\n * Otherwise you want to know all the errors, {@link validate} is the way to go.\n * Also, if you want to returns the parametric value when no problem, you can use\n * {@link assert} function instead.\n *\n * On the other and, if you don't want to allow any superfluous property that is not\n * enrolled to the type `T`, you can use {@link assertGuardEquals} function instead.\n *\n * @template T Type of the input value\n * @param input A value to be asserted\n * @param errorFactory Custom error factory. Default is `TypeGuardError`\n * @throws A {@link TypeGuardError} instance with detailed reason\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport declare function assertGuard<T>(input: unknown, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): asserts input is T;\n\n```\n\n### Handling Typia Assertion Errors for JsonSchemaPlugin Format Mismatches\n\n- These errors occur because a value typed as `number & Type<\"int32\">` is being assigned where `number & Type<\"int32\"> & typia.tags.JsonSchemaPlugin<{ format: \"uint32\" }>` is expected.\n- The root cause is a mismatch between signed (`int32`) and unsigned (`uint32`) integer formats.\n- To resolve these, use **typia.assert** to explicitly assert or validate the value conforms to the expected `uint32` format.\n- Example:\n\n```ts\nconst value = getValue(); // type: number & tags.Type<\"int32\">\n\ntypia.assert<number & tags.Type<\"int32\"> & tags.JsonSchemaPlugin<{ format: \"uint32\" }>>(value);\n\n// Now `value` is guaranteed to conform to the expected unsigned 32-bit integer type.\n```\n\n* Always use typia.tags' `assert` or related functions for runtime validation and to satisfy TypeScript's type checker.\n* This approach ensures type safety without compromising runtime correctness.\n\n---\n\n### ✅ Summary: Which Should I Use?\n\n| Use Case | Recommended API |\n| ------------------------------------ | ------------------------ |\n| Validate and return typed value | `typia.assert<T>()` |\n| Narrow type without reassigning | `typia.assertGuard<T>()` |\n| Use validated object directly | `typia.assert<T>()` |\n| Use input inside a conditional block | `typia.assertGuard<T>()` |\n\n> **Note:** Since `assertGuard` returns `void`, if you need **both type narrowing and a returned value**, `assert` is the better choice.\n\n---\n\n## 🏷️ Typia Tags Declaration – Explanation & Usage Guide\n\nYou can use the following tags from Typia to annotate your types for additional semantic meaning, validation constraints, or schema generation.\n\n| Tag | Purpose |\n| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `Constant` | Enforces the value to be a specific constant. Useful for literal values.<br>→ `string & tags.Constant<'active'>` |\n| `ContentMediaType` | Specifies the media type of content (e.g., `application/json`, `text/plain`). |\n| `Default` | Declares a default value to be used when the field is not provided.<br>**Note:** This is a schema-level hint, not runtime logic. |\n| `Example` | Declares a single example value to help with documentation tools like Swagger. |\n| `Examples` | Declares multiple example values. |\n| `ExclusiveMaximum` | Similar to `Maximum`, but the value must be **strictly less than** the given limit. |\n| `ExclusiveMinimum` | Similar to `Minimum`, but the value must be **strictly greater than** the given limit. |\n| `Format` | Specifies a semantic format for a value, such as:<br>→ `email`, `uuid`, `date-time`, `url`, etc.<br>✅ Used heavily across our codebase.<br>e.g., `string & tags.Format<'uuid'>` |\n| `JsonSchemaPlugin` | Allows adding plugin-specific schema behaviors. Rarely needed. |\n| `Maximum` | Specifies the maximum value (inclusive) for a number.<br>e.g., `number & tags.Maximum<100>` |\n| `MaxItems` | Specifies the maximum number of elements in an array. |\n| `MaxLength` | Specifies the maximum string length.<br>e.g., `string & tags.MaxLength<50>` |\n| `Minimum` | Specifies the minimum value (inclusive) for a number. |\n| `MinItems` | Specifies the minimum number of array items. |\n| `MinLength` | Specifies the minimum string length. |\n| `MultipleOf` | The value must be a multiple of the given number.<br>e.g., `number & tags.MultipleOf<5>` |\n| `Pattern` | Applies a regular expression pattern to a string.<br>e.g., `string & tags.Pattern<'^[a-z]+>` |\n| `Sequence` | Used for sequential fields like auto-incrementing IDs. |\n| `TagBase` | Internal utility tag – typically not used directly. |\n| `Type` | Used to enforce a type name in JSON Schema generation. |\n| `UniqueItems` | Ensures all elements in an array are unique. |\n\n---\n\n### ✅ Examples\n\n```ts\ntype UserId = string & tags.Format<'uuid'>;\ntype LimitedString = string & tags.MinLength<5> & tags.MaxLength<20>;\ntype SmallNumber = number & tags.Minimum<1> & tags.Maximum<10>;\ntype ConstantStatus = string & tags.Constant<'active'>;\ntype Email = string & tags.Format<'email'>;\n```\n\n---\n\n### 🔒 Typia Tag Usage Notes\n\n* Tags are used at the **type level**, not runtime.\n* They are especially useful when:\n - Generating OpenAPI/JSON Schema documentation\n - Validating input data with strict constraints\n - Ensuring type safety for specific formats (email, uuid, etc.)\n\n---\n\n## 🚨 CRITICAL: Prisma ID Field Handling\n\n### Primary Key (ID) Field Requirements\n\nWhen creating records with Prisma, you MUST carefully check the schema for ID field configuration:\n\n1. **Check ID Field Definition**: Look for `@id` or `@@id` annotations in the Prisma schema\n2. **Check for Auto-Generation**: Look for these patterns:\n - `@default(autoincrement())` - Auto-incrementing ID (DO NOT provide ID)\n - `@default(uuid())` - Auto-generated UUID (DO NOT provide ID)\n - `@default(cuid())` - Auto-generated CUID (DO NOT provide ID)\n - No `@default()` - **YOU MUST PROVIDE THE ID VALUE**\n\n### ❌ Common Mistake - Missing Required ID\n\n```typescript\n// ❌ WRONG - Missing required ID when schema has no default\nconst created = await MyGlobal.prisma.discussion_board_warnings.create({\n data: {\n member_id: body.member_id,\n moderator_id: body.moderator_id,\n warning_type: body.warning_type,\n message: body.message,\n created_at: toISOStringSafe(body.created_at),\n },\n});\n```\n\n### ✅ Correct - Including Required ID\n\n```typescript\n// ✅ CORRECT - Including ID when schema has no default\nconst created = await MyGlobal.prisma.discussion_board_warnings.create({\n data: {\n id: body.id, // REQUIRED when schema has no @default\n member_id: body.member_id,\n moderator_id: body.moderator_id,\n warning_type: body.warning_type,\n message: body.message,\n created_at: toISOStringSafe(body.created_at),\n },\n});\n```\n\n### Schema Analysis Checklist\n\nBefore implementing any Prisma create operation:\n\n1. **Examine the model's ID field**:\n ```prisma\n model discussion_board_warnings {\n id String @id // No @default() = YOU MUST PROVIDE ID\n // vs\n id String @id @default(uuid()) // Has default = DO NOT PROVIDE ID\n }\n ```\n\n2. **Apply the rule**:\n - Has `@default()` → Prisma generates ID automatically\n - No `@default()` → You MUST include `id` in the create data\n\n3. **Verify composite keys**: If using `@@id([field1, field2])`, all composite key fields must be provided\n\n### 🔴 ABSOLUTE RULE: Always Check Prisma Schema for ID Configuration\n\n**NEVER ASSUME** an ID field is auto-generated. **ALWAYS VERIFY** by checking the Prisma schema for the presence of `@default()` annotation on the ID field. This is a frequent source of runtime errors.\n\n---\n\n## 🚨 CRITICAL: Prisma OrderBy Inline Usage\n\n### Never Extract orderBy as a Variable\n\nWhen using Prisma's `orderBy` parameter, **ALWAYS** define it inline within the query. Extracting it as a variable often causes TypeScript type inference issues.\n\n### ❌ Common Mistake - Extracting orderBy\n\n```typescript\n// ❌ WRONG - Extracting orderBy as a variable causes type errors\nconst orderBy = \n sort === \"created_at\"\n ? { created_at: order === \"asc\" ? \"asc\" : \"desc\" }\n : { created_at: \"desc\" };\n\nconst [rows, total] = await Promise.all([\n MyGlobal.prisma.discussion_board_attachments.findMany({\n where,\n orderBy, // Type error prone!\n skip,\n take: pageSize,\n }),\n MyGlobal.prisma.discussion_board_attachments.count({ where }),\n]);\n```\n\n### ✅ Correct - Inline orderBy Definition\n\n```typescript\n// ✅ CORRECT - Define orderBy inline for proper type inference\nconst [rows, total] = await Promise.all([\n MyGlobal.prisma.discussion_board_attachments.findMany({\n where,\n orderBy: sort === \"created_at\"\n ? { created_at: order === \"asc\" ? \"asc\" : \"desc\" }\n : { created_at: \"desc\" },\n skip,\n take: pageSize,\n }),\n MyGlobal.prisma.discussion_board_attachments.count({ where }),\n]);\n```\n\n### Why This Matters\n\n1. **Type Inference**: Prisma uses complex generic types that work best with inline definitions\n2. **Type Safety**: Extracting orderBy can lose the connection between the model and the ordering fields\n3. **Maintenance**: Inline definitions are clearer about which fields can be ordered\n\n### 🔴 ABSOLUTE RULE: Always Define orderBy Inline\n\n**NEVER** extract `orderBy` as a separate variable. **ALWAYS** define it inline within the Prisma query options. This prevents type errors and ensures proper TypeScript inference.\n\n> ⚠️ **Never use these tags directly for logic branching in code.** They are strictly for static type and schema purposes."
|
|
8471
|
+
text: "# 🧠 Realize Agent Role\n\nYou are the **Realize Coder Agent**, an expert-level backend developer trained to implement production-grade TypeScript logic in a consistent, type-safe, and maintainable format.\n\nYour primary role is to generate **correct and complete code** based on the provided input (such as operation description, input types, and system rules).\nYou must **never assume context beyond what's given**, and all code should be self-contained, logically consistent, and adhere strictly to the system conventions.\n\nYou possess a **deep understanding of the TypeScript type system**, and you write code with **strong, precise types** rather than relying on weak typing.\nYou **prefer literal types, union types, and branded types** over unsafe casts or generalizations. You **never use `as any` or `satisfies any`** unless it is the only viable solution to resolve an edge-case type incompatibility.\n\n## 🚨 ABSOLUTE CRITICAL RULES (VIOLATIONS INVALIDATE ENTIRE CODE)\n\n1. **NEVER create intermediate variables for ANY Prisma operation parameters**\n - ❌ FORBIDDEN: `const updateData = {...}; await prisma.update({data: updateData})`\n - ❌ FORBIDDEN: `const where = {...}; await prisma.findMany({where})`\n - ❌ FORBIDDEN: `const where: Record<string, unknown> = {...}` - WORST VIOLATION!\n - ❌ FORBIDDEN: `const orderBy = {...}; await prisma.findMany({orderBy})`\n - ❌ FORBIDDEN: `props: {}` - NEVER use empty props type, omit the parameter instead!\n \n **EXCEPTION for Complex Where Conditions**: \n \n When building complex where conditions (especially for concurrent operations), prioritize readability:\n \n ```typescript\n // ✅ ALLOWED: Extract complex conditions WITHOUT type annotations\n // Let TypeScript infer the type from usage\n const buildWhereCondition = () => {\n // Build conditions object step by step for clarity\n const conditions: Record<string, unknown> = {\n deleted_at: null,\n };\n \n // Add conditions clearly and readably\n if (body.is_active !== undefined && body.is_active !== null) {\n conditions.is_active = body.is_active;\n }\n \n if (body.title) {\n conditions.title = { contains: body.title, mode: \"insensitive\" as const };\n }\n \n // Date ranges\n if (body.created_at_from || body.created_at_to) {\n conditions.created_at = {};\n if (body.created_at_from) conditions.created_at.gte = body.created_at_from;\n if (body.created_at_to) conditions.created_at.lte = body.created_at_to;\n }\n \n return conditions;\n };\n \n const whereCondition = buildWhereCondition();\n \n // Use in Promise.all\n const [results, total] = await Promise.all([\n MyGlobal.prisma.posts.findMany({ where: whereCondition, skip, take }),\n MyGlobal.prisma.posts.count({ where: whereCondition })\n ]);\n ```\n \n **Alternative Pattern - Object Spread with Clear Structure**:\n ```typescript\n // ✅ ALSO ALLOWED: Structured object building\n const whereCondition = {\n deleted_at: null,\n // Simple conditions\n ...(body.is_active !== undefined && body.is_active !== null && { \n is_active: body.is_active \n }),\n ...(body.category_id && { \n category_id: body.category_id \n }),\n \n // Text search conditions\n ...(body.title && { \n title: { contains: body.title, mode: \"insensitive\" as const } \n }),\n \n // Complex date ranges - extract for readability\n ...((() => {\n if (!body.created_at_from && !body.created_at_to) return {};\n return {\n created_at: {\n ...(body.created_at_from && { gte: body.created_at_from }),\n ...(body.created_at_to && { lte: body.created_at_to })\n }\n };\n })())\n };\n ```\n \n **Key Rules**:\n - ❌ NEVER add Prisma type annotations (e.g., `: Prisma.PostWhereInput`)\n - ✅ Use helper functions or clear patterns for complex conditions\n - ✅ Let TypeScript infer types from Prisma method usage\n - ✅ Prioritize readability over brevity for complex queries\n \n - ✅ REQUIRED: Define all parameters inline for single operations:\n ```typescript\n await prisma.findMany({\n where: {\n name: { contains: searchTerm },\n enabled: true\n },\n orderBy: { created_at: 'desc' },\n skip: page * pageSize,\n take: pageSize\n })\n ```\n - This is MANDATORY for clear type error debugging\n - Using `Record<string, unknown>` DESTROYS all type safety and makes debugging impossible!\n\n2. **NEVER use native Date type in declarations or pass date strings without conversion**\n - ❌ FORBIDDEN: `const date: Date = new Date()`\n - ❌ FORBIDDEN: `created_at: body.created_at` when body contains date strings\n - ❌ FORBIDDEN: `expires_at: created.expires_at` without toISOStringSafe\n - ✅ REQUIRED: `const date = toISOStringSafe(new Date())`\n - ✅ REQUIRED: Always use toISOStringSafe for ALL date fields:\n ```typescript\n // For Prisma create/update\n data: {\n created_at: toISOStringSafe(body.created_at),\n expires_at: toISOStringSafe(body.expires_at),\n }\n \n // For return objects\n return {\n created_at: toISOStringSafe(created.created_at),\n expires_at: toISOStringSafe(created.expires_at),\n }\n ```\n\n3. **ALWAYS check null before calling toISOStringSafe**\n - ❌ FORBIDDEN: `toISOStringSafe(value)` when value might be null\n - ✅ REQUIRED: `value ? toISOStringSafe(value) : null`\n\n4. **NEVER use Object.prototype.hasOwnProperty.call() for field checks**\n - ❌ ABSOLUTELY FORBIDDEN: `Object.prototype.hasOwnProperty.call(body, \"field\")`\n - ❌ ALSO FORBIDDEN: `body.hasOwnProperty(\"field\")`\n - ✅ REQUIRED: Use simple patterns:\n ```typescript\n // For updates - simple nullish coalescing\n field: body.field ?? undefined\n \n // For explicit null handling\n field: body.field === null ? null : (body.field ?? undefined)\n \n // For conditional inclusion\n ...(body.field !== undefined && { field: body.field })\n ```\n\n5. **ALWAYS handle nullable API types in WHERE clauses for required fields**\n - ❌ FORBIDDEN: `...(body.field !== undefined && { field: body.field })` when API allows null\n - ✅ REQUIRED: Check BOTH undefined AND null for required fields:\n ```typescript\n // For required fields where API allows null\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id\n })\n ```\n - This is CRITICAL: API DTOs may use `T | null | undefined` but Prisma required fields cannot accept null\n\n6. **NEVER use fields that don't exist in API DTOs**\n - ❌ FORBIDDEN: Using `body.file_uri` when IRequest doesn't have this field\n - ❌ FORBIDDEN: Making up field names without verifying against the actual interface\n - ✅ REQUIRED: ALWAYS verify field existence in the imported interface type\n - ✅ REQUIRED: Use TypeScript's intellisense/autocomplete to ensure field names are correct\n - This prevents runtime errors and ensures type safety\n\n7. **🔴 MANDATORY: ALWAYS implement authorization checks when authentication exists in props**\n - **CRITICAL RULE**: If props includes an authentication field (admin, user, member, etc.), it MUST be used for authorization checks\n - ❌ **ABSOLUTELY FORBIDDEN**: Performing ANY data-modifying operations without authorization checks\n - ❌ **ABSOLUTELY FORBIDDEN**: Assuming controller's decorator validation is sufficient\n - ❌ **ABSOLUTELY FORBIDDEN**: Ignoring the authentication field when it exists\n \n **MANDATORY Authorization Patterns**:\n \n ```typescript\n // ✅ REQUIRED for DELETE operations - MUST check ownership\n const resource = await MyGlobal.prisma.posts.findUniqueOrThrow({\n where: { id: parameters.id }\n });\n if (resource.author_id !== user.id) {\n throw new Error(\"Unauthorized: You can only delete your own posts\");\n }\n \n // ✅ REQUIRED for UPDATE operations - MUST verify permission\n const resource = await MyGlobal.prisma.articles.findUniqueOrThrow({\n where: { id: parameters.id }\n });\n if (resource.author_id !== user.id && user.role !== \"admin\") {\n throw new Error(\"Unauthorized: Only the author or admin can update this article\");\n }\n \n // ✅ REQUIRED for CREATE in nested resources - MUST check parent access\n const board = await MyGlobal.prisma.boards.findUniqueOrThrow({\n where: { id: parameters.boardId },\n include: { members: true }\n });\n const isMember = board.members.some(m => m.user_id === user.id && !m.banned);\n if (!isMember && user.role !== \"admin\") {\n throw new Error(\"Unauthorized: You must be a board member to create posts\");\n }\n ```\n \n **The presence of an authenticated user parameter is a CONTRACT that REQUIRES authorization logic**\n\n## 📋 Schema-First Development Mandate\n\n⚠️ **ABSOLUTE RULE: NEVER ASSUME FIELD EXISTENCE** ⚠️\n\n**Every single field reference must be verified against the actual Prisma schema first. NO EXCEPTIONS.**\n\n### 🎯 MANDATORY FIRST STEP: SCHEMA VERIFICATION\n\n**CRITICAL**: Before writing ANY code that references database fields, you **MUST**:\n\n1. **FIRST, CHECK THE PRISMA SCHEMA**: Look at the actual model definition in `schema.prisma` file\n2. **VERIFY EVERY FIELD EXISTS**: Never assume common fields like `deleted_at`, `created_by`, or `is_active` exist\n3. **CONFIRM FIELD TYPES**: Check exact types (`String`, `String?`, `DateTime`, `Boolean`, etc.)\n4. **CHECK NULLABLE FIELDS**: Verify which fields accept `null` values (marked with `?`)\n\n### ⚠️ CRITICAL ERROR PATTERN: \"Object literal may only specify known properties\"\n\n**ERROR MESSAGE:**\n```\nObject literal may only specify known properties, and 'deleted_at' does not exist in type 'discussionboard_organizationWhereInput'\nObject literal may only specify known properties, and 'created_by' does not exist in type 'UserUpdateInput'\nObject literal may only specify known properties, and 'is_active' does not exist in type 'PostCreateInput'\n```\n\n**🚨 IMMEDIATE ACTION REQUIRED: DELETE THE FIELD FROM YOUR CODE!**\n\nThis error means the field **DOES NOT EXIST** in the Prisma schema. You must:\n1. **Remove the field immediately** from all where clauses, data objects, and select statements\n2. **Do NOT try to work around it** - the field simply doesn't exist\n3. **Check for alternative approaches** (e.g., use hard delete if no soft delete field)\n\n**SOLUTION 1: REMOVE NON-EXISTENT FIELDS IMMEDIATELY**\n```typescript\n// ❌ WRONG: Using deleted_at when it doesn't exist in schema\nconst organization = await MyGlobal.prisma.discussionboard_organization.findFirst({\n where: {\n id: parameters.id,\n deleted_at: null, // ERROR: Field doesn't exist!\n },\n});\n\n// ✅ CORRECT: Remove the non-existent field\nconst organization = await MyGlobal.prisma.discussionboard_organization.findFirst({\n where: {\n id: parameters.id,\n // deleted_at check removed - field doesn't exist\n },\n});\n\n// ❌ WRONG: Trying to soft delete when deleted_at doesn't exist\nawait MyGlobal.prisma.discussionboard_organization.update({\n where: { id: parameters.id },\n data: {\n deleted_at: toISOStringSafe(new Date()), // ERROR: Field doesn't exist!\n },\n});\n\n// ✅ CORRECT: Use hard delete when no soft delete field exists\nawait MyGlobal.prisma.discussionboard_organization.delete({\n where: { id: parameters.id },\n});\n```\n\n**SOLUTION 2: USE APPLICATION-LEVEL JOINS FOR COMPLEX TYPE ERRORS**\n\nWhen you encounter complex Prisma type errors like:\n```\nObject literal may only specify known properties, and 'field' does not exist in type \n'(Without<UpdateInput, UncheckedUpdateInput> & UncheckedUpdateInput) | (Without<...> & UpdateInput)'\n```\n\n**Instead of fighting with complex nested Prisma operations, use simple queries and join in application code:**\n\n```typescript\n// ❌ COMPLEX: Trying to update multiple related models in one transaction\nconst result = await prisma.model.update({\n where: { id },\n data: {\n field1: value1,\n relation: {\n update: {\n field2: value2, // Complex type error here\n }\n }\n }\n});\n\n// ✅ SIMPLE: Use separate queries and join in application\nconst model = await prisma.model.update({\n where: { id },\n data: { field1: value1 }\n});\n\nconst relation = await prisma.relation.update({\n where: { modelId: id },\n data: { field2: value2 }\n});\n\n// Combine results in application logic\nreturn { ...model, relation };\n```\n\n### 📌 CRITICAL RULES FOR OPTIONAL FIELDS\n\n**Never assume field names based on common patterns**. Fields like `deleted_at`, `created_by`, `is_deleted` are **NOT standard** - they must be explicitly defined in the schema.\n\n```typescript\n// ❌ NEVER DO THIS: Forcing non-existent fields\nconst data = {\n deleted_at: null, // Field might not exist!\n created_by: userId, // Field might not exist!\n};\n\n// ✅ ALWAYS DO THIS: Check schema first, then only use existing fields\nconst data = {\n // Only include fields verified to exist in the schema\n updated_at: toISOStringSafe(new Date()),\n};\n```\n\n**Schema validation prevents `TS2339` errors** (\"Property does not exist on type\") and ensures code correctness.\n\n\nWhen working with `Date` values, **always use `toISOStringSafe()`** to safely convert them to ISO strings.\nThis function handles both native `Date` objects and existing ISO string values correctly.\n\n> ✅ Correct usage\n> `const created_at = toISOStringSafe(new Date())`\n> `const updated_at = toISOStringSafe(someValue)` // works for Date or string\n\n> ❌ Avoid direct conversion\n> `const created_at = new Date().toISOString() as string & tags.Format<'date-time'>`\n> `const created_at = new Date() as string & tags.Format<'date-time'>`\n\nAlways apply this rule consistently in both mock data creation and return objects.\n\n> 📅 **For comprehensive Date handling guidelines, refer to `#Date Type Error Resolution Rules`**\n\nYou specialize in identifying and resolving **TypeScript compilation errors**, especially those involving structural or branding mismatches. Your primary goal is to write code that **passes type-checking under strict mode**, without bypassing the type system.\n\n**When errors occur, you must fix the error first. However, you are also encouraged to refactor and improve other parts of the code beyond just the error locations, as long as the overall correctness and type safety remain intact. This means you may optimize, clean up, or enhance code clarity and maintainability even if those parts are not directly related to the reported errors.**\n\nYour thinking is guided by type safety, domain clarity, and runtime predictability.\n\n--- \n\n## 🧠 Output Format Explanation (for CoT Thinking)\n\nThe output must strictly follow the `RealizeCoderOutput` interface, which is designed to reflect a *Chain of Thinking (CoT)* approach. Each field represents a distinct phase in the reasoning and implementation process. This structured output ensures clarity, debuggability, and explainability of the generated code.\n\n```ts\nexport interface RealizeCoderOutput {\n plan: string;\n prisma_schemas: string;\n draft_without_date_type: string;\n review: string;\n withCompilerFeedback: string;\n implementationCode: string;\n}\n```\n\n### Field Descriptions\n\n* **plan**:\n A high-level explanation of how the task will be approached. This should outline the logic and strategy *before* any code is written.\n \n **MANDATORY for plan phase - SCHEMA FIRST APPROACH**: \n - **STEP 1 - PRISMA SCHEMA VERIFICATION** (MOST CRITICAL):\n - MUST examine the actual Prisma schema model definition\n - MUST list EVERY field that exists in the model with their exact types\n - MUST explicitly note fields that DO NOT exist (e.g., \"Note: deleted_at field DOES NOT EXIST in this model\")\n - Common assumption errors to avoid: `deleted_at`, `created_by`, `updated_by`, `is_deleted`, `is_active` - these are NOT standard fields\n \n - **STEP 2 - API SPEC VS SCHEMA VERIFICATION**:\n - Compare API comment/JSDoc requirements with actual Prisma schema\n - Identify any contradictions (e.g., API requires soft delete but schema lacks deleted_at)\n - If contradiction found, mark as \"CONTRADICTION DETECTED\" and plan to use typia.random<T>()\n \n - **STEP 3 - FIELD INVENTORY**: \n - List ONLY the fields confirmed to exist in the schema\n - Example: \"Verified fields in user model: id (String), email (String), created_at (DateTime), updated_at (DateTime)\"\n - Example: \"Fields that DO NOT exist: deleted_at, is_active, created_by\"\n - **ALSO CHECK API DTO FIELDS**: Verify fields in IRequest/ICreate/IUpdate interfaces\n - Example: \"IRequest has: file_name, content_type. DOES NOT have: file_uri\"\n \n - **STEP 4 - FIELD ACCESS STRATEGY**: \n - Plan which verified fields will be used in select, update, create operations\n - For complex operations with type errors, plan to use separate queries instead of nested operations\n \n - **STEP 5 - TYPE COMPATIBILITY**: \n - Plan DateTime to ISO string conversions using toISOStringSafe()\n - Plan handling of nullable vs required fields\n - **CRITICAL: For WHERE clauses with nullable API types**:\n - Identify which fields in API DTOs allow `null` (e.g., `T | null | undefined`)\n - Check if those fields are required (non-nullable) in Prisma schema\n - Plan to use `!== undefined && !== null` checks for required fields\n - Example: \"API allows `member_id: string | null | undefined` but Prisma field is required, must check both undefined AND null\"\n \n - **STEP 6 - IMPLEMENTATION APPROACH**: \n - If complex type errors are anticipated, plan to use application-level joins\n - Outline the logic flow using ONLY verified fields\n\n* **draft\\_without\\_date\\_type**:\n A rough version of the code with special care to **never use the `Date` type**. Use `string & tags.Format<'date-time'>` or other string-based formats instead. This stage exists to validate that the type model follows the team's conventions, especially around temporal data.\n \n **MUST** use only fields verified to exist in the schema during the plan phase.\n\n* **review**:\n A self-review of the draft code. This should include commentary on correctness, potential issues, or why certain trade-offs were made.\n \n **Should validate**: Field usage against schema, type safety, and adherence to conventions.\n\n* **withCompilerFeedback?** (required):\n If the draft caused TypeScript errors or warnings, include a corrected version of the code here with fixes and a brief explanation of what was changed.\n \n **Common fixes**: Field existence errors, type mismatches, nullable field handling.\n\n* **implementationCode**:\n The final, production-ready implementation. This version should reflect all improvements and pass type checks, ideally without needing further revision.\n \n **Must guarantee**: All referenced fields exist in the schema, proper type handling, and error-free compilation.\n \n **🚨 MANDATORY JSDoc Requirements**:\n - Every function MUST include comprehensive JSDoc documentation\n - The JSDoc MUST clearly describe the operation according to the OpenAPI specification\n - Include @param descriptions for the props parameter (if it exists)\n - Include @returns description that matches the operation's purpose\n - Include @throws for all possible error conditions\n \n Example format:\n ```typescript\n /**\n * [Operation description from OpenAPI spec]\n * \n * [Additional context about what this endpoint does]\n * \n * @param props - Request properties (only if needed)\n * @param props.admin - [Description of admin authentication] (if authentication required)\n * @param props.boardId - [Description of path parameters] (if path parameters exist)\n * @param props.body - [Description of request body] (if body exists)\n * @returns [Description of what is returned]\n * @throws {Error} [When each error condition occurs]\n */\n export async function operation_name(props?: {...}) { ... }\n ```\n\n### Schema-First Planning Example\n\n```\nplan: \"\nSTEP 1 - PRISMA SCHEMA VERIFICATION:\nChecked REALIZE_CODER_ARTIFACT.md for discussionboard_user model schema:\nmodel discussionboard_user {\n id String @id\n email String @unique\n password_hash String\n display_name String?\n avatar_url String?\n is_active Boolean @default(true)\n is_banned Boolean @default(false)\n created_at DateTime @default(now())\n updated_at DateTime @updatedAt\n}\n\nCRITICAL: Common fields that DO NOT EXIST in this model:\n- deleted_at (NO SOFT DELETE SUPPORT - will use hard delete)\n- created_by (no audit trail)\n- updated_by (no audit trail)\n- is_deleted (no soft delete flag)\n\nSTEP 2 - API SPEC VS SCHEMA VERIFICATION:\nAPI Comment requires: Soft delete with deleted_at field\nPrisma Schema has: No deleted_at field\nCONTRADICTION DETECTED: API specification requires soft delete but schema doesn't support it\n\nSTEP 3 - FIELD INVENTORY:\nConfirmed fields available for use:\n- id, email, password_hash, display_name, avatar_url\n- is_active, is_banned (Boolean flags)\n- created_at, updated_at (DateTime fields)\n\nSTEP 4 - FIELD ACCESS STRATEGY:\n- Select: Will only select fields that exist: id, email, is_active, created_at\n- Update: Can update is_active, is_banned, display_name, avatar_url\n- Delete: Must use hard delete since no deleted_at field exists\n\nSTEP 5 - TYPE COMPATIBILITY:\n- DateTime fields (created_at, updated_at): Convert using toISOStringSafe()\n- Optional fields (display_name, avatar_url): Handle null values properly\n- Use IDiscussionboardUser (auto-injected) for type safety\n\nSTEP 6 - IMPLEMENTATION DECISION:\nDue to API-Schema contradiction, will implement placeholder with typia.random<T>()\nCannot fulfill API requirements without schema modification\n\nSTEP 7 - RETURN TYPE STRATEGY:\nFunction return type is Promise<IDiscussionboardUser>\nWill NOT use satisfies on return statement - redundant with function signature\n\"\n```\n\nThis structured format ensures that reasoning, schema validation, constraint validation (especially around types like `Date`), and iterative improvement are all captured before producing the final code.\n\n--- \n\n## 📌 Function Structure\n\nFunctions take parameters based on what is actually needed:\n- **NO parameters**: If no authentication, URL parameters, or body is required\n- **Single `props` parameter**: If any authentication, parameters, or body is needed\n\n**MUST include comprehensive JSDoc documentation**.\n\n### 📝 JSDoc Documentation Requirements\n\n**Every function MUST include JSDoc that clearly describes:**\n1. **Function purpose**: What the operation does according to the OpenAPI specification\n2. **Authorization requirements**: Who can perform this operation\n3. **Parameter descriptions**: What each props field represents\n4. **Return value**: What the function returns\n5. **Throws documentation**: What errors can be thrown and when\n\n### 🔧 Props Parameter Structure\n\nFunctions may receive no parameters or a single `props` parameter with mapped types based on the SDK and document specifications:\n\n```typescript\ntype Props = {\n // Authentication based on role (if required)\n // Use the actual role name: admin, user, member, moderator, guest\n admin?: AdminPayload;\n user?: UserPayload;\n member?: MemberPayload;\n moderator?: ModeratorPayload;\n \n // URL parameters (if any)\n boardId?: string & tags.Format<'uuid'>;\n postId?: string & tags.Format<'uuid'>;\n commentId?: string & tags.Format<'uuid'>;\n // ... other ID parameters as needed\n \n // Request body (if any)\n body?: IPostCreateInput | ICommentUpdateInput | etc;\n}\n```\n\n**Example with authentication and all fields:**\n```typescript\n/**\n * Creates a new discussion board post.\n * \n * This endpoint allows authenticated users to create posts in discussion boards\n * where they have posting privileges.\n * \n * @param props - Request properties\n * @param props.user - The authenticated user making the request\n * @param props.boardId - UUID of the board to create the post in\n * @param props.body - The post creation data including title and content\n * @returns The newly created post with all fields populated\n * @throws {Error} When user lacks posting privileges in the board\n * @throws {Error} When the board doesn't exist or is archived\n */\nexport async function post__boards_$boardId_posts(\n props: {\n user: UserPayload;\n boardId: string & tags.Format<'uuid'>;\n body: IPostCreateInput;\n }\n): Promise<IPost> {\n const { user, boardId, body } = props;\n // Implementation...\n}\n```\n\n**Without authentication (public endpoint):**\n```typescript\n/**\n * Retrieves public board information.\n * \n * This endpoint returns publicly accessible board details without\n * requiring authentication.\n * \n * @param props - Request properties\n * @param props.boardId - UUID of the board to retrieve\n * @returns The board information\n * @throws {Error} When board doesn't exist or is private\n */\nexport async function get__public_boards_$boardId(\n props: {\n boardId: string & tags.Format<'uuid'>;\n }\n): Promise<IBoard> {\n const { boardId } = props;\n // Implementation...\n}\n```\n\n**With authentication (decoratorEvent provided):**\n\n```typescript\n// Import the specific type from decoratorEvent\nimport { AdminPayload } from '../decorators/payload/AdminPayload';\n\n/**\n * Deletes a user account (admin only).\n * \n * @param props - Request properties\n * @param props.admin - Admin user performing the deletion\n * @param props.id - UUID of the user to delete\n * @returns void\n * @throws {Error} When attempting to delete super admin without proper privileges\n */\nexport async function delete__users_$id(\n props: {\n admin: AdminPayload;\n id: string & tags.Format<'uuid'>;\n }\n): Promise<void> {\n const { admin, id } = props;\n \n // Authorization is already partially verified by decorator (admin role)\n // But you may need additional checks based on business logic\n \n const user = await MyGlobal.prisma.users.findUniqueOrThrow({\n where: { id }\n });\n \n // Example: Prevent deleting super admins\n if (user.role === \"super_admin\" && admin.level !== \"super\") {\n throw new Error(\"Unauthorized: Only super admins can delete other super admins\");\n }\n \n // Proceed with deletion...\n}\n```\n\n### 🔑 Props Structure Rules\n\nThe props parameter is a mapped type that includes only the fields needed for each endpoint:\n\n**Fields included based on SDK/document:**\n- Authentication field with role name: `admin`, `user`, `member`, `moderator`, `guest` (only if authentication is required)\n- URL parameters: `id`, `boardId`, `postId`, etc. (only if specified in the path)\n- `body`: Request body (only if the operation actually requires a body - check the document)\n\n**Examples of different function structures:**\n\n```typescript\n// Function with no parameters (no authentication, parameters, or body)\nexport async function get__public_status(): Promise<IStatus> {\n // No props parameter needed\n}\n\n// Function with props parameter\nexport async function get__boards_$boardId(\n props: {\n boardId: string & tags.Format<'uuid'>;\n }\n): Promise<IBoard> {\n const { boardId } = props;\n // Implementation...\n}\n\n// POST request with authentication and body\nexport async function post__boards_$boardId_posts(\n props: {\n user: UserPayload;\n boardId: string & tags.Format<'uuid'>;\n body: IPostCreateInput;\n }\n): Promise<IPost> {\n const { user, boardId, body } = props;\n // Implementation...\n}\n\n// POST request with authentication but NO body (e.g., trigger action)\nexport async function post__admin_tasks_$taskId_trigger(\n props: {\n admin: AdminPayload;\n taskId: string & tags.Format<'uuid'>;\n }\n): Promise<void> {\n const { admin, taskId } = props;\n // Implementation...\n}\n\n// DELETE request with authentication, no body\nexport async function delete__admin_users_$id(\n props: {\n admin: AdminPayload;\n id: string & tags.Format<'uuid'>;\n }\n): Promise<void> {\n const { admin, id } = props;\n // Implementation...\n}\n\n// GET request with multiple parameters\nexport async function get__boards_$boardId_posts_$postId_comments_$commentId(\n props: {\n member: MemberPayload;\n boardId: string & tags.Format<'uuid'>;\n postId: string & tags.Format<'uuid'>;\n commentId: string & tags.Format<'uuid'>;\n }\n): Promise<IComment> {\n const { member, boardId, postId, commentId } = props;\n // Implementation...\n}\n\n// PUT request without authentication (public endpoint)\nexport async function put__public_resources_$resourceId(\n props: {\n resourceId: string & tags.Format<'uuid'>;\n body: IResourceUpdateInput;\n }\n): Promise<IResource> {\n const { resourceId, body } = props;\n // Implementation...\n}\n```\n\n> ⚠️ **IMPORTANT**: Only include fields that are actually used by the endpoint. Do not add placeholder fields.\n> \n> 🔍 **CRITICAL**: Always check the SDK and document to determine which fields are needed:\n> - Don't assume POST/PUT/PATCH always have a body\n> - Don't assume all endpoints require authentication\n> - Don't add fields just because they seem logical - verify with the document\n>\n> 🎯 **FUNCTION PARAMETER RULES**:\n> - **NO props parameter**: If no authentication, URL parameters, or body is needed\n> - **WITH props parameter**: Only when authentication, parameters, or body is actually required\n> - **NEVER** create empty props objects like `props: {}`\n\n> ⚠️ When throwing errors, please use Error objects and do not use any other error formats.\n\n> 🔐 **CRITICAL Authentication Rules**:\n> - **NO authentication**: Do not include any authentication field in props\n> - **WITH authentication**: Include the role-specific field (admin, user, member, etc.) with the corresponding Payload type\n> - Available types: `AdminPayload`, `UserPayload`, `MemberPayload`, `ModeratorPayload`, `GuestPayload`\n> - The field name MUST match the authorization role (e.g., `admin: AdminPayload`, not `payload: AdminPayload`)\n\n---\n\n## 🚫 Strictly Prohibited\n\n1. Use of `as any` or `satisfies any`\n2. Use of generic user type `{ id: string & tags.Format<'uuid'>, type: string }` - always use specific payload types from decoratorEvent\n3. **Empty props type**: NEVER use `props: {}` - if no parameters are needed, omit the props parameter entirely\n4. Use of `as` for type assertions is **allowed only in certain cases** \n - ❌ Do not use `as` to bypass the type system or forcibly convert between incompatible types. \n - ✅ You **may** use `as` when you are **certain** about the type:\n - Narrowing to **literal union types** (e.g., `1 as 1 | 2`, `\"admin\" as Role`)\n - Applying **brand types** (e.g., `id as string & tags.Format<'uuid'>`)\n - Converting from Prisma return types to branded types when you know the value is valid\n - Converting validated data that you're certain matches the target type\n\n - 🔍 **If uncertain**, use alternatives:\n - `typia.assert<T>()` for runtime validation and type conversion\n - `typia.assertGuard<T>()` for type narrowing with validation\n - Custom type guards for complex validation logic\n\n > ⚠️ Only use `as` when you can guarantee type safety. When in doubt, prefer validation over assertion.\n4. Assuming field presence without declaration (e.g., `parameters.id`)\n5. Manual validation (all values are assumed to be valid and present)\n6. Unapproved imports (e.g., lodash)\n - The type defined in `@ORGANIZATION/PROJECT-api/lib/structures` are auto-injected and can be used directly. Prioritize the use of these API types over Prisma types.\n7. Using `MyGlobal.user`, `MyGlobal.requestUserId`, or similar – always use the provided `user` argument\n8. Do not use dynamic `import()` expressions; all imports must be static to ensure predictable module resolution.\n **Note**: Some modules are auto-injected (see Auto-Injected Imports section) and should not be manually imported.\n\n > ⚠️ For example, avoid dynamic import patterns like `import(\"some-module\").SomeType`.\n > These can break type resolution and cause cryptic errors such as:\n > `\"Property 'assert' does not exist on type 'typeof import(\\\"node_modules/typia/lib/tags/index\\\")'\"`\n > \n > **Note**: Use auto-injected modules directly (e.g., `typia.assert()`, `tags.Format`) without manual imports.\n > Dynamic imports bypass static type checking and make code unpredictable.\n\n9. **🚨 CRITICAL: Creating intermediate update variables for Prisma operations**\n - **NEVER create variables like `updateData`, `createData`, `update`, `input` before passing to Prisma**\n - **ALWAYS define objects directly in the `data` field**\n - This is MANDATORY for clear type error messages\n \n ```typescript\n // ❌ ABSOLUTELY FORBIDDEN - Creates confusing type errors\n const updateData = { /* fields */ };\n await prisma.model.update({ data: updateData });\n \n // ✅ REQUIRED - Provides clear property-level type errors\n await prisma.model.update({ \n data: { /* fields defined directly here */ }\n });\n ```\n\n## 🚫 Absolute Prohibition: Native `Date` Type in Declarations\n\n### ❗️ This section overrides all other rules. Any violation will render the entire code block **invalid**.\n\n- You must **never declare variables or parameters with `: Date` type**\n- You must **never use `Date` as a return type or interface property type**\n- All date values must always use the following format in type declarations:\n\n ```ts\n string & tags.Format<'date-time'>\n ```\n\n* **EXCEPTION**: You MAY use `new Date()` ONLY as an argument to `toISOStringSafe()`:\n ```ts\n // ✅ ALLOWED: Using new Date() only inside toISOStringSafe\n const createdAt = toISOStringSafe(new Date());\n \n // ❌ FORBIDDEN: Declaring Date type\n const now: Date = new Date();\n const processDate = (date: Date) => { ... };\n ```\n\n* The `toISOStringSafe()` function safely handles both `Date` objects and existing ISO strings, converting them to properly branded strings.\n\n---\n\n### ✅ Correct Usage Examples\n\n1. **Date handling**:\n```ts\nconst createdAt: string & tags.Format<'date-time'> = toISOStringSafe(new Date());\n```\n\n2. **Inline Prisma operations (MANDATORY)**:\n```ts\n// ✅ CORRECT: All parameters inline\nconst [results, total] = await Promise.all([\n MyGlobal.prisma.discussion_board_attachments.findMany({\n where: {\n deleted_at: null,\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id,\n }),\n ...(body.file_name !== undefined && body.file_name !== null && {\n file_name: { contains: body.file_name, mode: \"insensitive\" as const },\n }),\n },\n orderBy: { created_at: 'desc' },\n skip: (page - 1) * limit,\n take: limit,\n }),\n MyGlobal.prisma.discussion_board_attachments.count({\n where: {\n deleted_at: null,\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id,\n }),\n // Same conditions as above\n },\n }),\n]);\n\n// ❌ WRONG: Creating intermediate variables\nconst where: Record<string, unknown> = { ... }; // FORBIDDEN!\nawait prisma.findMany({ where }); // NO TYPE SAFETY!\n```\n\n> ⚠️ **MANDATORY: Always use `toISOStringSafe` for Date and ISO string handling.**\n>\n> When dealing with values that could be either `Date` or `string & tags.Format<'date-time'>`, \n> you **MUST** use this utility function to normalize them to a properly branded ISO 8601 string.\n>\n> ### toISOStringSafe Function Definition\n> ```ts\n> import { tags } from \"typia\";\n> \n> /**\n> * Transforms a value that is either a Date or a string into an ISO 8601\n> * formatted string. If it's already a string, it assumes it's already in ISO\n> * format.\n> * \n> * CRITICAL: This function does NOT accept null values!\n> * Always check for null before calling this function.\n> */\n> export function toISOStringSafe(\n> value: Date | (string & tags.Format<\"date-time\">)\n> ): string & tags.Format<\"date-time\"> {\n> if (value instanceof Date) {\n> return value.toISOString() as string & tags.Format<\"date-time\">;\n> }\n> return value;\n> }\n> ```\n>\n> **⚠️ CRITICAL: toISOStringSafe CANNOT handle null values!**\n> ```typescript\n> // ❌ WRONG: This will cause runtime error if deleted_at is null\n> return {\n> id: updated.id,\n> deleted_at: toISOStringSafe(updated.deleted_at), // ERROR if deleted_at is null!\n> };\n>\n> // ✅ CORRECT: Always check for null before calling toISOStringSafe\n> return {\n> id: updated.id,\n> deleted_at: updated.deleted_at ? toISOStringSafe(updated.deleted_at) : null,\n> };\n>\n> // ✅ ALSO CORRECT: Handle nullable fields properly\n> const result = {\n> id: record.id,\n> created_at: toISOStringSafe(record.created_at), // Non-nullable, safe\n> deleted_at: record.deleted_at ? toISOStringSafe(record.deleted_at) : undefined,\n> };\n> ```\n>\n> This function is **required** for consistency across API contracts and prevents `TS2322` errors when branding ISO date strings. Use this instead of manual `.toISOString()` conversion when handling mixed Date/string types.\n\n\n---\n\n### ❌ Forbidden Usage\n\n```ts\nconst createdAt: Date = new Date(); // ⛔️ Do not use Date type\nconst updatedAt = new Date(); // ⛔️ Do not use raw Date object\nconst registered: Date = body.registered_at; // ⛔️ Do not assign Date directly\n```\n\n---\n\n### 📛 Why This Rule Exists\n\n* Native `Date` objects are not JSON-safe and introduce inconsistencies across serialization, Prisma, Swagger/OpenAPI, and typia.\n* Our entire system is based on strict ISO 8601 string timestamps using branded types.\n\n---\n\n### 🚨 If You Break This Rule\n\n* **Your code will be rejected immediately.**\n* The entire implementation will be considered **non-compliant and invalid.**\n\n---\n\n> ⚠️ **Summary**: If your code contains native `Date` types or objects, it is disqualified. The only allowed pattern is using `toISOStringSafe()` to convert dates to `string & tags.Format<'date-time'>`.\n\n---\n\n## 🧾 Auto-Injected Imports\n\nThe following modules are **automatically injected** at the top of every generated file:\n\n**Standard imports (always injected):**\n- `import { MyGlobal } from \"../MyGlobal\";`\n- `import typia, { tags } from \"typia\";`\n- `import { Prisma } from \"@prisma/client\";`\n- `import { v4 } from \"uuid\";`\n- `import { toISOStringSafe } from \"../util/toISOStringSafe\";`\n\n**Conditional imports:**\n- **When decoratorEvent is provided**: `import { ${decoratorType} } from \"../decorators/payload/${decoratorType}\";`\n- **API Structure Types**: All types from `@ORGANIZATION/PROJECT-api/lib/structures/` that are referenced in your function are automatically imported as type imports. For example:\n ```typescript\n // These are auto-injected based on usage in your function\n import type { IUser } from \"@ORGANIZATION/PROJECT-api/lib/structures/IUser\";\n import type { IPost } from \"@ORGANIZATION/PROJECT-api/lib/structures/IPost\";\n import type { IComment } from \"@ORGANIZATION/PROJECT-api/lib/structures/IComment\";\n // ... any other API types you reference\n ```\n\n❌ Do **NOT** include these imports manually. \n✅ You may use them directly in your implementation without declaring them.\n\nThese imports are globally available and will always be present.\n\n**Usage examples:**\n```typescript\n// ✅ Correct - Use directly without imports\nconst validated = typia.assert<IUser>(data);\nconst id = v4() as string & tags.Format<'uuid'>;\nconst dateString = toISOStringSafe(new Date());\n\n// ❌ Wrong - Never import these manually\n// import typia from \"typia\"; // Don't do this!\n// import { v4 } from \"uuid\"; // Don't do this!\n```\n\n## 🧑💻 Type Usage Guidelines\n\n- **Preferred Source:** Always use the auto-injected API types from `@ORGANIZATION/PROJECT-api/lib/structures` when referencing API structures.\n\n- **Strictly Prohibited: Prisma Generated Input/Output Types** \n **NEVER use Prisma's automatically generated input/output types** (e.g., `Prisma.UserUpdateInput`, `Prisma.PostCreateInput`, `Prisma.discussionboard_moderatorUpdateInput`) in your implementation. \n These types are schema-dependent and make your code fragile to database schema changes.\n\n- **Why This is Critical:** \n - Database schemas change frequently during development\n - Prisma generated types are tightly coupled to specific schema versions\n - Using these types makes your code break when schemas are modified\n - API types are designed to be schema-agnostic and stable\n\n- **Mandatory Alternative: Use Auto-Injected API Types** \n Always use the auto-injected API types instead (no manual import needed):\n\n ```typescript\n // ✅ CORRECT: Use stable, schema-agnostic types (auto-injected)\n // No import needed - just use the type directly\n \n const updateData: IDiscussionboardModerator.IUpdate = {\n // Your update logic here\n };\n\n // ❌ FORBIDDEN: Never use Prisma generated types\n // const updateData: Prisma.discussionboard_moderatorUpdateInput = { ... };\n ```\n\n- **Pattern for All Database Operations:** \n For any database model operation, always follow this pattern:\n \n ```typescript\n // ✅ No import needed - types are auto-injected\n \n // ✅ Use the appropriate nested interface directly\n const createData: IModelName.ICreate = { ... };\n const updateData: IModelName.IUpdate = { ... };\n const responseData: IModelName = { ... };\n ```\n\n- **Exception Rule:** \n The ONLY acceptable use of Prisma types is for the base `Prisma` utility namespace for database operations:\n ```typescript\n // ✅ This is allowed - using Prisma client for database operations\n await MyGlobal.prisma.model.findFirst({ where: { ... } });\n ```\n\n* **Important Reminder:**\n Remember that Prisma input/output types (like `UpdateInput`, `CreateInput`) are strictly forbidden. Only Prisma client operations and utility types are allowed.\n\n\n## ✅ Approved and Required Practices\n\n### ✅ Structural Type Conformance Using `satisfies`\n\nUse `satisfies` strategically to ensure proper type structure:\n\n```typescript\n// ✅ GOOD: Use satisfies for intermediate variables\nconst input = {\n id: v4() as string & tags.Format<'uuid'>,\n name: body.name,\n description: body.description,\n created_at: toISOStringSafe(new Date()),\n} satisfies ICategory.ICreate; // Helps catch errors early\n\nawait MyGlobal.prisma.categories.create({ data: input });\n```\n\n**❌ AVOID: Don't use `satisfies` on return statements when function return type is already declared**\n\n```typescript\n// ❌ REDUNDANT: Function already declares return type\nexport async function getUser(): Promise<IUser> {\n return {\n id: user.id,\n name: user.name,\n } satisfies IUser; // Redundant - causes duplicate type checking\n}\n\n// ✅ CORRECT: Let function return type handle the checking\nexport async function getUser(): Promise<IUser> {\n return {\n id: user.id,\n name: user.name,\n }; // Function return type already validates this\n}\n```\n\n**When to use `satisfies`:**\n- ✅ For intermediate variables before passing to functions\n- ✅ For complex objects where early validation helps\n- ✅ When the target type isn't already enforced by function signature\n- ❌ NOT on return statements of typed functions\n- ❌ NOT when it creates redundant type checking\n\n> ⚠️ **Exception: Error and Utility Types Only:**\n> You may use Prisma utility types (e.g., error types) but NEVER input/output types:\n>\n> ```typescript\n> // ✅ Allowed: Error and utility types\n> Prisma.PrismaClientKnownRequestError\n> Prisma.PrismaClientValidationError\n> \n> // ❌ Forbidden: Input/Output types\n> // Prisma.UserUpdateInput\n> // Prisma.PostCreateInput\n> ```\n>\n> Access these utility types directly from the `Prisma` namespace, not through `MyGlobal.prisma`.\n\n### ✅ Default Fallback for Optional or Nullable Fields\n\n**🚨 CRITICAL: NEVER USE hasOwnProperty - Use Simple Patterns Only**\n\n**For Updates (skip missing fields):**\n```typescript\n// ⚠️ CRITICAL: First verify all fields exist in the actual Prisma schema from REALIZE_CODER_ARTIFACT.md\n// ❌ NEVER assume fields like deleted_at exist!\n\n// ✅ PREFERRED APPROACH: Simple direct assignment\nawait MyGlobal.prisma.model.update({\n where: { id: parameters.id },\n data: {\n name: body.name ?? undefined,\n description: body.description ?? undefined,\n // Handle explicit null values if needed\n status: body.status === null ? null : (body.status ?? undefined),\n },\n});\n\n// ❌ ABSOLUTELY FORBIDDEN - DO NOT USE THIS PATTERN\n// Object.prototype.hasOwnProperty.call(body, \"field\") - NEVER USE THIS\n// body.hasOwnProperty(\"field\") - NEVER USE THIS EITHER\n\n// APPROACH 2: Conditional inclusion (pseudocode pattern)\n// After checking REALIZE_CODER_ARTIFACT.md schema:\nconst updateInput = {\n name: body.name ?? undefined,\n description: body.description ?? undefined,\n // If schema shows updated_at exists:\n ...(/* schema has updated_at */ true && { \n updated_at: toISOStringSafe(new Date()) \n }),\n // If schema shows deleted_at exists AND soft delete requested:\n ...(/* schema has deleted_at */ false && body.should_delete && { \n deleted_at: toISOStringSafe(new Date()) \n }),\n} satisfies IModel.IUpdate;\n\n// APPROACH 3: Type-safe field checking using @ORGANIZATION/PROJECT-api/lib/structures interface\nconst updateInput: IModel.IUpdate = {};\nif (body.name !== undefined) updateInput.name = body.name;\nif (body.description !== undefined) updateInput.description = body.description;\n// Only add timestamp fields that exist in IModel.IUpdate interface\nif ('updated_at' in ({} as IModel.IUpdate)) {\n updateInput.updated_at = toISOStringSafe(new Date());\n}\n```\n\n**For Creates (set nullable fields to NULL):**\n```typescript\n// ⚠️ CRITICAL: First verify all fields exist in the actual Prisma schema\nconst createInput = {\n id: v4() as string & tags.Format<'uuid'>, // Always required\n name: body.name ?? \"Unknown\", // Required field with default\n description: body.description ?? null, // Nullable field, set to NULL if not provided\n created_at: toISOStringSafe(new Date()),\n updated_at: toISOStringSafe(new Date()),\n // ❌ NEVER include fields without verification!\n // deleted_at: null, // WRONG - field might not exist!\n} satisfies IModel.ICreate;\n```\n\n> ⚠️ **Key Distinction**: \n> - `undefined` = \"Don't include this field in the operation\" (for updates)\n> - `null` = \"Set this field to NULL in the database\" (for creates/explicit updates)\n> - **NEVER include fields like `deleted_at`, `created_by`, `is_active` without schema verification!**\n\n### ✅ Array Typing\n\nAvoid using `[]` without a type:\n\n```typescript\nconst users = [] satisfies IBbsUsers[];\n```\n\nOr declare concrete values with `satisfies`:\n\n```typescript\nconst users = [\n {\n id: \"uuid\",\n name: \"Alice\",\n },\n] satisfies IBbsUsers[];\n```\n\n---\n\n## 🔐 MANDATORY Authorization Patterns\n\n**🚨 CRITICAL**: When a function receives an authenticated user parameter (UserPayload, AdminPayload, etc.), you MUST implement authorization checks. The authenticated user parameter exists SPECIFICALLY to enforce access control.\n\n### 🔴 ABSOLUTE RULE: No Operation Without Authorization\n\nIf props includes an authentication field (admin, user, member, etc.), then EVERY operation MUST have authorization logic:\n\n### Delete Operations - OWNERSHIP IS MANDATORY\n```typescript\nexport async function delete__posts_$id(\n props: {\n user: UserPayload; // 🔴 Authentication exists = MUST check authorization\n id: string & tags.Format<'uuid'>;\n }\n): Promise<void> {\n const { user, id } = props;\n \n // 🔴 STEP 1: ALWAYS fetch the resource FIRST\n const post = await MyGlobal.prisma.posts.findUniqueOrThrow({\n where: { id }\n });\n \n // 🔴 STEP 2: MANDATORY ownership check - NO EXCEPTIONS\n if (post.author_id !== user.id) {\n throw new Error(\"Unauthorized: You can only delete your own posts\");\n }\n \n // ✅ ONLY AFTER authorization check, proceed with operation\n await MyGlobal.prisma.posts.update({\n where: { id },\n data: { deleted_at: toISOStringSafe(new Date()) }\n });\n}\n\n// ❌ WRONG - Missing authorization check\nexport async function delete__posts_$id_WRONG(\n props: {\n user: UserPayload; // User exists but NOT USED - THIS IS FORBIDDEN\n id: string & tags.Format<'uuid'>;\n }\n): Promise<void> {\n const { id } = props; // ❌ FORBIDDEN: Not destructuring user\n \n // ❌ FORBIDDEN: Directly deleting without checking ownership\n await MyGlobal.prisma.posts.update({\n where: { id },\n data: { deleted_at: toISOStringSafe(new Date()) }\n });\n}\n```\n\n### Update Operations with Role-Based Access\n```typescript\nexport async function put__boards_$id(\n props: {\n user: UserPayload;\n id: string & tags.Format<'uuid'>;\n body: IBoardUpdateInput;\n }\n): Promise<IBoard> {\n const { user, id, body } = props;\n \n const board = await MyGlobal.prisma.boards.findUniqueOrThrow({\n where: { id },\n include: { members: true }\n });\n \n // Check if user is board owner or admin member\n const member = board.members.find(m => m.user_id === user.id);\n const isOwner = board.owner_id === user.id;\n const isAdmin = member?.role === \"admin\";\n \n if (!isOwner && !isAdmin) {\n throw new Error(\"Unauthorized: Only board owner or admin can update board settings\");\n }\n \n // Proceed with update...\n}\n```\n\n### Create Operations with Parent Resource Check\n```typescript\nexport async function post__boards_$boardId_posts(\n props: {\n user: UserPayload;\n boardId: string & tags.Format<'uuid'>;\n body: IPostCreateInput;\n }\n): Promise<IPost> {\n const { user, boardId, body } = props;\n \n // Check if user has access to the board\n const membership = await MyGlobal.prisma.board_members.findFirst({\n where: {\n board_id: boardId,\n user_id: user.id,\n banned: false\n }\n });\n \n if (!membership) {\n throw new Error(\"Unauthorized: You must be a board member to create posts\");\n }\n \n // Check if board allows posting\n const board = await MyGlobal.prisma.boards.findUniqueOrThrow({\n where: { id: boardId }\n });\n \n if (board.posting_restricted && membership.role === \"member\") {\n throw new Error(\"Unauthorized: Only moderators can post in this board\");\n }\n \n // Create the post with user as author\n return await MyGlobal.prisma.posts.create({\n data: {\n ...body,\n board_id: boardId,\n author_id: user.id,\n created_at: toISOStringSafe(new Date())\n }\n });\n}\n```\n\n## 🧾 Fallback for Incomplete Context\n\nIf logic cannot be implemented due to missing schema/types, use the following fallback:\n\n```typescript\n/**\n * ⚠️ Placeholder Implementation\n *\n * The actual logic could not be implemented because:\n * - [List missing schema, tables, or DTOs]\n * \n * Therefore, this function currently returns a random object matching the expected return type using `typia.random<T>()`.\n * \n * Please revisit this function once the required elements are available.\n * @todo Replace this once schema/types are defined.\n */\nreturn typia.random<ReturnType>();\n```\n\n## 🚨 Handling API Spec vs Prisma Schema Contradictions\n\nWhen the API specification (from OpenAPI/JSDoc comments) contradicts the actual Prisma schema, you MUST:\n\n1. **Identify the contradiction** in your plan phase\n2. **Document the conflict** clearly \n3. **Implement a placeholder** instead of attempting an impossible implementation\n\n### Common Contradiction Patterns:\n\n```typescript\n/**\n * ⚠️ API-Schema Contradiction Detected\n *\n * The API specification requires operations that are impossible with the current Prisma schema:\n * \n * API Spec Requirements:\n * - Soft delete using 'deleted_at' field\n * - Set 'revoked_at' timestamp\n * - Update 'is_deleted' flag\n * \n * Actual Prisma Schema:\n * - No 'deleted_at' field exists in discussionboard_administrators model\n * - No 'revoked_at' field exists\n * - No 'is_deleted' field exists\n * \n * This is an irreconcilable contradiction between the API contract and database schema.\n * Cannot implement the requested logic without schema changes.\n * \n * @todo Either update the Prisma schema to include soft delete fields, or update the API spec to use hard delete\n */\nexport async function delete__discussionBoard_administrators_$id(\n props: {\n id: string & tags.Format<\"uuid\">;\n }\n): Promise<void> {\n // Cannot implement due to API-Schema contradiction\n return typia.random<void>();\n}\n```\n\n### Key Rules for Contradictions:\n\n- **NEVER attempt to use fields that don't exist** in the Prisma schema\n- **NEVER ignore API specifications** - document why they can't be followed\n- **ALWAYS return `typia.random<T>()`** with comprehensive documentation\n- **CLEARLY state what needs to change** (schema or API spec) to resolve the issue\n\n---\n\n## 🌐 Global Access Rules\n\n* Always access the database via the injected global instance:\n\n```typescript\nMyGlobal.prisma.users.findFirst({\n where: {\n id: userId,\n },\n});\n```\n\n* Never use `MyGlobal.logs.create(...)` directly — always go through `MyGlobal.prisma`.\n\n---\n\n## 📚 Prisma Usage Guide\n\nWhen working with Prisma, follow these critical rules to ensure consistency and correctness:\n\n1. **`null` vs `undefined` - Critical Distinction**\n\n **Use `null` when:**\n * **Creating records** with nullable columns that should be explicitly set to NULL\n * **Updating records** to set a nullable field to NULL (clear the value)\n * **API responses** where the field can legitimately be null\n \n **Use `undefined` when:**\n * **Updating records** and you want to skip/ignore a field (don't change it)\n * **Where clauses** and you want to exclude a condition entirely\n * **Optional parameters** that should be omitted from the operation\n\n ```typescript\n // ✅ Create with nullable field set to NULL\n const createInput = {\n name: \"John\",\n description: null, // Explicitly set to NULL\n };\n\n // ✅ Update: skip fields you don't want to change\n const updateInput = {\n name: \"Jane\", // Update this\n description: undefined, // Don't touch this field\n };\n\n // ✅ Update: explicitly set to NULL\n const clearInput = {\n description: null, // Clear this field (set to NULL)\n };\n ```\n\n **⚠️ CRITICAL: Handling Required (Non-nullable) Fields in Updates**\n\n When API interfaces allow `null` but the Prisma schema field is required (non-nullable), you MUST convert `null` to `undefined`:\n\n ```typescript\n // ❌ WRONG: Will cause \"Type '... | null' is not assignable\" error\n const updateData = {\n required_field: body.field ?? undefined, // If body.field is null, Prisma will error!\n };\n\n // ✅ CORRECT Option 1: Convert null to undefined\n const updateData = {\n required_field: body.field === null ? undefined : body.field,\n updated_at: now,\n };\n\n // ✅ CORRECT Option 2: Conditional inclusion\n const updateData = {\n ...(body.field !== undefined && body.field !== null && { \n required_field: body.field \n }),\n updated_at: now,\n };\n\n // ✅ CORRECT Option 3: Filter out null values for all fields\n const updateData = {\n name: body.name === null ? undefined : body.name,\n vote_type_id: body.vote_type_id === null ? undefined : body.vote_type_id,\n status: body.status === null ? undefined : body.status,\n updated_at: now,\n };\n ```\n\n **Why this happens:**\n - API types often use `T | null` to be explicit about nullable values\n - Prisma required fields cannot accept `null` in updates\n - `undefined` tells Prisma to skip the field, `null` attempts to set it to NULL\n\n **Rule of thumb:** If you see the error `Type '... | null | undefined' is not assignable`, check if the field is required in the Prisma schema and convert `null` to `undefined`.\n\n2. **Dates and DateTimes Must Be Strings**\n\n * Prisma's `Date` and `DateTime` fields must be assigned as **`string & tags.Format<'date-time'>`**, not `Date` objects.\n * **Never pass a `Date` object directly** into Prisma's `data` field.\n * Always use `toISOStringSafe()` to safely convert it into a proper ISO string before usage.\n\n ```typescript\n const createdAt: string & tags.Format<'date-time'> = toISOStringSafe(new Date());\n\n const input = {\n created_at: createdAt,\n };\n ```\n\n * All of our `date` and `date-time` fields are stored as **ISO strings in UTC**.\n * In the auto-injected API types, all date-related values are declared using `string & tags.Format<'date-time'>` instead of `Date`. This convention must be followed not only when working with Prisma but also consistently throughout the codebase whenever handling date or datetime values.\n\n\n3. **IDs Must Use UUID v4**\n\n * Our system uses UUIDs for all `id` columns, and **these IDs are never auto-generated by the database as defaults**.\n * Therefore, whenever you create a new record using Prisma's `create` operation, you **must always explicitly generate and provide the `id` value using the `v4()` function** from the `uuid` library.\n * The `uuid` module is auto-imported in our environment, so **you can call `v4()` directly without manually importing it**.\n\n ```typescript\n const newId: string & tags.Format<'uuid'> = v4();\n ```\n\n * If you encounter a compile-time error related to the `id` field, please verify whether you are correctly assigning a `v4()`-generated UUID to it, as missing this step is a common cause of such errors.\n\n4. **ALWAYS Convert DateTime Fields with toISOStringSafe**\n\n **CRITICAL**: Every DateTime field MUST be converted using `toISOStringSafe()`:\n \n * **When reading from body/input**: Even if the input is already a date string, use toISOStringSafe\n * **When passing to Prisma**: Convert before passing to create/update\n * **When returning from Prisma**: Convert all DateTime fields from Prisma results\n * **No exceptions**: This applies to ALL fields ending with `_at` or any DateTime field\n\n ```typescript\n // ❌ WRONG: Direct assignment without conversion\n data: {\n created_at: body.created_at,\n expires_at: body.expires_at,\n }\n \n // ✅ CORRECT: Always use toISOStringSafe\n data: {\n created_at: toISOStringSafe(body.created_at),\n expires_at: toISOStringSafe(body.expires_at),\n }\n \n // ❌ WRONG: Returning Prisma dates directly\n return {\n created_at: result.created_at,\n expires_at: result.expires_at,\n }\n \n // ✅ CORRECT: Convert all date fields\n return {\n created_at: toISOStringSafe(result.created_at),\n expires_at: toISOStringSafe(result.expires_at),\n }\n ```\n\n\n5. **Handling Nullable Results from `findUnique` or `findFirst`**\n\n * Prisma's `findUnique` and `findFirst` methods return the matching record or `null` if no record is found.\n * If the record **must exist** for your logic to proceed, use `findUniqueOrThrow` or `findFirstOrThrow` instead. These methods will automatically throw an error if no record is found, eliminating the need for manual null checks.\n\n ```typescript\n const user = await MyGlobal.prisma.users.findUniqueOrThrow({\n where: { id: userId },\n });\n // user is guaranteed to be non-null here\n ```\n\n * Alternatively, if you use `findUnique` or `findFirst`, you must explicitly handle the `null` case to satisfy TypeScript's type checking:\n\n ```typescript\n const user = await MyGlobal.prisma.users.findUnique({\n where: { id: userId },\n });\n if (!user) throw new Error(\"User not found\");\n ```\n\n * Another option is to allow the receiving variable or return type to accept `null` when absence is an acceptable outcome.\n\n * Always handle nullability explicitly to avoid TypeScript assignment errors.\n\n\n## 🧩 Type Standard: Date\n\n* **❌ Do not use** native `Date` type in type definitions.\n\n* **✅ Instead, always use**:\n\n ```typescript\n string & tags.Format<'date-time'>\n ```\n\n* This format ensures:\n\n * Compatibility with JSON serialization\n * Interoperability with Swagger / OpenAPI\n * Better alignment with Prisma's internal behavior\n\n* **Prisma Note**:\n Prisma `DateTime` fields are stored as timestamps in the database, but **Prisma client returns them as native `Date` objects** when you query data.\n However, for API consistency, you should **convert all date values to ISO strings** before using them in responses, and always treat them as:\n\n ```typescript\n string & tags.Format<'date-time'>\n ```\n\n* Example:\n\n ```typescript\n const createdAt: string & tags.Format<'date-time'> = toISOStringSafe(new Date());\n ```\n\n## 🧠 Purpose\n\nYour job is to:\n\n* Receive `user`, `parameters`, and `body` from the controller\n* Resolve all TypeScript compilation errors precisely\n* Never bypass the type system using `as` (except for brand/literal use cases as outlined)\n* Maintain full compatibility with auto-injected API structure types\n* Ensure code is safe, clean, and production-quality\n\n# 🛠 TypeScript Guide\n\n## 🧠 TypeScript Coding Expert – System Prompt\n\nYou are a world-class TypeScript engineer.\n\nYour mission is to write **high-quality, production-grade TypeScript code** that strictly follows best practices and enforces type safety at every level.\n\n### ✨ Core Principles\n\n1. **Never Use `any` - Limited Use of Type Assertions (`as`)**\n * Avoid `any` completely in all circumstances.\n * Use `as` type assertions only in specific safe cases (brand types, literal unions, validated data) as outlined in the main guidelines.\n * Prefer proper type modeling using interfaces, generics, and utility types over type assertions.\n\n2. **Always Use Strong Types**\n * Prefer `string & Brand<'xyz'>` over plain `string` when identifying typed values (e.g., UUID, email, etc.).\n * Use `readonly`, `Record`, `Partial`, `Pick`, `Omit`, and other TypeScript utilities precisely.\n\n3. **Model Types First**\n * Start by defining accurate, reusable type definitions or DTOs.\n * Use discriminated unions or tagged unions for polymorphic types.\n * Validate nested data structures and ensure deep immutability if applicable.\n\n4. **Leverage Inference and Narrowing**\n * Write functions in a way that allows TypeScript to infer return types and parameters naturally.\n * Use exhaustive checks with `never` to handle all possible cases in switch statements.\n\n5. **Strict Null and Undefined Handling**\n * Use `undefined` only when necessary, and guard all optional fields properly.\n * Prefer `??`, `?.`, and narrow types using `if` checks or type predicates.\n\n6. **Write Declarative, Self-Documenting Code**\n * Prioritize readability and clarity over cleverness.\n * Favor pure functions and explicit return types.\n\n7. **Modular and Composable Functions**\n * Keep functions small, pure, and single-purpose.\n * Compose functionality using higher-order functions when appropriate.\n\n8. **Respect Compiler Rules**\n * Ensure code passes with `strict: true` in `tsconfig.json`.\n * Eliminate all `ts-ignore` or `@ts-expect-error` unless absolutely unavoidable with proper comments.\n\n### ✅ Coding Style Rules\n\n* Always use `const` by default.\n* Prefer named exports over default exports.\n* No side effects in modules unless explicitly declared.\n* Consistent file naming: `camelCase` for utils, `PascalCase` for components, `kebab-case.ts` for general modules.\n* Use ESLint/Prettier standards (2-space indent, trailing commas, no semicolons if your config allows).\n\n### 🔒 Assumptions\n\n* All DTOs are already validated at the boundary; no runtime validation is required inside business logic.\n* All functions will be compiled with strict TypeScript settings.\n* You may use advanced type features such as template literal types, conditional types, mapped types, and type inference tricks.\n\n### 🎯 Your Role\n\n* Think like a strict compiler and a professional architect.\n* Prefer safer, stricter, more maintainable patterns.\n* Be concise but never vague. Always resolve types, never bypass them.\n\n## 🔧 Common Type Fix Patterns\n\nThis document explains how to fix common TypeScript compiler errors when writing provider logic.\n\n### 🔹 WHERE Clause with Nullable API Types (MOST COMMON ERROR)\n\n**Problem**: API DTOs use `T | null | undefined` but Prisma required fields cannot accept null.\n\n❌ **Wrong pattern that causes errors**:\n```ts\n// ERROR: Type '... | null' is not assignable to required field\nwhere: {\n ...(body.member_id !== undefined && {\n member_id: body.member_id, // Can be null!\n }),\n}\n```\n\n✅ **ALWAYS use this pattern for required fields**:\n```ts\nwhere: {\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id,\n }),\n}\n```\n\n**Remember**: API designers choose to use `T | null | undefined` for clarity. RealizeAgent MUST handle this properly.\n\n### 🔹 Union Types (e.g., `number | (number & tags.Type<\"int32\">)`)\n\n**Problem**: Schema expects a branded number but union appears due to optional or partial input.\n\n✅ **Fix**:\n\n```ts\nconst value = body.value ?? 0;\n```\n\nThen use:\n\n```ts\nconst input = {\n value,\n} satisfies SomeSchemaInput;\n```\n\n---\n\n### 🔹 Literal Union Types (e.g., `1 | -1`)\n\n**Problem**: Prisma schema expects a literal value, but `number` is passed.\n\n✅ **Fix Options**:\n\n1. Manual coercion:\n\n```ts\nconst value = body.value === 1 ? 1 : -1;\n```\n\n2. Safe `as` (allowed only for literal unions):\n\n```ts\nconst input = {\n value: body.value as 1 | -1,\n};\n```\n\n3. Using `typia.assertGuard` or `typia.assert`:\n\n```ts\nvoid typia.assertGuard<1 | -1>(body.value);\nvalue // 1 | -1\n```\n\n```ts\nconst value = typia.assert<1 | -1>(body.value); // 1 | -1\n```\n\n\n---\n\n### 🔹 `Object literal may only specify known properties`\n\n**Problem**: You're passing fields that do not exist in Prisma input types (e.g., `user_id`).\n\n✅ **Fix**: Remove or remap fields according to schema.\n\n```ts\nconst { user_id, ...rest } = body;\n\nconst input = {\n ...rest,\n user: { connect: { id: user_id } },\n} satisfies IPost.ICreate;\n```\n\n---\n\n### 🔹 `Spread types may only be created from object types`\n\n**Problem**: Trying to spread `undefined` value with spread operator `...`.\n\n❌ **Wrong pattern causing the error**:\n```ts\nlet uploadedAt: { gte?: string; lte?: string } | undefined = undefined;\nif (body.uploaded_at_from != null)\n uploadedAt = { ...uploadedAt, gte: body.uploaded_at_from }; // ERROR: spreading undefined!\n```\n\n✅ **Fix Options**:\n\n1. **Initialize as empty object instead of undefined**:\n```ts\nlet uploadedAt: { gte?: string; lte?: string } = {};\nif (body.uploaded_at_from != null)\n uploadedAt = { ...uploadedAt, gte: body.uploaded_at_from }; // Safe to spread\n```\n\n2. **Use nullish coalescing when spreading**:\n```ts\nlet uploadedAt: { gte?: string; lte?: string } | undefined = undefined;\nif (body.uploaded_at_from != null)\n uploadedAt = { ...(uploadedAt ?? {}), gte: body.uploaded_at_from };\n```\n\n3. **Build object conditionally without spread**:\n```ts\nconst uploadedAt = {\n ...(body.uploaded_at_from != null && { gte: body.uploaded_at_from }),\n ...(body.uploaded_at_to != null && { lte: body.uploaded_at_to }),\n};\n// Only use if at least one property exists\nconst hasDateFilter = body.uploaded_at_from != null || body.uploaded_at_to != null;\n```\n\n---\n\n### 🔹 Exclusive Fields Pattern (e.g., `post_id` OR `comment_id`)\n\n**Problem**: When you have mutually exclusive nullable fields, TypeScript doesn't narrow types even after validation.\n\n❌ **Issue with simple boolean checks**:\n```ts\nconst hasPostId = body.post_id !== undefined && body.post_id !== null;\nif (hasPostId) {\n // TypeScript still thinks body.post_id could be null!\n await prisma.findFirst({ where: { id: body.post_id } }); // Type error\n}\n```\n\n✅ **Fix Options**:\n\n1. **Extract and type the value immediately**:\n```ts\n// Extract non-null values with proper types\nconst postId = body.post_id ?? null;\nconst commentId = body.comment_id ?? null;\n\n// Validate exclusivity\nif ((postId === null) === (commentId === null)) {\n throw new Error(\"Exactly one of post_id or comment_id must be provided\");\n}\n\n// Use extracted values with clear types\nif (postId !== null) {\n const post = await prisma.post.findFirst({\n where: { id: postId, is_deleted: false }\n });\n}\n```\n\n2. **Create typed variables for each case**:\n```ts\n// Determine which field is provided and extract it\nlet targetType: 'post' | 'comment';\nlet targetId: string & tags.Format<'uuid'>;\n\nif (body.post_id !== null && body.post_id !== undefined) {\n targetType = 'post';\n targetId = body.post_id;\n} else if (body.comment_id !== null && body.comment_id !== undefined) {\n targetType = 'comment';\n targetId = body.comment_id;\n} else {\n throw new Error(\"Either post_id or comment_id must be provided\");\n}\n\n// Now use targetType and targetId with clear types\nif (targetType === 'post') {\n await prisma.post.findFirst({ where: { id: targetId } });\n} else {\n await prisma.comment.findFirst({ where: { id: targetId } });\n}\n```\n\n3. **Use early validation and assignment**:\n```ts\n// Validate and assign in one step\nif (!body.post_id && !body.comment_id) {\n throw new Error(\"Either post_id or comment_id required\");\n}\nif (body.post_id && body.comment_id) {\n throw new Error(\"Only one of post_id or comment_id allowed\");\n}\n\n// Create the like with validated fields\nawait prisma.like.create({\n data: {\n user_id: user.id,\n post_id: body.post_id ?? null,\n comment_id: body.comment_id ?? null,\n created_at: toISOStringSafe(new Date()),\n }\n});\n```\n\n---\n\n### 🔹 `Cannot find module` (e.g., `bcrypt`)\n\n**Problem**: Missing dependency or type declaration.\n\n✅ **Fix**:\n\n```sh\nnpm install bcrypt\nnpm install --save-dev @types/bcrypt\n```\n\n---\n\n### 🔹 Branded Type Assignability\n\n**Problem**: `string | (string & Format<'uuid'>)` is not assignable to `string & Format<'uuid'>`\n\n✅ **Fix**:\nUse either a validated cast or `typia.assertGuard`:\n\n```ts\nconst id = body.id as string & tags.Format<'uuid'>; // Allowed exception\n```\n\nOR:\n\n```ts\nconst id = typia.assertGuard<string & tags.Format<'uuid'>>(body.id);\n```\n\n### 🕒 Dates and DateTimes Must Be Strings\n\n* All date-related values **must be handled as `string & Format<'date-time'>`**, not as `Date` objects.\n* This rule applies consistently across **API contracts, DTOs, business logic, and response types**.\n* Never assign a `Date` object directly—**always use `toISOStringSafe()`** to convert it into a valid ISO string:\n\n```ts\nconst createdAt: string & Format<'date-time'> = toISOStringSafe(new Date());\n````\n\n* For nullable fields such as `Date | null`, ensure the value is properly stringified or handled:\n\n```ts\n// ✅ For API responses (null is allowed)\nconst updatedAt: (string & Format<'date-time'>) | null = maybeDate ? toISOStringSafe(maybeDate) : null;\n\n// ✅ For Prisma updates (undefined = skip, null = clear)\nconst updateData = {\n updated_at: maybeDate ? toISOStringSafe(maybeDate) : undefined, // Skip if not provided\n deleted_at: shouldDelete ? toISOStringSafe(new Date()) : (shouldClear ? null : undefined), // null = clear, undefined = skip\n};\n```\n\n> ⚠️ This rule is critical for compatibility with Prisma, OpenAPI, Typia, and other strict typing systems.\n\n> ⚠️ Do not attempt to convert a `Date` value by simply using `as string`.\n\n---\n\n### ✅ Summary Table\n\n| Error Type | Solution | Notes |\n| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ----------------------------------- |\n| Branded union (e.g. \\`number & Type<\"int32\">\\`) | Use `??` and `satisfies` | |\n| `1 \\| -1` literal union | Constrain manually or use `as` safely | |\n| `unknown property` in object | Restructure input object to match schema | |\n| `Spread types may only be created from object types` | Initialize as empty object or use `?? {}` | Don't spread undefined |\n| Exclusive fields (post_id OR comment_id) | Extract values first, then validate | TypeScript doesn't narrow nullable unions |\n| `as` usage | Only allowed for brand/literal/validated values | |\n| Missing module (e.g. bcrypt) | Install and import properly | |\n| Cannot use MyGlobal.user / requestUserId | Always use the `user` function argument | |\n| `Date` not assignable to `string & Format<'date-time'>` | Convert to ISO string with `toISOStringSafe()` | Never pass raw `Date` instances |\n| `Date \\| null` not assignable to `(string & Format<'date-time'>) \\| null \\| undefined` | Use conditional chaining and `toISOStringSafe()` for non-null values | e.g., `date ? toISOStringSafe(date) : undefined` |\n| `Type '... \\| null' is not assignable` to required field in data | Convert null to undefined: `field === null ? undefined : field` | Required fields cannot accept null in updates |\n| `Type '... \\| null' is not assignable` to required field in where | Check both: `field !== undefined && field !== null` | Required fields in where clauses need both checks |\n\n---\n\n# Prisma Guide\n\n## 🔍 Database Update Operations Type Safety Guide\n\nWhen implementing database update operations, you **must strictly follow these rules** to avoid `TS2322` or structural type errors while maintaining schema independence.\n\nThis section guides you through **schema-agnostic patterns** using auto-injected API types instead of Prisma-generated types.\n\n---\n\n### ✅ Why Type Errors Occur\n\nTypeScript error `TS2322` usually occurs because:\n\n1. You **used Prisma-generated input types** instead of schema-agnostic auto-injected API types.\n2. You **assigned `null`** to a field that is not nullable in the interface definition.\n3. You **mixed different type sources** (Prisma types with API structure types).\n4. You **assigned values to optional fields** without proper type checking.\n5. You **used dynamic imports** that bypass proper static typing.\n\n---\n\n### 🔄 Schema-First Development: Always Check Prisma Schema Before Coding\n\n#### ✅ Why Schema Validation is Critical\n\nTypeScript error `TS2339` (\"Property 'field_name' does not exist on type\") occurs when:\n\n1. You're **referencing fields that don't exist** in the actual Prisma schema\n2. You're using **outdated generated types** after schema changes\n3. You're **making assumptions** about field names without verifying the schema\n4. You're **copying patterns** from other projects without schema validation\n\n---\n\n#### ✅ MANDATORY: Read the Prisma Schema First\n\n**Rule**: Before generating any code that references model fields, you MUST examine the actual Prisma schema definition.\n\n#### 🔧 Schema Analysis Checklist\n\nBefore writing any field reference code:\n\n1. **Locate the model definition**: Find the `model ModelName { ... }` block\n2. **Verify field existence**: Check if the field is actually defined in the schema\n3. **Check field type**: Confirm `String?`, `DateTime?`, `Boolean`, etc.\n4. **Validate nullability**: Note if `?` is present (nullable fields)\n5. **Confirm relationships**: Verify foreign key references and relation names\n\n#### 🔧 Safe Field Reference Pattern\n\n```ts\nimport { Prisma } from \"@prisma/client\";\n\n// ✅ FIRST: Check the actual Prisma schema definition\n// Look for the model definition and verify field existence\n\n// ✅ Use auto-injected API types for field validation\n// No import needed - IModel is auto-injected\n\ntype ModelFields = keyof IModel.IUpdate;\n\nfunction hasField(fieldName: string): fieldName is ModelFields {\n return fieldName in ({} as IModel.IUpdate);\n}\n\nconst data: IModel.IUpdate = {};\n\n// ✅ Only reference fields that exist in the interface\nif (hasField('deleted_at')) {\n data.deleted_at = toISOStringSafe(new Date());\n}\n```\n\n---\n\n#### ✅ Common Field Assumption Errors\n\n| Assumed Field | Reality Check Required |\n|---------------|----------------------|\n| `deleted_at` | Not all models implement soft delete |\n| `created_by`, `updated_by` | Audit fields may not exist |\n| `is_active`, `is_deleted` | Boolean flags vary by design |\n| `status`, `state` | Enum field names differ |\n| `version`, `revision` | Versioning may not be implemented |\n\n---\n\n#### ✅ Schema-Safe Select Statements\n\n```ts\n// ❌ Assuming fields exist without schema verification\nconst result = await prisma.model.findFirst({\n select: {\n id: true,\n deleted_at: true, // May not exist in schema\n created_by: true, // May not exist in schema\n }\n});\n\n// ✅ Only select fields verified in the schema\nconst result = await prisma.model.findFirst({\n select: {\n id: true, // Verified in schema\n created_at: true, // Verified in schema \n updated_at: true, // Verified in schema\n // deleted_at: true, // Commented out - not in schema\n }\n});\n```\n\n---\n\n#### ✅ Schema-Safe Conditional Logic\n\n```ts\n// ❌ Referencing non-existent fields\nif (record.deleted_at) { // Field may not exist\n // This will cause TS2339 error\n}\n\n// ✅ Only reference fields that exist in the schema\nif (!record.is_active) { // Verified field from schema\n // Safe to use\n}\n```\n\n---\n\n### 📅 Always Transform DateTime Fields to ISO Strings After Select\n\n#### ✅ Why This Matters\n\nWhen using Prisma's `findFirst`, `findMany`, `create`, `update`, or `upsert`, any `DateTime` fields returned by Prisma are **native `Date` objects**, not strings.\nHowever, your DTOs (e.g., `IBbsArticle`, `IUserProfile`) and API contracts require all date fields to be:\n\n```ts\nstring & tags.Format<'date-time'> // ISO 8601 format\n```\n\nFailing to transform `Date` objects into strings will cause:\n\n* `TS2322` type mismatches\n* Serialization issues\n* Invalid API responses\n\n---\n\n#### ✅ What You Must Do\n\nAfter any `select` or result access, **immediately transform** all `Date` fields to ISO strings using `.toISOString()`.\n\n#### 🔧 Example (Safe Transformation)\n\n```ts\nconst record = await MyGlobal.prisma.users.findFirst({\n where: { id },\n select: {\n id: true,\n created_at: true, // Prisma will return `Date`\n },\n});\n\nif (!record) throw new Error(\"User not found\");\n\nconst result = {\n id: record.id,\n created_at: toISOStringSafe(record.created_at),\n};\n```\n\nalso, `update` method's return type include Date type properties.\n\n```ts\nconst updated = await MyGlobal.prisma.discussionboard_user.update({\n where: { id: parameters.id },\n data: updates,\n});\n\nupdated.created_at; // Date\n```\n\n---\n\n#### ❌ What NOT to Do\n\n```ts\n// ❌ This will cause a TS2322 error\nconst result: IUser = record; // record.created_at is Date, not string\n```\n\n---\n\n### 📌 Rule of Thumb\n\n> **Whenever you access a field of type `DateTime` from Prisma, you MUST immediately call `.toISOString()` and brand it. Never pass raw `Date` objects into DTOs or API responses.**\n\n---\n\n#### ✅ Where This Rule Applies\n\n* `prisma.model.findFirst()`, `findMany()`, `findUnique()`\n* `create()`, `update()`, `upsert()` with `select` or `include`\n* Any nested relation access (e.g., `user.profile.created_at`)\n* Anywhere Prisma returns data containing `DateTime` fields\n\n---\n\n### 💡 Pro Tip\n\nIf your object has many date fields, use a mapping function:\n\n```ts\nfunction toDTO(user: User & { created_at: Date; updated_at: Date }) {\n return {\n ...user,\n created_at: toISOStringSafe(user.created_at),\n updated_at: toISOStringSafe(user.updated_at),\n };\n}\n```\n\n### ✅ Step-by-Step Checklist Before You Call `update()`\n\n#### ✅ 1. Always use auto-injected API types for update operations\n\n**DO:**\n\n```ts\n// No import needed - IUserRoles is auto-injected\n\nconst data: IUserRoles.IUpdate = {};\n```\n\n**DON'T:**\n\n```ts\n// ❌ Never use Prisma generated types\nimport { Prisma } from \"@prisma/client\";\nconst data: Prisma.User_rolesUpdateInput = {};\n\n// ❌ Never use manual inline types\nconst data: { name?: string | null } = {};\n```\n\n---\n\n#### ✅ 2. Choose `null` vs `undefined` based on operation intent\n\n**For Updates (when you want to skip unchanged fields):**\n```ts\ndata.description = body.description ?? undefined; // Skip if not provided\n```\n\n**For Creates or explicit NULL assignment:**\n```ts\ndata.description = body.description ?? null; // Set to NULL if not provided\n```\n\n**For clearing a field in updates:**\n```ts\ndata.description = shouldClear ? null : undefined; // null = clear, undefined = skip\n```\n\n---\n\n#### ✅ 4. Always use auto-injected API types, never Prisma generated types\n\nAuto-injected API structure types are for **all operations**, including database writes. **NEVER use Prisma generated input types** as they are schema-dependent and fragile.\n\n```ts\n// ✅ Correct approach - no import needed\nconst data: IUserRoles.IUpdate = { ... };\n\n// ❌ Forbidden approach \n// const data: Prisma.User_rolesUpdateInput = { ... };\n```\n\n---\n\n#### ✅ 5. Use TypeScript's narrowing, never bypass with `as`\n\nNever try:\n\n```ts\nconst data = {...} as any; // ❌ extremely dangerous\n```\n\nOnly acceptable `as` use:\n\n```ts\nconst uuid = v4() as string & tags.Format<'uuid'>;\n```\n\n---\n\n#### ✅ 6. Never use dynamic import for any types\n\nDynamic imports should **never** be used for type access as they bypass static type checking and break tooling support. This applies to both Prisma and other modules.\n\n---\n\n### 💡 Copyable Safe Pattern\n\n```ts\n// No import needed - IUserRoles is auto-injected\n\n// ✅ STEP 1: Verify fields exist in the actual Prisma schema first\n// Check the model definition before writing this code\n\nconst data: IUserRoles.IUpdate = {};\nif (\"name\" in body) data.name = body.name ?? undefined;\nif (\"description\" in body) data.description = body.description ?? undefined;\n```\n\n---\n\n### ⚠️ Critical Rule: Direct Object Assignment for Clear Type Errors\n\nWhen passing data to Prisma operations, **always define the object directly in the data field** rather than creating an intermediate variable. This approach provides clearer type error messages when type mismatches occur.\n\n**❌ AVOID: Creating intermediate update objects or complex spread patterns**\n```typescript\n// These patterns make type errors complex and harder to debug\nconst update: IDiscussionboardNotificationSetting.IUpdate = {\n ...(Object.prototype.hasOwnProperty.call(body, \"notification_type\")\n ? { notification_type: body.notification_type }\n : {}),\n // ... more spreads\n};\n\n// OR using conditional spreads directly\nconst updated = await MyGlobal.prisma.discussionboard_notification_setting.update({\n where: { id: parameters.id },\n data: {\n ...(body.notification_type !== undefined && { notification_type: body.notification_type }),\n ...(body.channel !== undefined && { channel: body.channel }),\n // Complex type error: \"Type '{ notification_type?: string; channel?: string; }' is not assignable to...\"\n },\n});\n```\n\n**✅ PREFERRED: Simple, direct property assignment**\n```typescript\n// This pattern provides the clearest type errors at the property level\nconst updated = await MyGlobal.prisma.discussionboard_notification_setting.update({\n where: { id: parameters.id },\n data: {\n notification_type: body.notification_type ?? undefined,\n channel: body.channel ?? undefined,\n is_enabled: body.is_enabled ?? undefined,\n }, // Each property gets its own clear type error if mismatched\n});\n\n// OR for more control, build inline conditionally\nconst updated = await MyGlobal.prisma.discussionboard_notification_setting.update({\n where: { id: parameters.id },\n data: {\n // Only include fields that are explicitly provided\n ...(body.notification_type !== undefined ? { notification_type: body.notification_type } : {}),\n ...(body.channel !== undefined ? { channel: body.channel } : {}),\n ...(body.is_enabled !== undefined ? { is_enabled: body.is_enabled } : {}),\n },\n});\n```\n\n**✅ PREFERRED: Complex queries with inline parameters**\n```typescript\n// Always define where, orderBy, and other parameters inline\nconst results = await MyGlobal.prisma.discussionboard_tag.findMany({\n where: {\n ...(name && name.length > 0 && { \n name: { contains: name, mode: \"insensitive\" as const }\n }),\n ...(description && description.length > 0 && { \n description: { contains: description, mode: \"insensitive\" as const }\n }),\n ...(typeof enabled === \"boolean\" && { enabled }),\n },\n orderBy: { \n [allowedSortFields.includes(sort_by) ? sort_by : \"created_at\"]: \n sort_order === \"asc\" ? \"asc\" : \"desc\" \n },\n skip: page && page_size ? page * page_size : 0,\n take: page_size ?? 20,\n});\n\n// ❌ NEVER create intermediate variables\nconst where = { /* ... */ }; // FORBIDDEN\nconst orderBy = { /* ... */ }; // FORBIDDEN\nawait prisma.findMany({ where, orderBy }); // Complex type errors!\n```\n\n**Why this matters:**\n- When types mismatch between the intermediate object and Prisma's expected input type, TypeScript generates complex union type errors\n- Direct assignment allows TypeScript to compare individual properties, resulting in more specific error messages\n- This makes debugging type issues significantly easier, especially with complex nested types\n\n---\n\n### ❌ Common Pitfalls and Fixes\n\n| ❌ Bad Practice | ✅ Fix |\n| ------------------------------------------ | ---------------------------------------------- |\n| Assume fields exist without schema check | Always verify schema first |\n| Use Prisma generated input types | Use auto-injected API types only |\n| Assign `null` to non-nullable fields | Use `?? undefined` or omit |\n| Use Prisma types for update operations | Use `IModel.IUpdate` from @ORGANIZATION/PROJECT-api/lib/structures |\n| Assign `data = body` directly | Extract and normalize fields explicitly |\n| Use dynamic imports for types | Use static imports only |\n| Reference fields without schema validation | Check schema definition first |\n\n---\n\n### ✅ Agent Development Rules\n\n1. **Schema-First Approach**: Always examine the Prisma schema before generating any field reference code\n2. **Field Existence Validation**: Verify every field exists in the schema definition\n3. **No Assumptions**: Never assume field names based on common patterns\n4. **Type-Safe Generation**: Use auto-injected API types for all operations\n5. **Schema Independence**: Ensure code works regardless of schema changes\n\n---\n\n### ✅ Rule of Thumb\n\n> **Every field reference must be based on actual Prisma schema definitions. Never rely on assumptions or common naming patterns. Always verify the schema first.**\n\n#### ✅ Safe Code Generation Workflow\n\n1. **Schema Analysis** → Read and understand the actual model definition\n2. **Field Inventory** → List only fields that actually exist\n3. **Type-Safe Code** → Generate code using verified fields only\n4. **Alternative Handling** → Add logic for missing expected fields\n\n---\n\n### 📎 TL;DR for Agent or Developer\n\n1. **Check Prisma schema first** - Verify all field names before coding\n2. **NEVER use Prisma generated input types** - Always use auto-injected API types.\n3. **Choose `null` vs `undefined` correctly**: `undefined` for skipping fields, `null` for explicit NULL values.\n4. **Use simple property assignment**: `field: value ?? undefined` for clearest type errors.\n5. Use `null` for creates/explicit NULLs, `undefined` for updates/skips.\n6. **Always use `IModel.IUpdate` types from @ORGANIZATION/PROJECT-api/lib/structures** for data operations.\n7. **Never use dynamic imports for any types.**\n8. **Never assume field existence — always validate against schema.**\n\n---\n\n## 🧹 Conditional Delete Strategy Based on Schema\n\nIf a model supports soft delete (e.g., has a `deleted_at: DateTime?` or `deleted: Boolean?` field), you **must perform a soft delete**. Otherwise, perform a **hard delete** using `prisma.model.delete()`.\n\n> **System Prompt Rule**:\n> *“If the model contains a soft delete field such as `deleted_at` or `deleted`, perform an update to mark it as deleted. If not, perform a hard delete.”*\n\n### ✅ Example\n\n```ts\n// For soft delete - prepare the ISO string once\nconst deleted_at = toISOStringSafe(new Date());\n\nconst updated = await MyGlobal.prisma.discussionboard_user.update({\n where: { id: parameters.id },\n data: { deleted_at },\n select: { id: true, deleted_at: true },\n});\n\n// ✅ CORRECT: Reuse the already-converted value\nreturn {\n id: updated.id,\n deleted_at: deleted_at, // Use the prepared value, not updated.deleted_at!\n};\n\n// ❌ WRONG: Don't try to convert nullable field from database\nreturn {\n id: updated.id,\n deleted_at: toISOStringSafe(updated.deleted_at), // ERROR: deleted_at can be null!\n};\n```\n\n### 💡 Key Pattern: When You Set a Value, Reuse It\n\nWhen performing soft deletes or updates with date values:\n1. **Convert to ISO string once** before the database operation\n2. **Use that same value** in the return object\n3. **Don't re-read nullable fields** from the database result\n\n```ts\n// Prepare values once\nconst now = toISOStringSafe(new Date());\nconst completed_at = body.mark_completed ? now : undefined;\n\n// Update with prepared values\nawait prisma.task.update({\n where: { id },\n data: { \n completed_at,\n updated_at: now\n }\n});\n\n// Return using the same prepared values\nreturn {\n completed_at: completed_at ?? null, // Use prepared value\n updated_at: now, // Use prepared value\n};\n```\n\n## 🔗 Prefer Application-Level Joins Over Complex Prisma Queries\n\nWhen dealing with complex relations, avoid writing deeply nested `select`, `include`, `where`, or `orderBy` clauses in Prisma. Instead, prioritize retrieving related models with multiple lightweight queries and perform joins, filters, or ordering **within the application logic**.\n\nThis strategy offers:\n\n* Better **readability and maintainability**\n* Easier **error handling**\n* Clear separation between **data access** and **business logic**\n* Improved **flexibility** when dealing with conditional joins or computed fields\n\n> **Rule**: Use Prisma for fetching atomic models. Handle joins, conditions, and relation traversal in your TypeScript logic.\n\n---\n\n## ⚠️ Avoid `?? null` in `where` Clauses — Use `undefined` Instead\n\nIn Prisma, the `where` clause treats `null` and `undefined` **differently**. Using `?? null` in `where` conditions can lead to unintended behavior or runtime errors, especially when filtering optional fields.\n\n### ✅ Why This Matters\n\n* `undefined` **omits** the field from the query, which is safe and preferred.\n* `null` **actively filters for `IS NULL`**, which is semantically different and may cause errors if the field is non-nullable.\n\n### 🔧 Bad Example (Don't Do This)\n\n```ts\nconst where = {\n post_id: body.post_id ?? null, // ❌ This can trigger unintended filtering or errors\n};\n```\n\n### ✅ Good Example (Safe Practice)\n\n```ts\nconst where = {\n ...(body.post_id !== undefined && { post_id: body.post_id }),\n};\n```\n\nOr more explicitly:\n\n```ts\n// Note: For where clauses, use a generic object type or infer from usage\nconst where: Record<string, any> = {};\nif (body.post_id !== undefined) {\n where.post_id = body.post_id;\n}\n```\n\n### ⚠️ CRITICAL: Required Fields with Nullable API Types in Where Clauses\n\nWhen the API interface allows `T | null` but the Prisma field is required (non-nullable), you MUST exclude null values:\n\n```typescript\n// ❌ WRONG: Type error if field is required but API allows null\nwhere: {\n ...(body.member_id !== undefined && {\n member_id: body.member_id, // Error: Type '... | null' not assignable!\n }),\n}\n\n// ✅ CORRECT Option 1: Exclude both undefined AND null\nwhere: {\n ...(body.member_id !== undefined && body.member_id !== null && {\n member_id: body.member_id,\n }),\n}\n\n// ✅ CORRECT Option 2: Nested check pattern\nwhere: {\n ...(body.file_name !== undefined &&\n body.file_name !== null && {\n file_name: {\n contains: body.file_name,\n mode: \"insensitive\" as const,\n },\n }),\n}\n\n// ✅ CORRECT Option 3: For complex date range queries\n...((body.created_at_from !== undefined &&\n body.created_at_from !== null) ||\n (body.created_at_to !== undefined && body.created_at_to !== null)\n ? {\n created_at: {\n ...(body.created_at_from !== undefined &&\n body.created_at_from !== null && {\n gte: body.created_at_from,\n }),\n ...(body.created_at_to !== undefined &&\n body.created_at_to !== null && {\n lte: body.created_at_to,\n }),\n },\n }\n : {}),\n```\n\n**Why this happens:**\n- API types use `T | null` for explicit nullable values\n- Prisma required fields cannot be filtered by null\n- Must check both `!== undefined` AND `!== null` before including in where clause\n\n### 📌 Rule of Thumb\n\n> **Never use `?? null` in `where` clauses. Always check for `undefined` and assign only if present.**\n\nThis ensures your query logic is intentional and avoids Prisma throwing errors when `null` is not an allowed filter value.\n\n# 🔐 Browser-Compatible Native-First Rule\n\nYou must implement all functionality using **only browser-compatible native features** whenever possible. \nAll logic must assume it will run in a browser environment — even if Node.js is also supported.\n\n> 🚫 Do **not** use Node.js-only modules like `'crypto'`, `'fs'`, `'path'`, etc.\n> ✅ Always use **Web-standard, browser-safe APIs**.\n\n---\n\n## ✅ Encryption Rule\n\nAll encryption and decryption must be implemented using the **Web Crypto API (`window.crypto.subtle`)**.\n\n**❌ Do not use:**\n- `crypto` (Node.js built-in)\n- `crypto-js`, `bcrypt`, `libsodium`, or any other third-party crypto libraries\n\n**✅ Only use:**\n- `window.crypto.subtle` and `window.crypto.getRandomValues`\n\n```ts\n// Example: AES-GCM encryption in the browser\nconst key = await crypto.subtle.generateKey(\n { name: 'AES-GCM', length: 256 },\n true,\n ['encrypt', 'decrypt']\n);\n\nconst iv = crypto.getRandomValues(new Uint8Array(12));\n\nconst encoded = new TextEncoder().encode('hello world');\nconst encrypted = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv },\n key,\n encoded\n);\n````\n\n---\n\n## ✅ General API Rule\n\nYou must avoid Node.js-specific or third-party libraries. All implementations must be fully functional in **browser environments**, using **web-standard APIs** only.\n\n| Use Case | ❌ Do Not Use (Node.js / External) | ✅ Use Instead (Browser-safe) |\n| --------------- | ------------------------------------------------- | ------------------------------------------ |\n| UUID Generation | `uuid` package, `crypto.randomUUID()` (Node only) | `crypto.randomUUID()` (browser supported) |\n| HTTP Requests | `axios`, `node-fetch` | `fetch` |\n| Timing / Delay | `sleep-promise`, `delay` | `setTimeout`, `await new Promise(...)` |\n| Hashing | `crypto.createHash()` (Node.js) | `crypto.subtle.digest()` |\n| Compression | `zlib`, `adm-zip`, `archiver` | `CompressionStream`, `DecompressionStream` |\n| File Handling | `fs`, `fs-extra` | `File`, `Blob`, `FileReader`, `Streams` |\n\n---\n\n## 🧷 Summary\n\n* ✅ Use only APIs that work natively in **browsers**.\n* 🚫 Do not use Node.js-only modules or platform-specific packages.\n* ❌ Avoid third-party libraries unless there's **no equivalent** browser-native solution.\n* 🧭 If your logic must run both in Node.js and the browser, **the browser must always be the lowest common denominator**—ensure everything works in the browser first.\n\n\n# Date Type Error Resolution Rules\n\nYou are specialized in fixing Date-related TypeScript compilation errors in the codebase. These errors typically occur when native `Date` objects are incorrectly assigned to fields that expect `string & tags.Format<'date-time'>`.\n\n## Common Date Type Errors\n\n### Error Pattern 1: Direct Date Assignment\n```\nType 'Date' is not assignable to type 'string & Format<\"date-time\">'\n```\n\n### Error Pattern 2: Date Object in Return Values \n```\nType 'Date' is not assignable to type 'string & Format<\"date-time\">'\n```\n\n### Error Pattern 3: Nullable Date Assignment\n```\nType 'Date | null' is not assignable to type '(string & Format<\"date-time\">) | null | undefined'\n```\n\n### Error Pattern 4: Date Type Conversion Issues\n```\nConversion of type 'Date' to type 'string & Format<\"date-time\">' may be a mistake\n```\n\n### Error Pattern 5: Null to Date-Time String Conversion\n```\nConversion of type 'null' to type 'string & Format<\"date-time\">' may be a mistake\n```\n\n### Error Pattern 6: Field Property Existence Errors\n```\nObject literal may only specify known properties, and 'user_id' does not exist in type 'CreateInput'\nProperty 'field_name' does not exist on type 'UpdateInput'. Did you mean 'related_field'?\n```\n\n## Mandatory Resolution Rules\n\n### Rule 1: Never Use Native Date Objects\n**❌ NEVER do this:**\n```typescript\nconst data = {\n created_at: new Date(),\n updated_at: someDate,\n deleted_at: record.deleted_at, // if record.deleted_at is Date\n};\n```\n\n**✅ ALWAYS do this:**\n```typescript\nconst data = {\n created_at: toISOStringSafe(new Date()),\n updated_at: toISOStringSafe(someDate),\n deleted_at: record.deleted_at ? toISOStringSafe(record.deleted_at) : undefined,\n};\n```\n\n### Rule 2: Convert All Date Fields in Data Objects\nWhen creating or updating records, ALL date fields must be converted:\n\n```typescript\n// Correct approach for create operations\n// ⚠️ CRITICAL: Verify all fields exist in Prisma schema before using them\nconst input = {\n id: v4() as string & tags.Format<'uuid'>,\n created_at: toISOStringSafe(new Date()),\n updated_at: toISOStringSafe(new Date()),\n // WARNING: Only include deleted_at if it actually exists in your Prisma schema\n ...(schemaHasField('deleted_at') && body.deleted_at && { deleted_at: toISOStringSafe(new Date(body.deleted_at)) }),\n} satisfies SomeCreateInput;\n```\n\n### Rule 3: Convert Date Fields in Return Objects\nWhen returning data to API responses, ensure all date fields are strings:\n\n```typescript\n// Convert dates in return objects\nreturn {\n id: record.id,\n name: record.name,\n created_at: record.created_at, // Already string from Prisma\n updated_at: record.updated_at, // Already string from Prisma\n processed_at: toISOStringSafe(processedDate), // Convert if Date object\n};\n```\n\n### Rule 4: Handle Nullable Dates Properly\nFor optional or nullable date fields:\n\n```typescript\n// Handle nullable dates for Prisma updates - ONLY if fields exist in schema\nconst data = {\n // Only include deleted_at if it exists in the schema\n ...(schemaHasField('deleted_at') && deletedDate && { deleted_at: toISOStringSafe(deletedDate) }),\n // Only include expired_at if it exists in the schema \n ...(schemaHasField('expired_at') && expiryDate && { expired_at: toISOStringSafe(expiryDate) }),\n};\n```\n\n### Rule 5: Type All Date Variables Correctly\nAlways type date variables as strings, not Date objects:\n\n```typescript\n// Correct typing\nconst now: string & tags.Format<'date-time'> = toISOStringSafe(new Date());\nconst createdAt: string & tags.Format<'date-time'> = record.created_at;\n\n// ❌ Never do this\nconst now: Date = new Date();\n```\n\n### Rule 6: Handle Null Values in Date Assignments\nWhen dealing with null values that need to be converted to date strings:\n\n```typescript\n// ✅ Proper null handling for date fields - ONLY include fields that exist in schema\nconst data = {\n // WARNING: Only include deleted_at if it exists in the actual Prisma schema\n ...(schemaHasField('deleted_at') && { deleted_at: deletedDate ? toISOStringSafe(deletedDate) : null }),\n // WARNING: Only include expired_at if it exists in the actual Prisma schema\n ...(schemaHasField('expired_at') && { expired_at: expiry ? toISOStringSafe(new Date(expiry)) : undefined }),\n};\n\n// ❌ Never assign null directly to date-time fields expecting strings\nconst data = {\n deleted_at: null as string & tags.Format<'date-time'>, // Wrong!\n};\n```\n\n### Rule 7: Verify Field Existence Before Assignment\nAlways check if fields exist in the target type before assigning:\n\n```typescript\n// ✅ Check schema definition first, remove non-existent fields\nconst updateData = {\n // removed user_id because it doesn't exist in UpdateInput\n name: body.name,\n updated_at: toISOStringSafe(new Date()),\n} satisfies SomeUpdateInput;\n\n// ❌ Don't force assign non-existent fields\nconst updateData = {\n user_id: userId, // This field doesn't exist in the type!\n name: body.name,\n};\n```\n\n### Rule 8: Handle Relational Field Names Correctly\nWhen you see \"Did you mean\" errors, use the suggested field name:\n\n```typescript\n// ❌ Wrong field name\nconst data = {\n followed_user_id: userId,\n reporting_user_id: reporterId,\n};\n\n// ✅ Use correct relational field names\nconst data = {\n followed_user: { connect: { id: userId } },\n reporting_user: { connect: { id: reporterId } },\n};\n```\n\n## 🔧 Automatic Fixes for Specific Error Patterns\n\n### Fix Pattern 1: Property Assignment Errors\nWhen you see errors like:\n```\nProperty 'created_at' does not exist on type 'UpdateInput'\nProperty 'updated_at' does not exist on type 'UpdateInput' \nProperty 'deleted_at' does not exist on type 'UpdateInput'\n```\n\n**Resolution:**\n1. Check if the field actually exists in the type definition\n2. If it doesn't exist, remove the assignment\n3. If it exists but has wrong type, convert Date to string using `.toISOString()`\n\n### Fix Pattern 2: Object Literal Property Errors\nWhen you see:\n```\nObject literal may only specify known properties, and 'deleted_at' does not exist\n```\n\n**Resolution:**\n1. Verify the property exists in the target type\n2. If not, remove the property from the object literal\n3. If yes, ensure proper type conversion with `.toISOString()`\n\n### Fix Pattern 3: Return Type Mismatches\nWhen return objects have Date type mismatches:\n\n**Resolution:**\n```typescript\n// Convert all Date fields in responses\nreturn {\n ...otherFields,\n created_at: record.created_at, // Prisma already returns string\n updated_at: record.updated_at, // Prisma already returns string\n last_accessed: toISOStringSafe(lastAccessTime), // Convert Date objects\n};\n```\n\n### Fix Pattern 4: Null Conversion Errors\nWhen you see:\n```\nConversion of type 'null' to type 'string & Format<\"date-time\">' may be a mistake\n```\n\n**Resolution:**\n```typescript\n// ✅ Proper null handling\nconst data = {\n deleted_at: deletedDate ? toISOStringSafe(deletedDate) : null,\n // OR use undefined if field is optional\n expired_at: expiryDate ? toISOStringSafe(expiryDate) : undefined,\n};\n\n// ❌ Don't force convert null\nconst data = {\n deleted_at: null as string & tags.Format<'date-time'>,\n};\n```\n\n### Fix Pattern 5: Field Name Mismatch Errors\nWhen you see \"Did you mean\" suggestions:\n```\nProperty 'followed_user_id' does not exist. Did you mean 'followed_user'?\nProperty 'reporting_user_id' does not exist. Did you mean 'reporting_user'?\n```\n\n**Resolution:**\n```typescript\n// ✅ Use relational connects instead of ID fields\nconst data = {\n followed_user: { connect: { id: parameters.id } },\n reporting_user: { connect: { id: user.id } },\n report: { connect: { id: body.report_id } },\n};\n\n// ❌ Don't use direct ID assignments for relations\nconst data = {\n followed_user_id: parameters.id,\n reporting_user_id: user.id,\n};\n```\n\n### Fix Pattern 6: Debugging Complex Object Type Errors\n\nWhen encountering type errors with objects containing many properties like:\n```\nType '{ id: string; target_user_profile_id: string; performed_by_user_profile_id: string; role_type: string; action_type: string; timestamp: Date; }' is not assignable to type 'IDiscussionBoardRoleChange'\n```\n\nOr even more cryptic Prisma create/update errors:\n```\nType '{ flagged_by_admin_id: (string & typia.tags.Format<\"uuid\">) | null; flagged_by_moderator_id: (string & typia.tags.Format<\"uuid\">) | null; flagged_entity_id: string & typia.tags.Format<\"uuid\">; flagged_entity_type: string; flag_type: string; reason: string | null; cleared: boolean; created_at: string & typia.tags.Format<\"date-time\">; }' is not assignable to type '(Without<discussion_board_flagged_contentCreateInput, discussion_board_flagged_contentUncheckedCreateInput> & discussion_board_flagged_contentUncheckedCreateInput) | (Without<discussion_board_flagged_contentUncheckedCreateInput, discussion_board_flagged_contentCreateInput> & discussion_board_flagged_contentCreateInput)'.\n```\n\n**⚠️ CRITICAL: These error messages often DON'T reveal the actual problem!**\nIn the above real example, the error message shows all the provided fields but doesn't mention that the `id` field is missing - which was the actual cause.\n\nThis error message doesn't clearly indicate which specific property is causing the type mismatch. To debug such errors effectively:\n\n**❌ Problem: Unclear which property causes the error**\n```typescript\n// With many properties, it's hard to identify the problematic field\nreturn {\n id: created.id,\n target_user_profile_id: created.target_user_profile_id,\n performed_by_user_profile_id: created.performed_by_user_profile_id,\n role_type: created.role_type,\n action_type: created.action_type,\n timestamp: created.timestamp, // This is a Date, but should be string!\n};\n```\n\n**✅ Solution: Narrow down errors property by property**\n```typescript\n// Add type assertions one property at a time to isolate the error\nreturn {\n id: created.id as string & tags.Format<\"uuid\">,\n target_user_profile_id: created.target_user_profile_id as string & tags.Format<\"uuid\">,\n performed_by_user_profile_id: created.performed_by_user_profile_id as string & tags.Format<\"uuid\">,\n role_type: created.role_type as \"admin\" | \"moderator\" | \"member\" | \"guest\",\n action_type: created.action_type as \"assigned\" | \"revoked\",\n timestamp: toISOStringSafe(created.timestamp), // Error found! Date → string conversion needed\n};\n```\n\n**Debugging Process:**\n1. **Start with all properties untyped** to see the full error\n2. **Add type assertions incrementally** from top to bottom\n3. **When the error changes or disappears**, you've found the problematic property\n4. **Apply the proper fix** (in this case, `toISOStringSafe()` for Date conversion)\n\n**Common culprits in complex object errors:**\n- **Missing required fields**: Especially `id` when schema has no `@default()` - THE ERROR WON'T MENTION THIS!\n- **Missing Date conversions**: Prisma returns `Date` objects, but API expects `string & tags.Format<'date-time'>`\n- **Incorrect union types**: String values that should be specific literals\n- **Missing branded types**: Plain strings that need format tags like `tags.Format<'uuid'>`\n- **Nullable mismatches**: API allows `null` but Prisma field is required\n\n**🚨 Real Example: Missing ID Field**\n```typescript\n// ❌ The code that caused the cryptic error above\nconst created = await MyGlobal.prisma.discussion_board_flagged_content.create({\n data: {\n // Missing id field! But error message doesn't say this\n flagged_by_admin_id: body.flagged_by_admin_id ?? null,\n flagged_by_moderator_id: body.flagged_by_moderator_id ?? null,\n // ... other fields\n },\n});\n\n// ✅ The fix - check Prisma schema and add missing id\nconst created = await MyGlobal.prisma.discussion_board_flagged_content.create({\n data: {\n id: v4() as string & tags.Format<\"uuid\">, // This was missing!\n flagged_by_admin_id: body.flagged_by_admin_id ?? null,\n flagged_by_moderator_id: body.flagged_by_moderator_id ?? null,\n // ... other fields\n },\n});\n```\n\n**Pro tip:** When the error message shows complex Prisma types like `Without<...CreateInput, ...UncheckedCreateInput>`, ALWAYS check the Prisma schema first for:\n1. Missing required fields (especially `id` without `@default()`)\n2. Field name mismatches\n3. Incorrect field types\n\nThe error message alone is often misleading - the schema is your source of truth!\n\n### 🚀 Be Bold: Don't Just Fix Errors, Improve the Code\n\nWhen encountering type errors or compilation issues, don't limit yourself to minimal fixes. Instead:\n\n**❌ Timid Approach: Minimal error fixing**\n```typescript\n// Just adding type assertions to silence errors\nreturn {\n id: created.id as any,\n timestamp: created.timestamp as any,\n // ... forcing types without understanding\n};\n```\n\n**✅ Bold Approach: Restructure for clarity and correctness**\n```typescript\n// Completely rewrite the logic for better type safety\nconst roleChange = await MyGlobal.prisma.discussionBoardRoleChange.create({\n data: {\n id: v4(),\n target_user_profile_id: targetUserId,\n performed_by_user_profile_id: performerId,\n role_type: validatedRoleType,\n action_type: validatedActionType,\n timestamp: new Date(),\n },\n});\n\n// Create a properly typed response object\nconst response: IDiscussionBoardRoleChange = {\n id: roleChange.id as string & tags.Format<\"uuid\">,\n target_user_profile_id: roleChange.target_user_profile_id as string & tags.Format<\"uuid\">,\n performed_by_user_profile_id: roleChange.performed_by_user_profile_id as string & tags.Format<\"uuid\">,\n role_type: roleChange.role_type as \"admin\" | \"moderator\" | \"member\" | \"guest\",\n action_type: roleChange.action_type as \"assigned\" | \"revoked\",\n timestamp: toISOStringSafe(roleChange.timestamp),\n};\n\nreturn response;\n```\n\n**Key Principles for Bold Code Improvements:**\n\n1. **Restructure Complex Queries**: If a Prisma query with nested includes causes type errors, split it into multiple simpler queries\n2. **Extract Helper Functions**: Create utility functions for common transformations instead of repeating code\n3. **Use Intermediate Variables**: Create well-typed intermediate variables for clarity\n4. **Validate Early**: Add validation at the beginning rather than type assertions at the end\n5. **Simplify Logic**: If the current approach is convoluted, completely rewrite it with a cleaner pattern\n\n**Example: Transforming a Complex Nested Query**\n```typescript\n// ❌ Instead of fighting with complex nested types\nconst result = await prisma.post.findMany({\n include: {\n user: {\n include: {\n profile: true,\n settings: true,\n },\n },\n comments: {\n include: {\n user: true,\n },\n },\n },\n});\n\n// ✅ Bold approach: Separate queries with clear types\nconst posts = await prisma.post.findMany();\nconst postIds = posts.map(p => p.id);\n\nconst [users, comments] = await Promise.all([\n prisma.user.findMany({\n where: { posts: { some: { id: { in: postIds } } } },\n include: { profile: true, settings: true },\n }),\n prisma.comment.findMany({\n where: { post_id: { in: postIds } },\n include: { user: true },\n }),\n]);\n\n// Now combine with full type safety\nconst enrichedPosts = posts.map(post => ({\n ...transformPost(post),\n user: users.find(u => u.id === post.user_id),\n comments: comments.filter(c => c.post_id === post.id),\n}));\n```\n\n**Remember:** The goal isn't just to make TypeScript happy—it's to write clear, maintainable, and correct code. When you encounter resistance from the type system, it often means the code structure needs fundamental improvement, not just type patches.\n\n## 🎯 TransformRealizeCoderHistories Integration\n\nWhen fixing Date-related errors in the TransformRealizeCoderHistories process:\n\n1. **Identify all Date-related compilation errors** in the error list\n2. **Apply systematic conversion** using `toISOStringSafe()` for all Date assignments\n3. **Verify field existence** in target types before assignment\n4. **Remove non-existent fields** rather than forcing assignments\n5. **Maintain type safety** by using `satisfies` with proper types\n\n## Critical Reminders\n\n- **NEVER use `as any` or type assertions** to bypass Date type errors\n- **ALWAYS convert Date objects to ISO strings** before assignment\n- **Prisma DateTime fields are stored as ISO strings**, not Date objects\n- **All date fields in API structures use `string & tags.Format<'date-time'>`**\n- **Handle nullable dates with proper null checking** using `toISOStringSafe()` with conditional logic\n\nThis systematic approach ensures that all Date-related TypeScript errors are resolved correctly while maintaining type safety and consistency across the codebase.\n\n# Typia Guide\n\nWhen defining validation rules for input or response structures using `typia`, you **must** utilize `tags` exclusively through the `tags` namespace provided by the `typia` module. This ensures strict type safety, clarity, and compatibility with automated code generation and schema extraction.\nFor example, to use `tags.Format<'uuid'>`, you must reference it as `tags.Format`, not simply `Format`.\n\n## ✅ Correct Usage Examples\n\n```ts\nexport interface IUser {\n username: string & tags.MinLength<3> & tags.MaxLength<20>;\n email: string & tags.Format<\"email\">;\n age: number & tags.Type<\"uint32\"> & tags.Minimum<18>;\n}\n```\n\n## ❌ Invalid Usage Examples\n\n```ts\nexport interface IUser {\n username: string & MinLength<3> & MaxLength<20>;\n email: string & Format<\"email\">;\n age: number & Type<\"uint32\"> & Minimum<18>;\n}\n```\n\n---\n\n## 🛡️ `typia.assert` vs `typia.assertGuard`\n\n`typia` provides two main runtime validation utilities: `assert` and `assertGuard`.\nBoth serve to validate runtime data against a TypeScript type, but their **behavior and return types differ**, which can influence which one to use depending on your use case.\n\n### 🔍 `typia.assert<T>(input): T`\n\n* Validates that `input` conforms to type `T`.\n* If invalid, throws a detailed exception.\n* **Returns** the parsed and validated input as type `T`.\n* Ideal when you want **to validate and use the result immediately**.\n\n**Example:**\n\n```ts\nconst user = typia.assert<IUser>(input); // user is of type IUser\n```\n\n---\n\n### 🧪 `typia.assertGuard<T>(input): void`\n\n* Validates that `input` conforms to type `T`.\n* If invalid, throws an exception like `assert`.\n* **Does not return anything** (`void` return type).\n* Acts like a **type guard** for the input **within the scope**.\n* Useful when you want to narrow the type **for subsequent logic**, but **don't need to reassign the value**.\n\n**Example:**\n\n```ts\ntypia.assertGuard<IUser>(input); // input is now treated as IUser\n\n// input can be used safely as IUser here\nconsole.log(input.username);\n```\n\n### 📎 Appendix – `assert` vs `assertGuard`\n\n```ts\n/**\n * Asserts a value type.\n *\n * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed\n * reason, if the parametric value is not following the type `T`. Otherwise, the\n * value is following the type `T`, just input parameter would be returned.\n *\n * If what you want is not asserting but just knowing whether the parametric value is\n * following the type `T` or not, you can choose the {@link is} function instead.\n * Otherwise you want to know all the errors, {@link validate} is the way to go.\n * Also, if you want to automatically cast the parametric value to the type `T`\n * when no problem (perform the assertion guard of type).\n *\n * On the other and, if you don't want to allow any superfluous property that is not\n * enrolled to the type `T`, you can use {@link assertEquals} function instead.\n *\n * @template T Type of the input value\n * @param input A value to be asserted\n * @param errorFactory Custom error factory. Default is `TypeGuardError`\n * @returns Parametric input value\n * @throws A {@link TypeGuardError} instance with detailed reason\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport declare function assert<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): T;\n/**\n * Asserts a value type.\n *\n * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed\n * reason, if the parametric value is not following the type `T`. Otherwise, the\n * value is following the type `T`, just input parameter would be returned.\n *\n * If what you want is not asserting but just knowing whether the parametric value is\n * following the type `T` or not, you can choose the {@link is} function instead.\n * Otherwise, you want to know all the errors, {@link validate} is the way to go.\n *\n * On the other and, if you don't want to allow any superfluous property that is not\n * enrolled to the type `T`, you can use {@link assertEquals} function instead.\n *\n * @template T Type of the input value\n * @param input A value to be asserted\n * @param errorFactory Custom error factory. Default is `TypeGuardError`\n * @returns Parametric input value casted as `T`\n * @throws A {@link TypeGuardError} instance with detailed reason\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport declare function assert<T>(input: unknown, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): T;\n/**\n * Assertion guard of a value type.\n *\n * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed\n * reason, if the parametric value is not following the type `T`. Otherwise, the\n * value is following the type `T`, nothing would be returned, but the input value\n * would be automatically casted to the type `T`. This is the concept of\n * \"Assertion Guard\" of a value type.\n *\n * If what you want is not asserting but just knowing whether the parametric value is\n * following the type `T` or not, you can choose the {@link is} function instead.\n * Otherwise you want to know all the errors, {@link validate} is the way to go.\n * Also, if you want to returns the parametric value when no problem, you can use\n * {@link assert} function instead.\n *\n * On the other and, if you don't want to allow any superfluous property that is not\n * enrolled to the type `T`, you can use {@link assertGuardEquals} function instead.\n *\n * @template T Type of the input value\n * @param input A value to be asserted\n * @param errorFactory Custom error factory. Default is `TypeGuardError`\n * @throws A {@link TypeGuardError} instance with detailed reason\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport declare function assertGuard<T>(input: T, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): asserts input is T;\n/**\n * Assertion guard of a value type.\n *\n * Asserts a parametric value type and throws a {@link TypeGuardError} with detailed\n * reason, if the parametric value is not following the type `T`. Otherwise, the\n * value is following the type `T`, nothing would be returned, but the input value\n * would be automatically casted to the type `T`. This is the concept of\n * \"Assertion Guard\" of a value type.\n *\n * If what you want is not asserting but just knowing whether the parametric value is\n * following the type `T` or not, you can choose the {@link is} function instead.\n * Otherwise you want to know all the errors, {@link validate} is the way to go.\n * Also, if you want to returns the parametric value when no problem, you can use\n * {@link assert} function instead.\n *\n * On the other and, if you don't want to allow any superfluous property that is not\n * enrolled to the type `T`, you can use {@link assertGuardEquals} function instead.\n *\n * @template T Type of the input value\n * @param input A value to be asserted\n * @param errorFactory Custom error factory. Default is `TypeGuardError`\n * @throws A {@link TypeGuardError} instance with detailed reason\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport declare function assertGuard<T>(input: unknown, errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error)): asserts input is T;\n\n```\n\n### Handling Typia Assertion Errors for JsonSchemaPlugin Format Mismatches\n\n- These errors occur because a value typed as `number & Type<\"int32\">` is being assigned where `number & Type<\"int32\"> & typia.tags.JsonSchemaPlugin<{ format: \"uint32\" }>` is expected.\n- The root cause is a mismatch between signed (`int32`) and unsigned (`uint32`) integer formats.\n- To resolve these, use **typia.assert** to explicitly assert or validate the value conforms to the expected `uint32` format.\n- Example:\n\n```ts\nconst value = getValue(); // type: number & tags.Type<\"int32\">\n\ntypia.assert<number & tags.Type<\"int32\"> & tags.JsonSchemaPlugin<{ format: \"uint32\" }>>(value);\n\n// Now `value` is guaranteed to conform to the expected unsigned 32-bit integer type.\n```\n\n* Always use typia.tags' `assert` or related functions for runtime validation and to satisfy TypeScript's type checker.\n* This approach ensures type safety without compromising runtime correctness.\n\n---\n\n### ✅ Summary: Which Should I Use?\n\n| Use Case | Recommended API |\n| ------------------------------------ | ------------------------ |\n| Validate and return typed value | `typia.assert<T>()` |\n| Narrow type without reassigning | `typia.assertGuard<T>()` |\n| Use validated object directly | `typia.assert<T>()` |\n| Use input inside a conditional block | `typia.assertGuard<T>()` |\n\n> **Note:** Since `assertGuard` returns `void`, if you need **both type narrowing and a returned value**, `assert` is the better choice.\n\n---\n\n## 🏷️ Typia Tags Declaration – Explanation & Usage Guide\n\nYou can use the following tags from Typia to annotate your types for additional semantic meaning, validation constraints, or schema generation.\n\n| Tag | Purpose |\n| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `Constant` | Enforces the value to be a specific constant. Useful for literal values.<br>→ `string & tags.Constant<'active'>` |\n| `ContentMediaType` | Specifies the media type of content (e.g., `application/json`, `text/plain`). |\n| `Default` | Declares a default value to be used when the field is not provided.<br>**Note:** This is a schema-level hint, not runtime logic. |\n| `Example` | Declares a single example value to help with documentation tools like Swagger. |\n| `Examples` | Declares multiple example values. |\n| `ExclusiveMaximum` | Similar to `Maximum`, but the value must be **strictly less than** the given limit. |\n| `ExclusiveMinimum` | Similar to `Minimum`, but the value must be **strictly greater than** the given limit. |\n| `Format` | Specifies a semantic format for a value, such as:<br>→ `email`, `uuid`, `date-time`, `url`, etc.<br>✅ Used heavily across our codebase.<br>e.g., `string & tags.Format<'uuid'>` |\n| `JsonSchemaPlugin` | Allows adding plugin-specific schema behaviors. Rarely needed. |\n| `Maximum` | Specifies the maximum value (inclusive) for a number.<br>e.g., `number & tags.Maximum<100>` |\n| `MaxItems` | Specifies the maximum number of elements in an array. |\n| `MaxLength` | Specifies the maximum string length.<br>e.g., `string & tags.MaxLength<50>` |\n| `Minimum` | Specifies the minimum value (inclusive) for a number. |\n| `MinItems` | Specifies the minimum number of array items. |\n| `MinLength` | Specifies the minimum string length. |\n| `MultipleOf` | The value must be a multiple of the given number.<br>e.g., `number & tags.MultipleOf<5>` |\n| `Pattern` | Applies a regular expression pattern to a string.<br>e.g., `string & tags.Pattern<'^[a-z]+>` |\n| `Sequence` | Used for sequential fields like auto-incrementing IDs. |\n| `TagBase` | Internal utility tag – typically not used directly. |\n| `Type` | Used to enforce a type name in JSON Schema generation. |\n| `UniqueItems` | Ensures all elements in an array are unique. |\n\n---\n\n### ✅ Examples\n\n```ts\ntype UserId = string & tags.Format<'uuid'>;\ntype LimitedString = string & tags.MinLength<5> & tags.MaxLength<20>;\ntype SmallNumber = number & tags.Minimum<1> & tags.Maximum<10>;\ntype ConstantStatus = string & tags.Constant<'active'>;\ntype Email = string & tags.Format<'email'>;\n```\n\n---\n\n### 🔒 Typia Tag Usage Notes\n\n* Tags are used at the **type level**, not runtime.\n* They are especially useful when:\n - Generating OpenAPI/JSON Schema documentation\n - Validating input data with strict constraints\n - Ensuring type safety for specific formats (email, uuid, etc.)\n\n---\n\n## 🚨 CRITICAL: Prisma ID Field Handling\n\n### Primary Key (ID) Field Requirements\n\nWhen creating records with Prisma, you MUST carefully check the schema for ID field configuration:\n\n1. **Check ID Field Definition**: Look for `@id` or `@@id` annotations in the Prisma schema\n2. **Check for Auto-Generation**: Look for these patterns:\n - `@default(autoincrement())` - Auto-incrementing ID (DO NOT provide ID)\n - `@default(uuid())` - Auto-generated UUID (DO NOT provide ID)\n - `@default(cuid())` - Auto-generated CUID (DO NOT provide ID)\n - `@default(dbgenerated())` - Database-generated ID (DO NOT provide ID)\n - No `@default()` - **YOU MUST PROVIDE THE ID VALUE**\n\n3. **🚨 MANDATORY for Data Creation**: \n - **ALWAYS verify if the primary key has a default value before creating data**\n - This is a CRITICAL check that must be performed in every create operation\n - If no default exists, you MUST generate and provide the ID using `v4()`:\n ```typescript\n // When schema shows: id String @id (no default)\n const created = await MyGlobal.prisma.someModel.create({\n data: {\n id: v4() as string & tags.Format<\"uuid\">, // REQUIRED when no @default!\n // ... other fields\n }\n });\n ```\n - If default exists, NEVER provide the ID:\n ```typescript\n // When schema shows: id String @id @default(uuid())\n const created = await MyGlobal.prisma.someModel.create({\n data: {\n // DO NOT include id field - it's auto-generated\n // ... other fields\n }\n });\n ```\n\n### ❌ Common Mistake - Missing Required ID\n\n```typescript\n// ❌ WRONG - Missing required ID when schema has no default\nconst created = await MyGlobal.prisma.discussion_board_warnings.create({\n data: {\n member_id: body.member_id,\n moderator_id: body.moderator_id,\n warning_type: body.warning_type,\n message: body.message,\n created_at: toISOStringSafe(body.created_at),\n },\n});\n```\n\n### ✅ Correct - Including Required ID\n\n```typescript\n// ✅ CORRECT - Including ID when schema has no default\nconst created = await MyGlobal.prisma.discussion_board_warnings.create({\n data: {\n id: body.id, // REQUIRED when schema has no @default\n member_id: body.member_id,\n moderator_id: body.moderator_id,\n warning_type: body.warning_type,\n message: body.message,\n created_at: toISOStringSafe(body.created_at),\n },\n});\n```\n\n### Schema Analysis Checklist\n\nBefore implementing any Prisma create operation:\n\n1. **Examine the model's ID field**:\n ```prisma\n model discussion_board_warnings {\n id String @id // No @default() = YOU MUST PROVIDE ID\n // vs\n id String @id @default(uuid()) // Has default = DO NOT PROVIDE ID\n }\n ```\n\n2. **Apply the rule**:\n - Has `@default()` → Prisma generates ID automatically\n - No `@default()` → You MUST include `id` in the create data\n\n3. **Verify composite keys**: If using `@@id([field1, field2])`, all composite key fields must be provided\n\n### 🔴 ABSOLUTE RULE: Always Check Prisma Schema for ID Configuration\n\n**NEVER ASSUME** an ID field is auto-generated. **ALWAYS VERIFY** by checking the Prisma schema for the presence of `@default()` annotation on the ID field. This is a frequent source of runtime errors.\n\n---\n\n## 🚨 CRITICAL: Prisma OrderBy Inline Usage\n\n### Never Extract orderBy as a Variable\n\nWhen using Prisma's `orderBy` parameter, **ALWAYS** define it inline within the query. Extracting it as a variable often causes TypeScript type inference issues.\n\n### ❌ Common Mistake - Extracting orderBy\n\n```typescript\n// ❌ WRONG - Extracting orderBy as a variable causes type errors\nconst orderBy = \n sort === \"created_at\"\n ? { created_at: order === \"asc\" ? \"asc\" : \"desc\" }\n : { created_at: \"desc\" };\n\nconst [rows, total] = await Promise.all([\n MyGlobal.prisma.discussion_board_attachments.findMany({\n where,\n orderBy, // Type error prone!\n skip,\n take: pageSize,\n }),\n MyGlobal.prisma.discussion_board_attachments.count({ where }),\n]);\n```\n\n### ✅ Correct - Inline orderBy Definition\n\n```typescript\n// ✅ CORRECT - Define orderBy inline for proper type inference\nconst [rows, total] = await Promise.all([\n MyGlobal.prisma.discussion_board_attachments.findMany({\n where,\n orderBy: sort === \"created_at\"\n ? { created_at: order === \"asc\" ? \"asc\" : \"desc\" }\n : { created_at: \"desc\" },\n skip,\n take: pageSize,\n }),\n MyGlobal.prisma.discussion_board_attachments.count({ where }),\n]);\n```\n\n### Why This Matters\n\n1. **Type Inference**: Prisma uses complex generic types that work best with inline definitions\n2. **Type Safety**: Extracting orderBy can lose the connection between the model and the ordering fields\n3. **Maintenance**: Inline definitions are clearer about which fields can be ordered\n\n### 🔴 ABSOLUTE RULE: Always Define orderBy Inline\n\n**NEVER** extract `orderBy` as a separate variable. **ALWAYS** define it inline within the Prisma query options. This prevents type errors and ensures proper TypeScript inference.\n\n> ⚠️ **Never use these tags directly for logic branching in code.** They are strictly for static type and schema purposes."
|
|
8348
8472
|
}, {
|
|
8349
8473
|
id: v4(),
|
|
8350
8474
|
created_at: (new Date).toISOString(),
|
|
8351
8475
|
type: "systemMessage",
|
|
8352
|
-
text:
|
|
8353
|
-
}, {
|
|
8476
|
+
text: '# Prisma Schemas\n\n```json\n{prisma_schemas}\n````\n\n# ℹ️ How to Use the Above Prisma Schemas\n\nThese Prisma schemas are extracted directly from your actual `schema.prisma` file.\n\n✅ **You must always consult this schema before writing any Prisma function** such as `create`, `update`, `select`, `delete`, or `where`. Do **not** rely on assumptions — every field must be verified.\n\n### 🔍 When reviewing the schema, check:\n\n1. **Does the field exist?**\n2. **Is it a scalar field or a relation field?**\n3. **Is it required, optional, or nullable?**\n4. **Can this field be updated directly, or must it be accessed via `connect`, `disconnect`, or `set`?**\n5. **Does the model include soft-delete fields like `deleted_at`?**\n\n> You must check the schema to determine whether fields such as `deleted_at`, `actor_id`, or `user_id` are actually present.\n> Never assume a field exists or is accessible directly.\n\n### ⚠️ Common Prisma Mistakes (Avoid These!)\n\n* ❌ Referencing fields that do not exist (→ causes `TS2339`, `TS2353`)\n* ❌ Using foreign keys like `user_id` directly instead of:\n\n ```ts\n user: { connect: { id: "..." } }\n ```\n* ❌ Passing `Date` directly into a field that expects a string (→ causes `TS2322`)\n\n ```ts\n new Date().toISOString() // ✅ use this\n ```\n* ❌ Selecting or updating fields that are derived or virtual (Prisma types exclude them)\n* ❌ Using fields in `updateInput` that only exist in `createInput`, or vice versa\n\n### ✅ Rule of Thumb\n\n> **If you get a TypeScript error like `TS2339`, `TS2353`, `TS2322`, or `TS2352`, check your schema first.**\n> Most of the time, you\'re either referencing a non-existent field or using the wrong type or structure.\n\n---\n\n# Function Props Structure\n\nThe following shows the expected props structure for this function:\n\n```typescript\n{input}\n```\n\n**IMPORTANT**: The provider function you will implement must:\n- **If props are defined above**: Accept a **single object parameter** that matches this props structure **exactly**\n- **If no props are shown above**: Accept **no parameters** at all\n- The parameter type must be **identical** to what is shown above - no additions, no modifications\n- This is a mapped type containing only the fields that are actually needed for this specific endpoint\n\nThe props structure is carefully constructed based on:\n- Authentication requirements (role-specific fields like admin, user, member)\n- URL path parameters (e.g., id, boardId, postId)\n- Request body (if applicable)\n\nYour function signature must match one of these patterns:\n```typescript\n// If props are defined above\nexport async function your_function_name(\n props: { /* exactly as shown above */ }\n): Promise<ReturnType> {\n // Implementation\n}\n\n// If no props are shown above (empty)\nexport async function your_function_name(): Promise<ReturnType> {\n // Implementation - no props parameter\n}\n```\n\n---\n\n# SDK\n\nThe following is the SDK for the API. Based on the information provided by this SDK, you must write code that maps the SDK-provided parameters directly into the `parameters` and `body` properties of the provider function response.\n\n* If there are no parameters, define `parameters` as `Record<string, never>`.\n* If there is no body, define `body` as `Record<string, never>`.\n* **Every function must be implemented to accept both `parameters` and `body`, without exception.**\n* If any required type information is referenced in the SDK, refer to the definitions in the DTO section.\n\n```json\n{artifacts_sdk}\n```\n\n---\n\n# DTO\n\nWhen importing DTOs, you must **always** use this path structure:\n\n```ts\nimport { Something } from \'../api/structures/Something\';\n```\n\n* ✅ Use `../api/structures/...`\n* ❌ Never use `../../structures/...` — these paths will not resolve\n* If a type like `string & Format<"date-time">` is required, ensure you convert `Date` to a valid ISO string\n\n```json\n{artifacts_dto}\n```'.replaceAll(`{prisma_schemas}`, JSON.stringify(state.prisma.schemas)).replaceAll(`{artifacts_sdk}`, JSON.stringify(artifacts.sdk)).replaceAll(`{artifacts_dto}`, JSON.stringify(artifacts.dto)).replaceAll(`{input}`, input)
|
|
8477
|
+
}, ...previous !== null ? [ {
|
|
8354
8478
|
id: v4(),
|
|
8355
8479
|
created_at: (new Date).toISOString(),
|
|
8356
|
-
type: "
|
|
8357
|
-
text:
|
|
8358
|
-
},
|
|
8480
|
+
type: "assistantMessage",
|
|
8481
|
+
text: [ "These values contain previously generated code and thought flow.", "All of these codes are failed compilation values.", previousCodes.length >= 2 ? "🚨 CRITICAL: You have already failed " + previousCodes.length + " times. The current approach is FUNDAMENTALLY WRONG!" : "Please refer to the code for writing a new code.", previousCodes.length >= 2 ? [ "", "After multiple failures, you MUST make AGGRESSIVE changes:", "1. COMPLETELY REWRITE the problematic parts - don't just tweak", "2. Try a DIFFERENT algorithm or approach entirely", "3. Question ALL your assumptions about the requirements", "4. Consider alternative Prisma patterns or query structures", "5. The error might be in your fundamental understanding - rethink everything" ].join("\n") : "", "", "```json", JSON.stringify(previousCodes.map((c => c.result.implementationCode))), "```" ].filter(Boolean).join("\n")
|
|
8482
|
+
}, {
|
|
8359
8483
|
id: v4(),
|
|
8360
8484
|
created_at: (new Date).toISOString(),
|
|
8361
8485
|
type: "assistantMessage",
|
|
@@ -8390,15 +8514,22 @@ var RealizeFileSystem;
|
|
|
8390
8514
|
})(RealizeFileSystem || (RealizeFileSystem = {}));
|
|
8391
8515
|
|
|
8392
8516
|
function replaceImportStatements(ctx) {
|
|
8393
|
-
return async function(code, decoratorType) {
|
|
8517
|
+
return async function(artifacts, code, decoratorType) {
|
|
8518
|
+
const typeReferences = Array.from(new Set(Object.keys(artifacts.document.components.schemas).map((key => key.split(".")[0]))));
|
|
8394
8519
|
const compiler = await ctx.compiler();
|
|
8395
8520
|
code = await compiler.typescript.beautify(code);
|
|
8396
8521
|
code = code.replace(/import\s*{\s*MyGlobal\s*}\s*from\s*["']\.\.\/MyGlobal["']\s*;?\s*/gm, "").replace(/import\s+typia\s*,\s*{\s*tags\s*}\s*from\s*["']typia["']\s*;?\s*/gm, "").replace(/import\s*{\s*tags\s*}\s*from\s*["']typia["']\s*;?\s*/gm, "").replace(/import\s*{\s*tags\s*,\s*typia\s*}\s*from\s*["']typia["']\s*;?\s*/gm, "").replace(/import\s+typia\s*from\s*["']typia["']\s*;?\s*/gm, "").replace(/import\s*{\s*Prisma\s*}\s*from\s*["']@prisma\/client["']\s*;?\s*/gm, "").replace(/import\s*{\s*v4\s*}\s*from\s*["']uuid["']\s*;?\s*/gm, "").replace(/import\s*{\s*toISOStringSafe\s*}\s*from\s*["']\.\.\/util\/toISOStringSafe["']\s*;?\s*/gm, "");
|
|
8522
|
+
code = code.replace(/import\s*(?:type\s*)?{\s*[^}]+\s*}\s*from\s*["']\.\.\/api\/structures\/[^"']+["']\s*;?\s*/gm, "");
|
|
8523
|
+
code = code.replace(/import\s*(?:type\s*)?{\s*[^}]+\s*}\s*from\s*["']@ORGANIZATION\/PROJECT-api\/lib\/structures\/[^"']+["']\s*;?\s*/gm, "");
|
|
8524
|
+
for (const ref of typeReferences) {
|
|
8525
|
+
const typeImportRegex = new RegExp(`import\\s*(?:type\\s*)?{\\s*${ref}\\s*}\\s*from\\s*["'][^"']+["']\\s*;?\\s*`, "gm");
|
|
8526
|
+
code = code.replace(typeImportRegex, "");
|
|
8527
|
+
}
|
|
8397
8528
|
if (decoratorType) {
|
|
8398
|
-
const decoratorTypeRegex = new RegExp(`import\\s*{\\s*${decoratorType}\\s*}\\s*from\\s*["']\\.\\./decorators/payload/${decoratorType}["']\\s*;?\\s*`, "gm");
|
|
8529
|
+
const decoratorTypeRegex = new RegExp(`import\\s*(?:type\\s*)?{\\s*${decoratorType}\\s*}\\s*from\\s*["']\\.\\./decorators/payload/${decoratorType}["']\\s*;?\\s*`, "gm");
|
|
8399
8530
|
code = code.replace(decoratorTypeRegex, "");
|
|
8400
8531
|
}
|
|
8401
|
-
const imports = [ 'import { MyGlobal } from "../MyGlobal";', 'import typia, { tags } from "typia";', 'import { Prisma } from "@prisma/client";', 'import { v4 } from "uuid";', 'import { toISOStringSafe } from "../util/toISOStringSafe"' ];
|
|
8532
|
+
const imports = [ 'import { MyGlobal } from "../MyGlobal";', 'import typia, { tags } from "typia";', 'import { Prisma } from "@prisma/client";', 'import { v4 } from "uuid";', 'import { toISOStringSafe } from "../util/toISOStringSafe"', ...typeReferences.map((ref => `import { ${ref} } from "@ORGANIZATION/PROJECT-api/lib/structures/${ref}";`)) ];
|
|
8402
8533
|
if (decoratorType) {
|
|
8403
8534
|
imports.push(`import { ${decoratorType} } from "../decorators/payload/${decoratorType}"`);
|
|
8404
8535
|
}
|
|
@@ -8410,7 +8541,7 @@ function replaceImportStatements(ctx) {
|
|
|
8410
8541
|
};
|
|
8411
8542
|
}
|
|
8412
8543
|
|
|
8413
|
-
const orchestrateRealizeCoder = async (ctx, operation, props, previous, total, diagnostics) => {
|
|
8544
|
+
const orchestrateRealizeCoder = async (ctx, operation, previousCodes, props, previous, total, diagnostics, authorization) => {
|
|
8414
8545
|
const artifacts = await getTestScenarioArtifacts(ctx, {
|
|
8415
8546
|
endpoint: {
|
|
8416
8547
|
method: operation.method,
|
|
@@ -8437,7 +8568,7 @@ const orchestrateRealizeCoder = async (ctx, operation, props, previous, total, d
|
|
|
8437
8568
|
describe: null
|
|
8438
8569
|
}
|
|
8439
8570
|
},
|
|
8440
|
-
histories: transformRealizeCoderHistories(ctx.state(), props, artifacts, previous, diagnostics)
|
|
8571
|
+
histories: transformRealizeCoderHistories(ctx.state(), previousCodes, props, artifacts, previous, diagnostics, authorization)
|
|
8441
8572
|
});
|
|
8442
8573
|
enforceToolCall(agent);
|
|
8443
8574
|
await randomBackoffRetry((() => agent.conversate([ `Write complete, production-ready TypeScript code that strictly follows these rules:`, "", `1. Do **not** use the native \`Date\` type anywhere.`, `2. All date or datetime values must be written as \`string & tags.Format<'date-time'>\`.`, `3. UUIDs must be generated using \`v4()\` and typed as \`string & tags.Format<'uuid'>\`.`, `4. Do not use \`as\` for type assertions — resolve types properly.`, `5. All functions must be fully typed with clear parameter and return types.`, `6. Do not skip validations or default values where necessary.`, `7. Follow functional, immutable, and consistent code structure.`, "", `Use \`@nestia/e2e\` test structure if relevant.` ].join("\n")))).finally((() => {
|
|
@@ -8447,7 +8578,7 @@ const orchestrateRealizeCoder = async (ctx, operation, props, previous, total, d
|
|
|
8447
8578
|
if (pointer.value === null) {
|
|
8448
8579
|
return FAILED;
|
|
8449
8580
|
}
|
|
8450
|
-
pointer.value.implementationCode = await replaceImportStatements(ctx)(pointer.value.implementationCode, props.decoratorEvent?.payload.name);
|
|
8581
|
+
pointer.value.implementationCode = await replaceImportStatements(ctx)(artifacts, pointer.value.implementationCode, props.decoratorEvent?.payload.name);
|
|
8451
8582
|
pointer.value.implementationCode = pointer.value.implementationCode.replaceAll("typia.tags.assert", "typia.assert");
|
|
8452
8583
|
return {
|
|
8453
8584
|
...pointer.value,
|
|
@@ -8484,19 +8615,16 @@ const claude$4 = {
|
|
|
8484
8615
|
properties: {
|
|
8485
8616
|
output: {
|
|
8486
8617
|
description: "The detailed output of the code generation process, containing all phases\nfrom planning to final implementation of a TypeScript provider function.",
|
|
8487
|
-
$ref: "#/$defs/
|
|
8618
|
+
$ref: "#/$defs/OmitIAutoBeRealizeCoderApplication.RealizeCoderOutputfilename"
|
|
8488
8619
|
}
|
|
8489
8620
|
},
|
|
8490
8621
|
required: [ "output" ],
|
|
8491
8622
|
additionalProperties: false,
|
|
8492
8623
|
$defs: {
|
|
8493
|
-
"
|
|
8494
|
-
description: "
|
|
8624
|
+
"OmitIAutoBeRealizeCoderApplication.RealizeCoderOutputfilename": {
|
|
8625
|
+
description: "Construct a type with the properties of T except for those in type K.",
|
|
8495
8626
|
type: "object",
|
|
8496
8627
|
properties: {
|
|
8497
|
-
filename: {
|
|
8498
|
-
type: "string"
|
|
8499
|
-
},
|
|
8500
8628
|
errorAnalysis: {
|
|
8501
8629
|
description: "Error Analysis Phase (Optional)\n\n🔍 Analyzes TypeScript compilation errors from previous attempts.\n\nThis field should contain a detailed analysis of any TypeScript errors\nencountered, with root cause identification and resolution strategies:\n\nCommon Error Patterns to Analyze:\n\n1. **\"Property does not exist\" (TS2353)**:\n\n - Root Cause: Using fields that don't exist in Prisma schema\n - Example: Using `deleted_at` when the field doesn't exist in the model\n - Resolution: Remove the non-existent field or use hard delete instead\n2. **\"Type 'void' is not assignable\" (TS2322)**:\n\n - Root Cause: Using `typia.assertGuard` instead of `typia.assert`\n - `assertGuard` returns void, `assert` returns the validated value\n - Resolution: Change `typia.assertGuard<T>()` to `typia.assert<T>()`\n3. **\"Type 'Date' is not assignable to type 'string &\n Format<'date-time'>'\"**:\n\n - Root Cause: Assigning native Date objects to string fields\n - Resolution: Use `toISOStringSafe(dateValue)` for all date conversions\n4. **Complex Prisma Type Errors**:\n\n - Root Cause: Nested operations with incompatible types\n - Resolution: Use separate queries and application-level joins\n\nAnalysis Format:\n\n- List each error with its TypeScript error code\n- Identify the root cause (schema mismatch, wrong function usage, etc.)\n- Provide specific resolution steps\n- Note any schema limitations discovered",
|
|
8502
8630
|
type: "string"
|
|
@@ -8518,7 +8646,7 @@ const claude$4 = {
|
|
|
8518
8646
|
type: "string"
|
|
8519
8647
|
},
|
|
8520
8648
|
withCompilerFeedback: {
|
|
8521
|
-
description: "🛠 Phase 4-2: With compiler feedback (optional)\n\nA correction pass that applies fixes for compile-time errors that arose\nduring the review stage (if any).\n\n✅ Must:\n\n- Only include this field if TypeScript errors are detected in the Review\n phase.\n- Resolve all TypeScript errors without using `as any`.\n- Provide safe brand casting only if required (e.g., `as string &\n tags.Format<'uuid'>`)
|
|
8649
|
+
description: "🛠 Phase 4-2: With compiler feedback (optional)\n\nA correction pass that applies fixes for compile-time errors that arose\nduring the review stage (if any).\n\n✅ Must:\n\n- Only include this field if TypeScript errors are detected in the Review\n phase.\n- Resolve all TypeScript errors without using `as any`.\n- Provide safe brand casting only if required (e.g., `as string &\n tags.Format<'uuid'>`).\n- If no TypeScript errors exist, this field MUST contain the text: \"No\n TypeScript errors detected - skipping this phase\"",
|
|
8522
8650
|
type: "string"
|
|
8523
8651
|
},
|
|
8524
8652
|
implementationCode: {
|
|
@@ -8526,27 +8654,23 @@ const claude$4 = {
|
|
|
8526
8654
|
type: "string"
|
|
8527
8655
|
}
|
|
8528
8656
|
},
|
|
8529
|
-
required: [ "
|
|
8657
|
+
required: [ "plan", "prisma_schemas", "draft_without_date_type", "review", "withCompilerFeedback", "implementationCode" ]
|
|
8530
8658
|
}
|
|
8531
8659
|
}
|
|
8532
8660
|
},
|
|
8533
8661
|
validate: (() => {
|
|
8534
8662
|
const _io0 = input => "object" === typeof input.output && null !== input.output && _io1(input.output);
|
|
8535
|
-
const _io1 = input =>
|
|
8663
|
+
const _io1 = input => (undefined === input.errorAnalysis || "string" === typeof input.errorAnalysis) && "string" === typeof input.plan && "string" === typeof input.prisma_schemas && "string" === typeof input.draft_without_date_type && "string" === typeof input.review && "string" === typeof input.withCompilerFeedback && "string" === typeof input.implementationCode;
|
|
8536
8664
|
const _vo0 = (input, _path, _exceptionable = true) => [ ("object" === typeof input.output && null !== input.output || _report(_exceptionable, {
|
|
8537
8665
|
path: _path + ".output",
|
|
8538
|
-
expected:
|
|
8666
|
+
expected: 'Omit<IAutoBeRealizeCoderApplication.RealizeCoderOutput, "filename">',
|
|
8539
8667
|
value: input.output
|
|
8540
8668
|
})) && _vo1(input.output, _path + ".output", _exceptionable) || _report(_exceptionable, {
|
|
8541
8669
|
path: _path + ".output",
|
|
8542
|
-
expected:
|
|
8670
|
+
expected: 'Omit<IAutoBeRealizeCoderApplication.RealizeCoderOutput, "filename">',
|
|
8543
8671
|
value: input.output
|
|
8544
8672
|
}) ].every((flag => flag));
|
|
8545
|
-
const _vo1 = (input, _path, _exceptionable = true) => [ "string" === typeof input.
|
|
8546
|
-
path: _path + ".filename",
|
|
8547
|
-
expected: "string",
|
|
8548
|
-
value: input.filename
|
|
8549
|
-
}), undefined === input.errorAnalysis || "string" === typeof input.errorAnalysis || _report(_exceptionable, {
|
|
8673
|
+
const _vo1 = (input, _path, _exceptionable = true) => [ undefined === input.errorAnalysis || "string" === typeof input.errorAnalysis || _report(_exceptionable, {
|
|
8550
8674
|
path: _path + ".errorAnalysis",
|
|
8551
8675
|
expected: "(string | undefined)",
|
|
8552
8676
|
value: input.errorAnalysis
|
|
@@ -8566,9 +8690,9 @@ const claude$4 = {
|
|
|
8566
8690
|
path: _path + ".review",
|
|
8567
8691
|
expected: "string",
|
|
8568
8692
|
value: input.review
|
|
8569
|
-
}),
|
|
8693
|
+
}), "string" === typeof input.withCompilerFeedback || _report(_exceptionable, {
|
|
8570
8694
|
path: _path + ".withCompilerFeedback",
|
|
8571
|
-
expected: "
|
|
8695
|
+
expected: "string",
|
|
8572
8696
|
value: input.withCompilerFeedback
|
|
8573
8697
|
}), "string" === typeof input.implementationCode || _report(_exceptionable, {
|
|
8574
8698
|
path: _path + ".implementationCode",
|
|
@@ -8625,19 +8749,16 @@ const collection$4 = {
|
|
|
8625
8749
|
type: "object",
|
|
8626
8750
|
properties: {
|
|
8627
8751
|
output: {
|
|
8628
|
-
$ref: "#/$defs/
|
|
8752
|
+
$ref: "#/$defs/OmitIAutoBeRealizeCoderApplication.RealizeCoderOutputfilename"
|
|
8629
8753
|
}
|
|
8630
8754
|
},
|
|
8631
8755
|
required: [ "output" ],
|
|
8632
8756
|
additionalProperties: false,
|
|
8633
8757
|
$defs: {
|
|
8634
|
-
"
|
|
8635
|
-
description: "
|
|
8758
|
+
"OmitIAutoBeRealizeCoderApplication.RealizeCoderOutputfilename": {
|
|
8759
|
+
description: "Construct a type with the properties of T except for those in type K.",
|
|
8636
8760
|
type: "object",
|
|
8637
8761
|
properties: {
|
|
8638
|
-
filename: {
|
|
8639
|
-
type: "string"
|
|
8640
|
-
},
|
|
8641
8762
|
errorAnalysis: {
|
|
8642
8763
|
description: "Error Analysis Phase (Optional)\n\n🔍 Analyzes TypeScript compilation errors from previous attempts.\n\nThis field should contain a detailed analysis of any TypeScript errors\nencountered, with root cause identification and resolution strategies:\n\nCommon Error Patterns to Analyze:\n\n1. **\"Property does not exist\" (TS2353)**:\n\n - Root Cause: Using fields that don't exist in Prisma schema\n - Example: Using `deleted_at` when the field doesn't exist in the model\n - Resolution: Remove the non-existent field or use hard delete instead\n2. **\"Type 'void' is not assignable\" (TS2322)**:\n\n - Root Cause: Using `typia.assertGuard` instead of `typia.assert`\n - `assertGuard` returns void, `assert` returns the validated value\n - Resolution: Change `typia.assertGuard<T>()` to `typia.assert<T>()`\n3. **\"Type 'Date' is not assignable to type 'string &\n Format<'date-time'>'\"**:\n\n - Root Cause: Assigning native Date objects to string fields\n - Resolution: Use `toISOStringSafe(dateValue)` for all date conversions\n4. **Complex Prisma Type Errors**:\n\n - Root Cause: Nested operations with incompatible types\n - Resolution: Use separate queries and application-level joins\n\nAnalysis Format:\n\n- List each error with its TypeScript error code\n- Identify the root cause (schema mismatch, wrong function usage, etc.)\n- Provide specific resolution steps\n- Note any schema limitations discovered",
|
|
8643
8764
|
type: "string"
|
|
@@ -8659,7 +8780,7 @@ const collection$4 = {
|
|
|
8659
8780
|
type: "string"
|
|
8660
8781
|
},
|
|
8661
8782
|
withCompilerFeedback: {
|
|
8662
|
-
description: "🛠 Phase 4-2: With compiler feedback (optional)\n\nA correction pass that applies fixes for compile-time errors that arose\nduring the review stage (if any).\n\n✅ Must:\n\n- Only include this field if TypeScript errors are detected in the Review\n phase.\n- Resolve all TypeScript errors without using `as any`.\n- Provide safe brand casting only if required (e.g., `as string &\n tags.Format<'uuid'>`)
|
|
8783
|
+
description: "🛠 Phase 4-2: With compiler feedback (optional)\n\nA correction pass that applies fixes for compile-time errors that arose\nduring the review stage (if any).\n\n✅ Must:\n\n- Only include this field if TypeScript errors are detected in the Review\n phase.\n- Resolve all TypeScript errors without using `as any`.\n- Provide safe brand casting only if required (e.g., `as string &\n tags.Format<'uuid'>`).\n- If no TypeScript errors exist, this field MUST contain the text: \"No\n TypeScript errors detected - skipping this phase\"",
|
|
8663
8784
|
type: "string"
|
|
8664
8785
|
},
|
|
8665
8786
|
implementationCode: {
|
|
@@ -8667,27 +8788,23 @@ const collection$4 = {
|
|
|
8667
8788
|
type: "string"
|
|
8668
8789
|
}
|
|
8669
8790
|
},
|
|
8670
|
-
required: [ "
|
|
8791
|
+
required: [ "plan", "prisma_schemas", "draft_without_date_type", "review", "withCompilerFeedback", "implementationCode" ]
|
|
8671
8792
|
}
|
|
8672
8793
|
}
|
|
8673
8794
|
},
|
|
8674
8795
|
validate: (() => {
|
|
8675
8796
|
const _io0 = input => "object" === typeof input.output && null !== input.output && _io1(input.output);
|
|
8676
|
-
const _io1 = input =>
|
|
8797
|
+
const _io1 = input => (undefined === input.errorAnalysis || "string" === typeof input.errorAnalysis) && "string" === typeof input.plan && "string" === typeof input.prisma_schemas && "string" === typeof input.draft_without_date_type && "string" === typeof input.review && "string" === typeof input.withCompilerFeedback && "string" === typeof input.implementationCode;
|
|
8677
8798
|
const _vo0 = (input, _path, _exceptionable = true) => [ ("object" === typeof input.output && null !== input.output || _report(_exceptionable, {
|
|
8678
8799
|
path: _path + ".output",
|
|
8679
|
-
expected:
|
|
8800
|
+
expected: 'Omit<IAutoBeRealizeCoderApplication.RealizeCoderOutput, "filename">',
|
|
8680
8801
|
value: input.output
|
|
8681
8802
|
})) && _vo1(input.output, _path + ".output", _exceptionable) || _report(_exceptionable, {
|
|
8682
8803
|
path: _path + ".output",
|
|
8683
|
-
expected:
|
|
8804
|
+
expected: 'Omit<IAutoBeRealizeCoderApplication.RealizeCoderOutput, "filename">',
|
|
8684
8805
|
value: input.output
|
|
8685
8806
|
}) ].every((flag => flag));
|
|
8686
|
-
const _vo1 = (input, _path, _exceptionable = true) => [ "string" === typeof input.
|
|
8687
|
-
path: _path + ".filename",
|
|
8688
|
-
expected: "string",
|
|
8689
|
-
value: input.filename
|
|
8690
|
-
}), undefined === input.errorAnalysis || "string" === typeof input.errorAnalysis || _report(_exceptionable, {
|
|
8807
|
+
const _vo1 = (input, _path, _exceptionable = true) => [ undefined === input.errorAnalysis || "string" === typeof input.errorAnalysis || _report(_exceptionable, {
|
|
8691
8808
|
path: _path + ".errorAnalysis",
|
|
8692
8809
|
expected: "(string | undefined)",
|
|
8693
8810
|
value: input.errorAnalysis
|
|
@@ -8707,9 +8824,9 @@ const collection$4 = {
|
|
|
8707
8824
|
path: _path + ".review",
|
|
8708
8825
|
expected: "string",
|
|
8709
8826
|
value: input.review
|
|
8710
|
-
}),
|
|
8827
|
+
}), "string" === typeof input.withCompilerFeedback || _report(_exceptionable, {
|
|
8711
8828
|
path: _path + ".withCompilerFeedback",
|
|
8712
|
-
expected: "
|
|
8829
|
+
expected: "string",
|
|
8713
8830
|
value: input.withCompilerFeedback
|
|
8714
8831
|
}), "string" === typeof input.implementationCode || _report(_exceptionable, {
|
|
8715
8832
|
path: _path + ".implementationCode",
|
|
@@ -8770,123 +8887,165 @@ const orchestrateRealizePlanner = async (ctx, operation, authorization) => {
|
|
|
8770
8887
|
};
|
|
8771
8888
|
};
|
|
8772
8889
|
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
total: []
|
|
8784
|
-
};
|
|
8785
|
-
for (let i = 0; i < retry; i++) {
|
|
8786
|
-
const targets = ops.filter((op => shouldProcessOperation(op, diagnostics.current)));
|
|
8787
|
-
const metadata = {
|
|
8788
|
-
total: targets.length,
|
|
8789
|
-
count: 0
|
|
8890
|
+
function writeCodeUntilCompilePassed(ctx) {
|
|
8891
|
+
return async function(props) {
|
|
8892
|
+
const payloads = Object.fromEntries(props.authorizations.map((el => [ el.payload.location, el.payload.content ])));
|
|
8893
|
+
const files = Object.fromEntries(Object.entries(await ctx.files({
|
|
8894
|
+
dbms: "postgres"
|
|
8895
|
+
})).filter((([key]) => key.startsWith("src"))));
|
|
8896
|
+
const templateFiles = await getTemplates(ctx);
|
|
8897
|
+
let diagnostics = {
|
|
8898
|
+
current: [],
|
|
8899
|
+
total: []
|
|
8790
8900
|
};
|
|
8791
|
-
const
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
return process$1(ctx, metadata, op, diagnostics, entireCodes, decorator);
|
|
8795
|
-
})));
|
|
8796
|
-
for (const c of generatedCodes) {
|
|
8797
|
-
if (c.type === "success") {
|
|
8798
|
-
entireCodes[c.result.filename] = {
|
|
8799
|
-
content: c.result.implementationCode,
|
|
8800
|
-
result: "success",
|
|
8801
|
-
endpoint: {
|
|
8802
|
-
method: c.op.method,
|
|
8803
|
-
path: c.op.path
|
|
8804
|
-
},
|
|
8805
|
-
location: c.result.filename,
|
|
8806
|
-
name: c.result.name
|
|
8807
|
-
};
|
|
8808
|
-
}
|
|
8901
|
+
const histories = new HashMap(ProviderCodeComparator.hashCode, ProviderCodeComparator.equals);
|
|
8902
|
+
for (const operation of props.operations) {
|
|
8903
|
+
histories.set(operation, []);
|
|
8809
8904
|
}
|
|
8810
|
-
|
|
8811
|
-
const
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8905
|
+
let compiled = null;
|
|
8906
|
+
const entireCodes = {};
|
|
8907
|
+
for (let i = 0; i < props.retry; i++) {
|
|
8908
|
+
const targets = props.operations.filter((op => shouldProcessOperation(op, diagnostics.current)));
|
|
8909
|
+
const metadata = {
|
|
8910
|
+
total: targets.length,
|
|
8911
|
+
count: 0
|
|
8912
|
+
};
|
|
8913
|
+
const generatedCodes = await Promise.all(targets.map((operation => {
|
|
8914
|
+
const role = operation.authorizationRole;
|
|
8915
|
+
const authorization = props.authorizations.find((el => el.role === role));
|
|
8916
|
+
return process$1(ctx)({
|
|
8917
|
+
metadata,
|
|
8918
|
+
operation,
|
|
8919
|
+
previousCodes: histories.get(operation),
|
|
8920
|
+
diagnostics,
|
|
8921
|
+
entireCodes,
|
|
8922
|
+
authorization
|
|
8923
|
+
});
|
|
8924
|
+
})));
|
|
8925
|
+
for (const code of generatedCodes) {
|
|
8926
|
+
if (code.type === "success") {
|
|
8927
|
+
const response = histories.get(code.operation);
|
|
8928
|
+
response.push(code);
|
|
8929
|
+
histories.set(code.operation, response);
|
|
8930
|
+
entireCodes[code.result.filename] = {
|
|
8931
|
+
content: code.result.implementationCode,
|
|
8932
|
+
result: "success",
|
|
8933
|
+
endpoint: {
|
|
8934
|
+
method: code.operation.method,
|
|
8935
|
+
path: code.operation.path
|
|
8936
|
+
},
|
|
8937
|
+
location: code.result.filename,
|
|
8938
|
+
name: code.result.name
|
|
8939
|
+
};
|
|
8940
|
+
}
|
|
8941
|
+
}
|
|
8942
|
+
const prisma = ctx.state().prisma?.compiled;
|
|
8943
|
+
const nodeModules = prisma?.type === "success" ? prisma.nodeModules : {};
|
|
8944
|
+
const compiler = await ctx.compiler();
|
|
8945
|
+
compiled = await compiler.typescript.compile({
|
|
8946
|
+
files: {
|
|
8947
|
+
...payloads,
|
|
8948
|
+
...files,
|
|
8949
|
+
...nodeModules,
|
|
8950
|
+
...Object.fromEntries(templateFiles.map((file => [ file.location, file.content ]))),
|
|
8951
|
+
...Object.fromEntries(Object.entries(entireCodes).map((([filename, {content}]) => [ filename, content ])))
|
|
8952
|
+
}
|
|
8953
|
+
});
|
|
8954
|
+
if (compiled && compiled.type !== "success") {
|
|
8955
|
+
ctx.dispatch({
|
|
8956
|
+
type: "realizeValidate",
|
|
8957
|
+
created_at: (new Date).toISOString(),
|
|
8958
|
+
files: compiled.type === "failure" ? Object.fromEntries(compiled.diagnostics.map((diagnostic => [ diagnostic.file, diagnostic.code ]))) : {},
|
|
8959
|
+
result: compiled,
|
|
8960
|
+
step: ctx.state().analyze?.step ?? 0
|
|
8961
|
+
});
|
|
8962
|
+
}
|
|
8963
|
+
if (compiled.type === "success" && generatedCodes.every((c => c.type === "success"))) {
|
|
8964
|
+
break;
|
|
8965
|
+
} else if (compiled.type === "failure") {
|
|
8966
|
+
diagnostics.current = compiled.diagnostics;
|
|
8967
|
+
diagnostics.total = [ ...diagnostics.total, ...compiled.diagnostics ];
|
|
8819
8968
|
}
|
|
8820
|
-
});
|
|
8821
|
-
if (compiled.type === "success" && generatedCodes.every((c => c.type === "success"))) {
|
|
8822
|
-
break;
|
|
8823
|
-
} else if (compiled.type === "failure") {
|
|
8824
|
-
diagnostics.current = compiled.diagnostics;
|
|
8825
|
-
diagnostics.total = [ ...diagnostics.total, ...compiled.diagnostics ];
|
|
8826
|
-
console.log(JSON.stringify(diagnostics.current, null, 2), `현재 에러의 수: ${diagnostics.current.length}\n`, `현재 시도 수: ${i + 1}`);
|
|
8827
8969
|
}
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8970
|
+
const functions = Object.entries(entireCodes).filter((([filename]) => filename.startsWith("src/providers"))).map((([filename, value]) => ({
|
|
8971
|
+
filename,
|
|
8972
|
+
content: value.content,
|
|
8973
|
+
endpoint: value.endpoint,
|
|
8974
|
+
location: value.location,
|
|
8975
|
+
name: value.name,
|
|
8976
|
+
role: value.role ?? null
|
|
8977
|
+
})));
|
|
8978
|
+
return {
|
|
8979
|
+
functions,
|
|
8980
|
+
compiled: compiled ? compiled : {
|
|
8981
|
+
type: "success"
|
|
8982
|
+
}
|
|
8983
|
+
};
|
|
8984
|
+
};
|
|
8837
8985
|
}
|
|
8838
8986
|
|
|
8839
|
-
async function
|
|
8840
|
-
const
|
|
8841
|
-
const
|
|
8842
|
-
const
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
};
|
|
8850
|
-
}
|
|
8851
|
-
return result;
|
|
8987
|
+
async function getTemplates(ctx) {
|
|
8988
|
+
const compiler = await ctx.compiler();
|
|
8989
|
+
const templateFiles = await compiler.realize.getTemplate();
|
|
8990
|
+
const pathnames = [ "src/MyGlobal.ts", "src/util/toISOStringSafe.ts" ];
|
|
8991
|
+
return pathnames.map((pathname => ({
|
|
8992
|
+
content: templateFiles[pathname],
|
|
8993
|
+
result: "success",
|
|
8994
|
+
location: pathname,
|
|
8995
|
+
role: null
|
|
8996
|
+
})));
|
|
8852
8997
|
}
|
|
8853
8998
|
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
const
|
|
8857
|
-
|
|
8858
|
-
|
|
8859
|
-
|
|
8860
|
-
|
|
8861
|
-
ctx.
|
|
8862
|
-
|
|
8863
|
-
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8999
|
+
function process$1(ctx) {
|
|
9000
|
+
return async function(props) {
|
|
9001
|
+
const result = await pipe(props.operation, (operation => orchestrateRealizePlanner(ctx, operation, props.authorization)), (async plan => {
|
|
9002
|
+
const filename = RealizeFileSystem.providerPath(plan.functionName);
|
|
9003
|
+
const totalDiagnostics = props.diagnostics.total.filter((el => el.file === filename));
|
|
9004
|
+
const currentDiagnostics = props.diagnostics.current.filter((el => el.file === filename));
|
|
9005
|
+
const code = props.entireCodes[filename]?.content ?? null;
|
|
9006
|
+
return orchestrateRealizeCoder(ctx, props.operation, props.previousCodes, plan, code, totalDiagnostics, currentDiagnostics, props.authorization).then((res => {
|
|
9007
|
+
if (props.previousCodes.length === 0) {
|
|
9008
|
+
ctx.dispatch({
|
|
9009
|
+
type: "realizeWrite",
|
|
9010
|
+
filename,
|
|
9011
|
+
content: res === FAILED ? "FAILED" : res.implementationCode,
|
|
9012
|
+
completed: ++props.metadata.count,
|
|
9013
|
+
created_at: (new Date).toISOString(),
|
|
9014
|
+
step: ctx.state().analyze?.step ?? 0,
|
|
9015
|
+
total: props.metadata.total
|
|
9016
|
+
});
|
|
9017
|
+
} else {
|
|
9018
|
+
ctx.dispatch({
|
|
9019
|
+
type: "realizeCorrect",
|
|
9020
|
+
filename,
|
|
9021
|
+
content: res === FAILED ? "FAILED" : res.implementationCode,
|
|
9022
|
+
completed: ++props.metadata.count,
|
|
9023
|
+
created_at: (new Date).toISOString(),
|
|
9024
|
+
step: ctx.state().analyze?.step ?? 0,
|
|
9025
|
+
total: props.metadata.total
|
|
9026
|
+
});
|
|
9027
|
+
}
|
|
9028
|
+
if (res === FAILED) {
|
|
9029
|
+
return res;
|
|
9030
|
+
}
|
|
9031
|
+
return {
|
|
9032
|
+
...res,
|
|
9033
|
+
name: plan.functionName
|
|
9034
|
+
};
|
|
9035
|
+
}));
|
|
9036
|
+
}));
|
|
9037
|
+
if (result === FAILED) {
|
|
8873
9038
|
return {
|
|
8874
|
-
|
|
8875
|
-
|
|
9039
|
+
type: "failed",
|
|
9040
|
+
operation: props.operation,
|
|
9041
|
+
result
|
|
8876
9042
|
};
|
|
8877
|
-
}
|
|
8878
|
-
}));
|
|
8879
|
-
if (result === FAILED) {
|
|
9043
|
+
}
|
|
8880
9044
|
return {
|
|
8881
|
-
type: "
|
|
8882
|
-
|
|
9045
|
+
type: "success",
|
|
9046
|
+
operation: props.operation,
|
|
8883
9047
|
result
|
|
8884
9048
|
};
|
|
8885
|
-
}
|
|
8886
|
-
return {
|
|
8887
|
-
type: "success",
|
|
8888
|
-
op,
|
|
8889
|
-
result
|
|
8890
9049
|
};
|
|
8891
9050
|
}
|
|
8892
9051
|
|
|
@@ -8903,10 +9062,11 @@ function generateProviderFilename(op) {
|
|
|
8903
9062
|
}
|
|
8904
9063
|
|
|
8905
9064
|
const orchestrateRealize = ctx => async props => {
|
|
8906
|
-
const
|
|
8907
|
-
if (!
|
|
9065
|
+
const operations = ctx.state().interface?.document.operations;
|
|
9066
|
+
if (!operations) {
|
|
8908
9067
|
throw new Error("Can't do realize agent because operations are nothing.");
|
|
8909
9068
|
}
|
|
9069
|
+
const start = new Date;
|
|
8910
9070
|
ctx.dispatch({
|
|
8911
9071
|
type: "realizeStart",
|
|
8912
9072
|
created_at: (new Date).toISOString(),
|
|
@@ -8914,54 +9074,47 @@ const orchestrateRealize = ctx => async props => {
|
|
|
8914
9074
|
step: ctx.state().test?.step ?? 0
|
|
8915
9075
|
});
|
|
8916
9076
|
const authorizations = await orchestrateRealizeAuthorization(ctx);
|
|
8917
|
-
const
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
realize.functions = files;
|
|
8922
|
-
} else {
|
|
8923
|
-
const history = ctx.state().realize = {
|
|
8924
|
-
type: "realize",
|
|
8925
|
-
compiled: {
|
|
8926
|
-
type: "success"
|
|
8927
|
-
},
|
|
8928
|
-
functions: {
|
|
8929
|
-
...files,
|
|
8930
|
-
...authorizations.flatMap((el => [ {
|
|
8931
|
-
[el.decorator.location]: el.decorator.content
|
|
8932
|
-
}, {
|
|
8933
|
-
[el.payload.location]: el.payload.content
|
|
8934
|
-
}, {
|
|
8935
|
-
[el.payload.location]: el.payload.content
|
|
8936
|
-
} ])).reduce(((acc, cur) => Object.assign(acc, cur)))
|
|
8937
|
-
},
|
|
8938
|
-
completed_at: now,
|
|
8939
|
-
created_at: now,
|
|
8940
|
-
id: v4(),
|
|
8941
|
-
reason: props.reason,
|
|
8942
|
-
step: ctx.state().analyze?.step ?? 0,
|
|
8943
|
-
authorizations: ctx.state().realize?.authorizations ?? []
|
|
8944
|
-
};
|
|
8945
|
-
ctx.histories().push(history);
|
|
8946
|
-
}
|
|
8947
|
-
ctx.dispatch({
|
|
8948
|
-
type: "assistantMessage",
|
|
8949
|
-
text: "Any codes can not be generated.",
|
|
8950
|
-
created_at: now
|
|
9077
|
+
const result = await writeCodeUntilCompilePassed(ctx)({
|
|
9078
|
+
operations,
|
|
9079
|
+
authorizations,
|
|
9080
|
+
retry: 4
|
|
8951
9081
|
});
|
|
8952
|
-
|
|
9082
|
+
const functions = result.functions;
|
|
9083
|
+
const compiler = await ctx.compiler();
|
|
9084
|
+
const controllers = await compiler.realize.controller({
|
|
9085
|
+
document: ctx.state().interface.document,
|
|
9086
|
+
functions,
|
|
9087
|
+
authorizations
|
|
9088
|
+
});
|
|
9089
|
+
const history = {
|
|
8953
9090
|
type: "realize",
|
|
8954
|
-
compiled:
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
|
|
8958
|
-
completed_at:
|
|
8959
|
-
created_at:
|
|
9091
|
+
compiled: result.compiled,
|
|
9092
|
+
authorizations,
|
|
9093
|
+
functions,
|
|
9094
|
+
controllers,
|
|
9095
|
+
completed_at: (new Date).toISOString(),
|
|
9096
|
+
created_at: start.toISOString(),
|
|
8960
9097
|
id: v4(),
|
|
8961
9098
|
reason: props.reason,
|
|
8962
|
-
step: ctx.state().analyze?.step ?? 0
|
|
8963
|
-
authorizations: ctx.state().realize?.authorizations ?? []
|
|
9099
|
+
step: ctx.state().analyze?.step ?? 0
|
|
8964
9100
|
};
|
|
9101
|
+
ctx.dispatch({
|
|
9102
|
+
type: "realizeComplete",
|
|
9103
|
+
created_at: (new Date).toISOString(),
|
|
9104
|
+
functions: history.functions,
|
|
9105
|
+
authorizations: history.authorizations,
|
|
9106
|
+
controllers: history.controllers,
|
|
9107
|
+
compiled: await compiler.typescript.compile({
|
|
9108
|
+
files: await getAutoBeGenerated(compiler, {
|
|
9109
|
+
...ctx.state(),
|
|
9110
|
+
realize: history
|
|
9111
|
+
}, [ ...ctx.histories(), history ], ctx.usage())
|
|
9112
|
+
}),
|
|
9113
|
+
step: ctx.state().analyze?.step ?? 0
|
|
9114
|
+
});
|
|
9115
|
+
ctx.state().realize = history;
|
|
9116
|
+
ctx.histories().push(history);
|
|
9117
|
+
return history;
|
|
8965
9118
|
};
|
|
8966
9119
|
|
|
8967
9120
|
function completeTestCode(artifacts, code) {
|
|
@@ -10620,7 +10773,7 @@ const orchestrateTest = ctx => async props => {
|
|
|
10620
10773
|
ctx.dispatch({
|
|
10621
10774
|
type: "testComplete",
|
|
10622
10775
|
created_at: start.toISOString(),
|
|
10623
|
-
files:
|
|
10776
|
+
files: result,
|
|
10624
10777
|
compiled,
|
|
10625
10778
|
step: ctx.state().interface?.step ?? 0
|
|
10626
10779
|
});
|
|
@@ -11585,7 +11738,7 @@ class AutoBeAgent extends AutoBeAgentBase {
|
|
|
11585
11738
|
execute: () => transformFacadeStateMessage(this.state_)
|
|
11586
11739
|
}
|
|
11587
11740
|
},
|
|
11588
|
-
tokenUsage:
|
|
11741
|
+
tokenUsage: this.usage_.facade,
|
|
11589
11742
|
controllers: [ createAutoBeController({
|
|
11590
11743
|
model: props.model,
|
|
11591
11744
|
context: this.context_
|
|
@@ -11692,12 +11845,12 @@ class AutoBeMockAgent extends AutoBeAgentBase {
|
|
|
11692
11845
|
};
|
|
11693
11846
|
void this.dispatch(userMessage).catch((() => {}));
|
|
11694
11847
|
const state = createAutoBeState(this.histories_);
|
|
11695
|
-
if (state.
|
|
11848
|
+
if (state.realize !== null) {
|
|
11696
11849
|
await sleep_for(2e3);
|
|
11697
11850
|
const assistantMessage = {
|
|
11698
11851
|
id: v4(),
|
|
11699
11852
|
type: "assistantMessage",
|
|
11700
|
-
text: [ "
|
|
11853
|
+
text: [ "AutoBE has successfully realized the application.", "", "Thanks for using AutoBE!" ].join("\n"),
|
|
11701
11854
|
created_at: (new Date).toISOString(),
|
|
11702
11855
|
completed_at: (new Date).toISOString()
|
|
11703
11856
|
};
|
|
@@ -11715,7 +11868,7 @@ class AutoBeMockAgent extends AutoBeAgentBase {
|
|
|
11715
11868
|
this.histories_.push(userMessage);
|
|
11716
11869
|
this.histories_.push(this.props_.preset.histories.find((h => h.type === type)));
|
|
11717
11870
|
};
|
|
11718
|
-
if (state.analyze === null) await take("analyze"); else if (state.prisma === null) await take("prisma"); else if (state.interface === null) await take("interface"); else if (state.test === null) await take("test");
|
|
11871
|
+
if (state.analyze === null) await take("analyze"); else if (state.prisma === null) await take("prisma"); else if (state.interface === null) await take("interface"); else if (state.test === null) await take("test"); else if (state.realize === null) await take("realize");
|
|
11719
11872
|
return this.histories_;
|
|
11720
11873
|
}
|
|
11721
11874
|
getHistories() {
|
|
@@ -11752,7 +11905,16 @@ const sleepMap = {
|
|
|
11752
11905
|
testWrite: 40,
|
|
11753
11906
|
testValidate: 100,
|
|
11754
11907
|
testCorrect: 100,
|
|
11755
|
-
testComplete: 1e3
|
|
11908
|
+
testComplete: 1e3,
|
|
11909
|
+
realizeStart: 1e3,
|
|
11910
|
+
realizeComplete: 1e3,
|
|
11911
|
+
realizeWrite: 80,
|
|
11912
|
+
realizeCorrect: 80,
|
|
11913
|
+
realizeValidate: 200,
|
|
11914
|
+
realizeAuthorizationStart: 1e3,
|
|
11915
|
+
realizeAuthorizationWrite: 200,
|
|
11916
|
+
realizeAuthorizationValidate: 200,
|
|
11917
|
+
realizeAuthorizationComplete: 1e3
|
|
11756
11918
|
};
|
|
11757
11919
|
|
|
11758
11920
|
export { AutoBeAgent, AutoBeMockAgent, AutoBeTokenUsage, index$1 as factory, index as orchestrate };
|