@autobe/agent 0.24.2 → 0.25.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/constants/AutoBeSystemPromptConstant.d.ts +16 -16
- package/lib/context/IAutoBeApplication.d.ts +101 -6
- package/lib/context/IAutoBeApplicationProps.d.ts +6 -2
- package/lib/factory/createAgenticaHistory.js +1 -1
- package/lib/factory/createAgenticaHistory.js.map +1 -1
- package/lib/factory/createAutoBeApplication.js +80 -90
- package/lib/factory/createAutoBeApplication.js.map +1 -1
- package/lib/factory/createAutoBeContext.js +5 -5
- package/lib/factory/createAutoBeContext.js.map +1 -1
- package/lib/index.mjs +941 -1065
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/histories/transformAnalyzeReviewHistories.js +5 -1
- package/lib/orchestrate/analyze/histories/transformAnalyzeReviewHistories.js.map +1 -1
- package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioHistories.d.ts +1 -1
- package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioHistories.js +18 -3
- package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioHistories.js.map +1 -1
- package/lib/orchestrate/analyze/histories/transformAnalyzeWriteHistories.d.ts +5 -1
- package/lib/orchestrate/analyze/histories/transformAnalyzeWriteHistories.js +19 -7
- package/lib/orchestrate/analyze/histories/transformAnalyzeWriteHistories.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyze.js +3 -2
- package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeScenario.d.ts +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeScenario.js +2 -2
- package/lib/orchestrate/analyze/orchestrateAnalyzeScenario.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.d.ts +1 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +2 -2
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -1
- package/lib/orchestrate/facade/transformFacadeStateMessage.js +1 -1
- package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceAssetHistories.js +2 -1
- package/lib/orchestrate/interface/histories/transformInterfaceAssetHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceAuthorizationsHistories.d.ts +5 -1
- package/lib/orchestrate/interface/histories/transformInterfaceAuthorizationsHistories.js +20 -7
- package/lib/orchestrate/interface/histories/transformInterfaceAuthorizationsHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.d.ts +6 -1
- package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js +31 -23
- package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.d.ts +6 -1
- package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js +22 -6
- package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceEndpointsReviewHistories.js +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceEndpointsReviewHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.d.ts +4 -1
- package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js +26 -5
- package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.d.ts +5 -1
- package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js +21 -5
- package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceOperationsReviewHistories.js +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceOperationsReviewHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.d.ts +5 -1
- package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js +20 -4
- package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterface.js +25 -7
- package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.d.ts +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js +17 -8
- package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.d.ts +4 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +18 -11
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.d.ts +6 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +25 -10
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.d.ts +4 -1
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.js +9 -6
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.d.ts +5 -1
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +33 -17
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.d.ts +5 -1
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js +36 -18
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js.map +1 -1
- package/lib/orchestrate/prisma/histories/transformPrismaComponentsHistories.d.ts +4 -1
- package/lib/orchestrate/prisma/histories/transformPrismaComponentsHistories.js +19 -8
- package/lib/orchestrate/prisma/histories/transformPrismaComponentsHistories.js.map +1 -1
- package/lib/orchestrate/prisma/histories/transformPrismaReviewHistories.js +1 -1
- package/lib/orchestrate/prisma/histories/transformPrismaReviewHistories.js.map +1 -1
- package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistories.d.ts +6 -1
- package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistories.js +20 -6
- package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistories.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrisma.js +3 -3
- package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaComponent.d.ts +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js +6 -3
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaSchemas.d.ts +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaSchemas.js +12 -6
- package/lib/orchestrate/prisma/orchestratePrismaSchemas.js.map +1 -1
- package/lib/orchestrate/{common/histories/transformCommonCorrectDateHistories.d.ts → realize/histories/transformRealizeCorrectCastingHistories.d.ts} +1 -2
- package/lib/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.js +33 -0
- package/lib/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.js.map +1 -0
- package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js +21 -7
- package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealize.js +3 -9
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeCorrect.js +12 -2
- package/lib/orchestrate/realize/orchestrateRealizeCorrect.js.map +1 -1
- package/lib/orchestrate/realize/utils/generateRealizeScenario.js +1 -5
- package/lib/orchestrate/realize/utils/generateRealizeScenario.js.map +1 -1
- package/lib/orchestrate/realize/utils/replaceImportStatements.js +3 -1
- package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestCorrectHistories.d.ts +5 -1
- package/lib/orchestrate/test/histories/transformTestCorrectHistories.js +11 -7
- package/lib/orchestrate/test/histories/transformTestCorrectHistories.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestScenarioHistories.d.ts +7 -1
- package/lib/orchestrate/test/histories/transformTestScenarioHistories.js +39 -31
- package/lib/orchestrate/test/histories/transformTestScenarioHistories.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.d.ts +6 -3
- package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.js +32 -26
- package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestWriteHistories.d.ts +5 -1
- package/lib/orchestrate/test/histories/transformTestWriteHistories.js +111 -94
- package/lib/orchestrate/test/histories/transformTestWriteHistories.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTest.js +20 -14
- package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +4 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.js +51 -35
- package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.d.ts +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.js +14 -3
- package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestScenarioReview.d.ts +5 -1
- package/lib/orchestrate/test/orchestrateTestScenarioReview.js +19 -11
- package/lib/orchestrate/test/orchestrateTestScenarioReview.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestWrite.d.ts +4 -1
- package/lib/orchestrate/test/orchestrateTestWrite.js +9 -4
- package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
- package/package.json +5 -5
- package/src/constants/AutoBeSystemPromptConstant.ts +16 -16
- package/src/context/IAutoBeApplication.ts +101 -6
- package/src/context/IAutoBeApplicationProps.ts +6 -2
- package/src/factory/createAgenticaHistory.ts +11 -5
- package/src/factory/createAutoBeContext.ts +5 -5
- package/src/orchestrate/analyze/histories/transformAnalyzeReviewHistories.ts +5 -1
- package/src/orchestrate/analyze/histories/transformAnalyzeScenarioHistories.ts +16 -0
- package/src/orchestrate/analyze/histories/transformAnalyzeWriteHistories.ts +22 -7
- package/src/orchestrate/analyze/orchestrateAnalyze.ts +3 -2
- package/src/orchestrate/analyze/orchestrateAnalyzeScenario.ts +2 -1
- package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +3 -2
- package/src/orchestrate/interface/histories/transformInterfaceAssetHistories.ts +2 -1
- package/src/orchestrate/interface/histories/transformInterfaceAuthorizationsHistories.ts +23 -9
- package/src/orchestrate/interface/histories/transformInterfaceComplementHistories.ts +33 -24
- package/src/orchestrate/interface/histories/transformInterfaceEndpointHistories.ts +26 -9
- package/src/orchestrate/interface/histories/transformInterfaceGroupHistories.ts +27 -5
- package/src/orchestrate/interface/histories/transformInterfaceOperationHistories.ts +24 -7
- package/src/orchestrate/interface/histories/transformInterfaceSchemaHistories.ts +23 -6
- package/src/orchestrate/interface/orchestrateInterface.ts +29 -10
- package/src/orchestrate/interface/orchestrateInterfaceAuthorizations.ts +22 -12
- package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +25 -17
- package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +35 -23
- package/src/orchestrate/interface/orchestrateInterfaceGroups.ts +9 -3
- package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +44 -29
- package/src/orchestrate/interface/orchestrateInterfaceSchemas.ts +51 -32
- package/src/orchestrate/prisma/histories/transformPrismaComponentsHistories.ts +20 -6
- package/src/orchestrate/prisma/histories/transformPrismaSchemaHistories.ts +24 -9
- package/src/orchestrate/prisma/orchestratePrisma.ts +7 -3
- package/src/orchestrate/prisma/orchestratePrismaComponent.ts +5 -1
- package/src/orchestrate/prisma/orchestratePrismaSchemas.ts +15 -10
- package/src/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.ts +45 -0
- package/src/orchestrate/realize/orchestRateRealizeCorrectCasting.ts +26 -7
- package/src/orchestrate/realize/orchestrateRealize.ts +6 -17
- package/src/orchestrate/realize/orchestrateRealizeCorrect.ts +18 -2
- package/src/orchestrate/realize/utils/generateRealizeScenario.ts +1 -5
- package/src/orchestrate/realize/utils/replaceImportStatements.ts +5 -0
- package/src/orchestrate/test/histories/transformTestCorrectHistories.ts +14 -7
- package/src/orchestrate/test/histories/transformTestScenarioHistories.ts +44 -36
- package/src/orchestrate/test/histories/transformTestScenarioReviewHistories.ts +74 -71
- package/src/orchestrate/test/histories/transformTestWriteHistories.ts +35 -12
- package/src/orchestrate/test/orchestrateTest.ts +19 -13
- package/src/orchestrate/test/orchestrateTestCorrect.ts +65 -46
- package/src/orchestrate/test/orchestrateTestScenario.ts +15 -11
- package/src/orchestrate/test/orchestrateTestScenarioReview.ts +29 -16
- package/src/orchestrate/test/orchestrateTestWrite.ts +13 -4
- package/lib/orchestrate/common/histories/transformCommonCorrectDateHistories.js +0 -48
- package/lib/orchestrate/common/histories/transformCommonCorrectDateHistories.js.map +0 -1
- package/lib/orchestrate/common/structures/IAutoBeCommonCorrectDateApplication.d.ts +0 -35
- package/lib/orchestrate/common/structures/IAutoBeCommonCorrectDateApplication.js +0 -3
- package/lib/orchestrate/common/structures/IAutoBeCommonCorrectDateApplication.js.map +0 -1
- package/lib/orchestrate/realize/orchestrateRealizeCorrectDate.d.ts +0 -4
- package/lib/orchestrate/realize/orchestrateRealizeCorrectDate.js +0 -540
- package/lib/orchestrate/realize/orchestrateRealizeCorrectDate.js.map +0 -1
- package/src/orchestrate/common/histories/transformCommonCorrectDateHistories.ts +0 -60
- package/src/orchestrate/common/structures/IAutoBeCommonCorrectDateApplication.ts +0 -40
- package/src/orchestrate/realize/orchestrateRealizeCorrectDate.ts +0 -372
|
@@ -26,14 +26,16 @@ export async function orchestrateInterfaceOperations<
|
|
|
26
26
|
Model extends ILlmSchema.Model,
|
|
27
27
|
>(
|
|
28
28
|
ctx: AutoBeContext<Model>,
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
props: {
|
|
30
|
+
instruction: string;
|
|
31
|
+
endpoints: AutoBeOpenApi.IEndpoint[];
|
|
32
|
+
capacity?: number;
|
|
33
|
+
},
|
|
31
34
|
): Promise<AutoBeOpenApi.IOperation[]> {
|
|
32
35
|
const matrix: AutoBeOpenApi.IEndpoint[][] = divideArray({
|
|
33
|
-
array: endpoints,
|
|
34
|
-
capacity,
|
|
36
|
+
array: props.endpoints,
|
|
37
|
+
capacity: props.capacity ?? AutoBeConfigConstant.INTERFACE_CAPACITY,
|
|
35
38
|
});
|
|
36
|
-
|
|
37
39
|
const progress: AutoBeProgressEventBase = {
|
|
38
40
|
total: matrix.flat().length,
|
|
39
41
|
completed: 0,
|
|
@@ -45,13 +47,13 @@ export async function orchestrateInterfaceOperations<
|
|
|
45
47
|
return (
|
|
46
48
|
await executeCachedBatch(
|
|
47
49
|
matrix.map((it) => async (promptCacheKey) => {
|
|
48
|
-
const row: AutoBeOpenApi.IOperation[] = await divideAndConquer(
|
|
49
|
-
|
|
50
|
-
it,
|
|
50
|
+
const row: AutoBeOpenApi.IOperation[] = await divideAndConquer(ctx, {
|
|
51
|
+
endpoints: it,
|
|
51
52
|
progress,
|
|
52
53
|
reviewProgress,
|
|
53
54
|
promptCacheKey,
|
|
54
|
-
|
|
55
|
+
instruction: props.instruction,
|
|
56
|
+
});
|
|
55
57
|
return row;
|
|
56
58
|
}),
|
|
57
59
|
)
|
|
@@ -60,13 +62,16 @@ export async function orchestrateInterfaceOperations<
|
|
|
60
62
|
|
|
61
63
|
async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
62
64
|
ctx: AutoBeContext<Model>,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
props: {
|
|
66
|
+
endpoints: AutoBeOpenApi.IEndpoint[];
|
|
67
|
+
progress: AutoBeProgressEventBase;
|
|
68
|
+
reviewProgress: AutoBeProgressEventBase;
|
|
69
|
+
promptCacheKey: string;
|
|
70
|
+
instruction: string;
|
|
71
|
+
},
|
|
67
72
|
): Promise<AutoBeOpenApi.IOperation[]> {
|
|
68
73
|
const remained: HashSet<AutoBeOpenApi.IEndpoint> = new HashSet(
|
|
69
|
-
endpoints,
|
|
74
|
+
props.endpoints,
|
|
70
75
|
OpenApiEndpointComparator.hashCode,
|
|
71
76
|
OpenApiEndpointComparator.equals,
|
|
72
77
|
);
|
|
@@ -76,9 +81,15 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
|
76
81
|
OpenApiEndpointComparator.equals,
|
|
77
82
|
);
|
|
78
83
|
for (let i: number = 0; i < ctx.retry; ++i) {
|
|
79
|
-
if (remained.empty() === true || unique.size() >= endpoints.length)
|
|
84
|
+
if (remained.empty() === true || unique.size() >= props.endpoints.length)
|
|
85
|
+
break;
|
|
80
86
|
const operations: AutoBeOpenApi.IOperation[] = remained.size()
|
|
81
|
-
? await process(ctx,
|
|
87
|
+
? await process(ctx, {
|
|
88
|
+
endpoints: remained,
|
|
89
|
+
progress: props.progress,
|
|
90
|
+
promptCacheKey: props.promptCacheKey,
|
|
91
|
+
instruction: props.instruction,
|
|
92
|
+
})
|
|
82
93
|
: [];
|
|
83
94
|
|
|
84
95
|
for (const item of operations) {
|
|
@@ -90,7 +101,7 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
|
90
101
|
await orchestrateInterfaceOperationsReview(
|
|
91
102
|
ctx,
|
|
92
103
|
unique.toJSON().map((it) => it.second),
|
|
93
|
-
|
|
104
|
+
props.reviewProgress,
|
|
94
105
|
);
|
|
95
106
|
for (const item of newbie) unique.set(item, item);
|
|
96
107
|
return unique.toJSON().map((it) => it.second);
|
|
@@ -98,9 +109,12 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
|
98
109
|
|
|
99
110
|
async function process<Model extends ILlmSchema.Model>(
|
|
100
111
|
ctx: AutoBeContext<Model>,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
props: {
|
|
113
|
+
endpoints: HashSet<AutoBeOpenApi.IEndpoint>;
|
|
114
|
+
progress: AutoBeProgressEventBase;
|
|
115
|
+
promptCacheKey: string;
|
|
116
|
+
instruction: string;
|
|
117
|
+
},
|
|
104
118
|
): Promise<AutoBeOpenApi.IOperation[]> {
|
|
105
119
|
const prefix: string = NamingConvention.camel(ctx.state().analyze!.prefix);
|
|
106
120
|
const pointer: IPointer<AutoBeOpenApi.IOperation[] | null> = {
|
|
@@ -108,10 +122,11 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
108
122
|
};
|
|
109
123
|
const { tokenUsage } = await ctx.conversate({
|
|
110
124
|
source: "interfaceOperations",
|
|
111
|
-
histories: transformInterfaceOperationHistories(
|
|
112
|
-
ctx.state(),
|
|
113
|
-
endpoints.toJSON(),
|
|
114
|
-
|
|
125
|
+
histories: transformInterfaceOperationHistories({
|
|
126
|
+
state: ctx.state(),
|
|
127
|
+
endpoints: props.endpoints.toJSON(),
|
|
128
|
+
instruction: props.instruction,
|
|
129
|
+
}),
|
|
115
130
|
controller: createController({
|
|
116
131
|
model: ctx.model,
|
|
117
132
|
roles: ctx.state().analyze?.roles.map((it) => it.name) ?? [],
|
|
@@ -143,10 +158,10 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
143
158
|
}));
|
|
144
159
|
});
|
|
145
160
|
pointer.value.push(...matrix.flat());
|
|
146
|
-
progress.completed += matrix.flat().length;
|
|
147
|
-
progress.total += operations
|
|
161
|
+
props.progress.completed += matrix.flat().length;
|
|
162
|
+
props.progress.total += operations
|
|
148
163
|
.map((op) =>
|
|
149
|
-
endpoints.has({ path: op.path, method: op.method })
|
|
164
|
+
props.endpoints.has({ path: op.path, method: op.method })
|
|
150
165
|
? op.authorizationRoles.length === 0
|
|
151
166
|
? 0
|
|
152
167
|
: op.authorizationRoles.length - 1
|
|
@@ -156,7 +171,7 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
156
171
|
},
|
|
157
172
|
}),
|
|
158
173
|
enforceFunctionCall: true,
|
|
159
|
-
promptCacheKey,
|
|
174
|
+
promptCacheKey: props.promptCacheKey,
|
|
160
175
|
message: "Make API operations",
|
|
161
176
|
});
|
|
162
177
|
if (pointer.value === null) throw new Error("Failed to create operations."); // never be happened
|
|
@@ -166,7 +181,7 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
166
181
|
id: v7(),
|
|
167
182
|
operations: pointer.value,
|
|
168
183
|
tokenUsage,
|
|
169
|
-
...progress,
|
|
184
|
+
...props.progress,
|
|
170
185
|
step: ctx.state().analyze?.step ?? 0,
|
|
171
186
|
created_at: new Date().toISOString(),
|
|
172
187
|
} satisfies AutoBeInterfaceOperationsEvent);
|
|
@@ -27,15 +27,18 @@ export async function orchestrateInterfaceSchemas<
|
|
|
27
27
|
Model extends ILlmSchema.Model,
|
|
28
28
|
>(
|
|
29
29
|
ctx: AutoBeContext<Model>,
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
props: {
|
|
31
|
+
operations: AutoBeOpenApi.IOperation[];
|
|
32
|
+
instruction: string;
|
|
33
|
+
capacity?: number;
|
|
34
|
+
},
|
|
32
35
|
): Promise<Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>> {
|
|
33
36
|
// fix operation type names
|
|
34
|
-
JsonSchemaNamingConvention.operations(operations);
|
|
37
|
+
JsonSchemaNamingConvention.operations(props.operations);
|
|
35
38
|
|
|
36
39
|
// gather type names
|
|
37
40
|
const typeNames: Set<string> = new Set();
|
|
38
|
-
for (const op of operations) {
|
|
41
|
+
for (const op of props.operations) {
|
|
39
42
|
if (op.requestBody !== null) typeNames.add(op.requestBody.typeName);
|
|
40
43
|
if (op.responseBody !== null) typeNames.add(op.responseBody.typeName);
|
|
41
44
|
}
|
|
@@ -45,7 +48,7 @@ export async function orchestrateInterfaceSchemas<
|
|
|
45
48
|
// divide and conquer
|
|
46
49
|
const matrix: string[][] = divideArray({
|
|
47
50
|
array: Array.from(typeNames),
|
|
48
|
-
capacity,
|
|
51
|
+
capacity: props.capacity ?? AutoBeConfigConstant.INTERFACE_CAPACITY,
|
|
49
52
|
});
|
|
50
53
|
const progress: AutoBeProgressEventBase = {
|
|
51
54
|
total: typeNames.size,
|
|
@@ -57,39 +60,48 @@ export async function orchestrateInterfaceSchemas<
|
|
|
57
60
|
for (const y of await executeCachedBatch(
|
|
58
61
|
matrix.map((it) => async (promptCacheKey) => {
|
|
59
62
|
const row: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive> =
|
|
60
|
-
await divideAndConquer(ctx,
|
|
63
|
+
await divideAndConquer(ctx, {
|
|
64
|
+
instruction: props.instruction,
|
|
65
|
+
operations: props.operations,
|
|
66
|
+
typeNames: it,
|
|
67
|
+
progress,
|
|
68
|
+
promptCacheKey,
|
|
69
|
+
});
|
|
61
70
|
return row;
|
|
62
71
|
}),
|
|
63
72
|
)) {
|
|
64
|
-
JsonSchemaNamingConvention.schemas(operations, x, y);
|
|
73
|
+
JsonSchemaNamingConvention.schemas(props.operations, x, y);
|
|
65
74
|
Object.assign(x, y);
|
|
66
75
|
}
|
|
67
76
|
Object.assign(x, presets);
|
|
68
|
-
JsonSchemaNamingConvention.schemas(operations, x);
|
|
77
|
+
JsonSchemaNamingConvention.schemas(props.operations, x);
|
|
69
78
|
JsonSchemaFactory.authorize(x);
|
|
70
79
|
return x;
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
74
83
|
ctx: AutoBeContext<Model>,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
props: {
|
|
85
|
+
operations: AutoBeOpenApi.IOperation[];
|
|
86
|
+
typeNames: string[];
|
|
87
|
+
progress: AutoBeProgressEventBase;
|
|
88
|
+
promptCacheKey: string;
|
|
89
|
+
instruction: string;
|
|
90
|
+
},
|
|
79
91
|
): Promise<Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>> {
|
|
80
|
-
const remained: Set<string> = new Set(typeNames);
|
|
92
|
+
const remained: Set<string> = new Set(props.typeNames);
|
|
81
93
|
const schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive> = {};
|
|
82
94
|
for (let i: number = 0; i < ctx.retry; ++i) {
|
|
83
95
|
if (remained.size === 0) break;
|
|
84
96
|
const newbie: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive> =
|
|
85
|
-
await process(
|
|
86
|
-
|
|
87
|
-
operations,
|
|
88
|
-
|
|
97
|
+
await process(ctx, {
|
|
98
|
+
instruction: props.instruction,
|
|
99
|
+
operations: props.operations,
|
|
100
|
+
promptCacheKey: props.promptCacheKey,
|
|
101
|
+
progress: props.progress,
|
|
102
|
+
oldbie: schemas,
|
|
89
103
|
remained,
|
|
90
|
-
|
|
91
|
-
promptCacheKey,
|
|
92
|
-
);
|
|
104
|
+
});
|
|
93
105
|
for (const key of Object.keys(newbie)) {
|
|
94
106
|
schemas[key] = newbie[key];
|
|
95
107
|
remained.delete(key);
|
|
@@ -100,13 +112,16 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
|
100
112
|
|
|
101
113
|
async function process<Model extends ILlmSchema.Model>(
|
|
102
114
|
ctx: AutoBeContext<Model>,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
props: {
|
|
116
|
+
operations: AutoBeOpenApi.IOperation[];
|
|
117
|
+
oldbie: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>;
|
|
118
|
+
remained: Set<string>;
|
|
119
|
+
progress: AutoBeProgressEventBase;
|
|
120
|
+
promptCacheKey: string;
|
|
121
|
+
instruction: string;
|
|
122
|
+
},
|
|
108
123
|
): Promise<Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>> {
|
|
109
|
-
const already: string[] = Object.keys(oldbie);
|
|
124
|
+
const already: string[] = Object.keys(props.oldbie);
|
|
110
125
|
const pointer: IPointer<Record<
|
|
111
126
|
string,
|
|
112
127
|
AutoBeOpenApi.IJsonSchemaDescriptive
|
|
@@ -115,7 +130,11 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
115
130
|
};
|
|
116
131
|
const { tokenUsage } = await ctx.conversate({
|
|
117
132
|
source: "interfaceSchemas",
|
|
118
|
-
histories: transformInterfaceSchemaHistories(
|
|
133
|
+
histories: transformInterfaceSchemaHistories({
|
|
134
|
+
state: ctx.state(),
|
|
135
|
+
operations: props.operations,
|
|
136
|
+
instruction: props.instruction,
|
|
137
|
+
}),
|
|
119
138
|
controller: createController({
|
|
120
139
|
model: ctx.model,
|
|
121
140
|
build: async (next) => {
|
|
@@ -125,7 +144,7 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
125
144
|
pointer,
|
|
126
145
|
}),
|
|
127
146
|
enforceFunctionCall: true,
|
|
128
|
-
promptCacheKey,
|
|
147
|
+
promptCacheKey: props.promptCacheKey,
|
|
129
148
|
message: StringUtil.trim`
|
|
130
149
|
Make type components please.
|
|
131
150
|
|
|
@@ -134,7 +153,7 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
134
153
|
types are required during making the components, please make them
|
|
135
154
|
too.
|
|
136
155
|
|
|
137
|
-
${Array.from(remained)
|
|
156
|
+
${Array.from(props.remained)
|
|
138
157
|
.map((k) => ` - \`${k}\``)
|
|
139
158
|
.join("\n")}${
|
|
140
159
|
already.length !== 0
|
|
@@ -161,9 +180,9 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
161
180
|
id: v7(),
|
|
162
181
|
schemas,
|
|
163
182
|
tokenUsage,
|
|
164
|
-
completed: (progress.completed += Object.keys(schemas).length),
|
|
165
|
-
total: (progress.total += Object.keys(schemas).filter(
|
|
166
|
-
(k) => remained.has(k) === false,
|
|
183
|
+
completed: (props.progress.completed += Object.keys(schemas).length),
|
|
184
|
+
total: (props.progress.total += Object.keys(schemas).filter(
|
|
185
|
+
(k) => props.remained.has(k) === false,
|
|
167
186
|
).length),
|
|
168
187
|
step: ctx.state().prisma?.step ?? 0,
|
|
169
188
|
created_at: new Date().toISOString(),
|
|
@@ -8,14 +8,17 @@ import { AutoBeState } from "../../../context/AutoBeState";
|
|
|
8
8
|
|
|
9
9
|
export const transformPrismaComponentsHistories = (
|
|
10
10
|
state: AutoBeState,
|
|
11
|
-
|
|
11
|
+
props: {
|
|
12
|
+
prefix: string | null;
|
|
13
|
+
instruction: string;
|
|
14
|
+
},
|
|
12
15
|
): Array<
|
|
13
16
|
IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
|
|
14
17
|
> => {
|
|
15
18
|
if (state.analyze === null)
|
|
16
19
|
// unreachable
|
|
17
20
|
throw new Error("Analyze state is not set.");
|
|
18
|
-
if (prefix) prefix = NamingConvention.snake(prefix);
|
|
21
|
+
if (props.prefix) props.prefix = NamingConvention.snake(props.prefix);
|
|
19
22
|
return [
|
|
20
23
|
{
|
|
21
24
|
id: v7(),
|
|
@@ -28,20 +31,20 @@ export const transformPrismaComponentsHistories = (
|
|
|
28
31
|
created_at: new Date().toISOString(),
|
|
29
32
|
type: "assistantMessage",
|
|
30
33
|
text: StringUtil.trim`
|
|
34
|
+
## Requirement Analysis Report
|
|
35
|
+
|
|
31
36
|
Here is the requirement analysis report.
|
|
32
37
|
|
|
33
38
|
Call the provided tool function to generate Prisma DB schema
|
|
34
39
|
referencing below requirement analysis report.
|
|
35
40
|
|
|
36
|
-
## Requirement Analysis Report
|
|
37
|
-
|
|
38
41
|
\`\`\`json
|
|
39
42
|
${JSON.stringify(state.analyze.files)}
|
|
40
43
|
\`\`\`
|
|
41
44
|
|
|
42
45
|
## Prefix
|
|
43
46
|
|
|
44
|
-
- Prefix provided by the user: ${prefix}
|
|
47
|
+
- Prefix provided by the user: ${props.prefix}
|
|
45
48
|
|
|
46
49
|
The user wants all database schema (table) names to start with the prefix provided below.
|
|
47
50
|
|
|
@@ -74,11 +77,22 @@ export const transformPrismaComponentsHistories = (
|
|
|
74
77
|
Create separate tables for each role:
|
|
75
78
|
|
|
76
79
|
${state.analyze.roles
|
|
77
|
-
.map((role) => `- ${prefix}_${role.name.toLowerCase()}`)
|
|
80
|
+
.map((role) => `- ${props.prefix}_${role.name.toLowerCase()}`)
|
|
78
81
|
.join("\n")}
|
|
79
82
|
`
|
|
80
83
|
: ""
|
|
81
84
|
}
|
|
85
|
+
|
|
86
|
+
## Database Design Instructions
|
|
87
|
+
|
|
88
|
+
The following database-specific instructions were extracted by AI from
|
|
89
|
+
the user's utterances. These focus ONLY on database schema design aspects
|
|
90
|
+
such as table structure, relationships, constraints, and indexing strategies.
|
|
91
|
+
|
|
92
|
+
Reference these instructions when designing namespace components and
|
|
93
|
+
DB table names.
|
|
94
|
+
|
|
95
|
+
${props.instruction}
|
|
82
96
|
`,
|
|
83
97
|
},
|
|
84
98
|
];
|
|
@@ -5,11 +5,12 @@ import { v7 } from "uuid";
|
|
|
5
5
|
|
|
6
6
|
import { AutoBeSystemPromptConstant } from "../../../constants/AutoBeSystemPromptConstant";
|
|
7
7
|
|
|
8
|
-
export const transformPrismaSchemaHistories = (
|
|
9
|
-
|
|
10
|
-
targetComponent: AutoBePrisma.IComponent
|
|
11
|
-
otherTables: string[]
|
|
12
|
-
|
|
8
|
+
export const transformPrismaSchemaHistories = (props: {
|
|
9
|
+
analysis: Record<string, string>;
|
|
10
|
+
targetComponent: AutoBePrisma.IComponent;
|
|
11
|
+
otherTables: string[];
|
|
12
|
+
instruction: string;
|
|
13
|
+
}): Array<
|
|
13
14
|
IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
|
|
14
15
|
> => {
|
|
15
16
|
return [
|
|
@@ -27,7 +28,7 @@ export const transformPrismaSchemaHistories = (
|
|
|
27
28
|
Here is the requirement analysis report:
|
|
28
29
|
|
|
29
30
|
\`\`\`json
|
|
30
|
-
${JSON.stringify(
|
|
31
|
+
${JSON.stringify(props.analysis)}
|
|
31
32
|
\`\`\`
|
|
32
33
|
`,
|
|
33
34
|
},
|
|
@@ -36,12 +37,26 @@ export const transformPrismaSchemaHistories = (
|
|
|
36
37
|
created_at: new Date().toISOString(),
|
|
37
38
|
type: "assistantMessage",
|
|
38
39
|
text: StringUtil.trim`
|
|
40
|
+
## Database Design Instructions
|
|
41
|
+
|
|
42
|
+
The following database-specific instructions were extracted by AI from
|
|
43
|
+
the user's utterances. These focus ONLY on database schema design aspects
|
|
44
|
+
such as table structure, relationships, constraints, and indexing strategies.
|
|
45
|
+
|
|
46
|
+
Reference these instructions when designing the DB schema for this specific
|
|
47
|
+
component. If the instruction is not related to the current domain or
|
|
48
|
+
component, you may ignore it.
|
|
49
|
+
|
|
50
|
+
${props.instruction}
|
|
51
|
+
|
|
52
|
+
## Target Component
|
|
53
|
+
|
|
39
54
|
Here is the input data for generating Prisma DB schema.
|
|
40
55
|
|
|
41
56
|
\`\`\`json
|
|
42
57
|
${JSON.stringify({
|
|
43
|
-
targetComponent,
|
|
44
|
-
otherTables,
|
|
58
|
+
targetComponent: props.targetComponent,
|
|
59
|
+
otherTables: props.otherTables,
|
|
45
60
|
})}
|
|
46
61
|
\`\`\`
|
|
47
62
|
`,
|
|
@@ -58,7 +73,7 @@ export const transformPrismaSchemaHistories = (
|
|
|
58
73
|
|
|
59
74
|
\`\`\`json
|
|
60
75
|
${JSON.stringify({
|
|
61
|
-
targetComponent,
|
|
76
|
+
targetComponent: props.targetComponent,
|
|
62
77
|
})}
|
|
63
78
|
\`\`\`
|
|
64
79
|
`,
|
|
@@ -39,18 +39,22 @@ export const orchestratePrisma = async <Model extends ILlmSchema.Model>(
|
|
|
39
39
|
type: "prismaStart",
|
|
40
40
|
id: v7(),
|
|
41
41
|
created_at: start.toISOString(),
|
|
42
|
-
reason: props.
|
|
42
|
+
reason: props.instruction,
|
|
43
43
|
step: ctx.state().analyze?.step ?? 0,
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
// COMPONENTS
|
|
47
47
|
const componentEvent: AutoBePrismaComponentsEvent =
|
|
48
|
-
await orchestratePrismaComponents(ctx);
|
|
48
|
+
await orchestratePrismaComponents(ctx, props.instruction);
|
|
49
49
|
ctx.dispatch(componentEvent);
|
|
50
50
|
|
|
51
51
|
// CONSTRUCT AST DATA
|
|
52
52
|
const schemaEvents: AutoBePrismaSchemasEvent[] =
|
|
53
|
-
await orchestratePrismaSchemas(
|
|
53
|
+
await orchestratePrismaSchemas(
|
|
54
|
+
ctx,
|
|
55
|
+
props.instruction,
|
|
56
|
+
componentEvent.components,
|
|
57
|
+
);
|
|
54
58
|
const application: AutoBePrisma.IApplication = {
|
|
55
59
|
files: schemaEvents.map((e) => e.file),
|
|
56
60
|
};
|
|
@@ -14,6 +14,7 @@ export async function orchestratePrismaComponents<
|
|
|
14
14
|
Model extends ILlmSchema.Model,
|
|
15
15
|
>(
|
|
16
16
|
ctx: AutoBeContext<Model>,
|
|
17
|
+
instruction: string,
|
|
17
18
|
message: string = "Design database from the given requirement analysis documents.",
|
|
18
19
|
): Promise<AutoBePrismaComponentsEvent> {
|
|
19
20
|
const start: Date = new Date();
|
|
@@ -23,7 +24,10 @@ export async function orchestratePrismaComponents<
|
|
|
23
24
|
const prefix: string | null = ctx.state().analyze?.prefix ?? null;
|
|
24
25
|
const { tokenUsage } = await ctx.conversate({
|
|
25
26
|
source: "prismaComponents",
|
|
26
|
-
histories: transformPrismaComponentsHistories(ctx.state(),
|
|
27
|
+
histories: transformPrismaComponentsHistories(ctx.state(), {
|
|
28
|
+
prefix,
|
|
29
|
+
instruction,
|
|
30
|
+
}),
|
|
27
31
|
controller: createController({
|
|
28
32
|
model: ctx.model,
|
|
29
33
|
build: (next) => {
|
|
@@ -15,6 +15,7 @@ import { IAutoBePrismaSchemaApplication } from "./structures/IAutoBePrismaSchema
|
|
|
15
15
|
|
|
16
16
|
export async function orchestratePrismaSchemas<Model extends ILlmSchema.Model>(
|
|
17
17
|
ctx: AutoBeContext<Model>,
|
|
18
|
+
instruction: string,
|
|
18
19
|
componentList: AutoBePrisma.IComponent[],
|
|
19
20
|
): Promise<AutoBePrismaSchemasEvent[]> {
|
|
20
21
|
const start: Date = new Date();
|
|
@@ -29,6 +30,7 @@ export async function orchestratePrismaSchemas<Model extends ILlmSchema.Model>(
|
|
|
29
30
|
.map((c) => c.tables)
|
|
30
31
|
.flat();
|
|
31
32
|
const event: AutoBePrismaSchemasEvent = await process(ctx, {
|
|
33
|
+
instruction,
|
|
32
34
|
component,
|
|
33
35
|
otherTables,
|
|
34
36
|
start,
|
|
@@ -45,6 +47,7 @@ export async function orchestratePrismaSchemas<Model extends ILlmSchema.Model>(
|
|
|
45
47
|
async function process<Model extends ILlmSchema.Model>(
|
|
46
48
|
ctx: AutoBeContext<Model>,
|
|
47
49
|
props: {
|
|
50
|
+
instruction: string;
|
|
48
51
|
component: AutoBePrisma.IComponent;
|
|
49
52
|
otherTables: string[];
|
|
50
53
|
start: Date;
|
|
@@ -58,16 +61,18 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
58
61
|
};
|
|
59
62
|
const { tokenUsage } = await ctx.conversate({
|
|
60
63
|
source: "prismaSchemas",
|
|
61
|
-
histories: transformPrismaSchemaHistories(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
props.
|
|
70
|
-
|
|
64
|
+
histories: transformPrismaSchemaHistories({
|
|
65
|
+
analysis:
|
|
66
|
+
ctx
|
|
67
|
+
.state()
|
|
68
|
+
.analyze?.files.map((file) => ({ [file.filename]: file.content }))
|
|
69
|
+
.reduce((acc, cur) => {
|
|
70
|
+
return Object.assign(acc, cur);
|
|
71
|
+
}, {}) ?? {},
|
|
72
|
+
targetComponent: props.component,
|
|
73
|
+
otherTables: props.otherTables,
|
|
74
|
+
instruction: props.instruction,
|
|
75
|
+
}),
|
|
71
76
|
controller: createController(ctx, {
|
|
72
77
|
targetComponent: props.component,
|
|
73
78
|
otherTables: props.otherTables,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IAgenticaHistoryJson } from "@agentica/core";
|
|
2
|
+
import { IAutoBeTypeScriptCompileResult } from "@autobe/interface";
|
|
3
|
+
import { StringUtil } from "@autobe/utils";
|
|
4
|
+
import { v7 } from "uuid";
|
|
5
|
+
|
|
6
|
+
import { AutoBeSystemPromptConstant } from "../../../constants/AutoBeSystemPromptConstant";
|
|
7
|
+
|
|
8
|
+
interface IFailure {
|
|
9
|
+
diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[];
|
|
10
|
+
script: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const transformRealizeCorrectCastingHistories = (
|
|
14
|
+
failures: IFailure[],
|
|
15
|
+
): Array<
|
|
16
|
+
IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
|
|
17
|
+
> => {
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
id: v7(),
|
|
21
|
+
created_at: new Date().toISOString(),
|
|
22
|
+
type: "systemMessage",
|
|
23
|
+
text: AutoBeSystemPromptConstant.REALIZE_CORRECT_CASTING,
|
|
24
|
+
},
|
|
25
|
+
...failures.map(
|
|
26
|
+
(f, i, array) =>
|
|
27
|
+
({
|
|
28
|
+
id: v7(),
|
|
29
|
+
created_at: new Date().toISOString(),
|
|
30
|
+
type: "assistantMessage",
|
|
31
|
+
text: StringUtil.trim`
|
|
32
|
+
# ${i === array.length - 1 ? "Latest Failure" : "Previous Failure"}
|
|
33
|
+
## Generated TypeScript Code
|
|
34
|
+
\`\`\`typescript
|
|
35
|
+
${f.script}
|
|
36
|
+
\`\`\`
|
|
37
|
+
## Compile Errors
|
|
38
|
+
\`\`\`json
|
|
39
|
+
${JSON.stringify(f.diagnostics)}
|
|
40
|
+
\`\`\`
|
|
41
|
+
`,
|
|
42
|
+
}) satisfies IAgenticaHistoryJson.IAssistantMessage,
|
|
43
|
+
),
|
|
44
|
+
];
|
|
45
|
+
};
|
|
@@ -14,8 +14,8 @@ import { v7 } from "uuid";
|
|
|
14
14
|
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
15
15
|
import { assertSchemaModel } from "../../context/assertSchemaModel";
|
|
16
16
|
import { executeCachedBatch } from "../../utils/executeCachedBatch";
|
|
17
|
-
import { transformCommonCorrectCastingHistories } from "../common/histories/transformCommonCorrectCastingHistories";
|
|
18
17
|
import { IAutoBeCommonCorrectCastingApplication } from "../common/structures/IAutoBeCommonCorrectCastingApplication";
|
|
18
|
+
import { transformRealizeCorrectCastingHistories } from "./histories/transformRealizeCorrectCastingHistories";
|
|
19
19
|
import { compileRealizeFiles } from "./internal/compileRealizeFiles";
|
|
20
20
|
|
|
21
21
|
/** Result of attempting to correct a single function */
|
|
@@ -94,6 +94,12 @@ const correct = async <Model extends ILlmSchema.Model>(
|
|
|
94
94
|
const locations: string[] = diagnose(event).filter((l) =>
|
|
95
95
|
functions.map((f) => f.location).includes(l),
|
|
96
96
|
);
|
|
97
|
+
|
|
98
|
+
// If no locations to correct, return original functions
|
|
99
|
+
if (locations.length === 0) {
|
|
100
|
+
return functions;
|
|
101
|
+
}
|
|
102
|
+
|
|
97
103
|
progress.total += locations.length;
|
|
98
104
|
|
|
99
105
|
const converted: CorrectionResult[] = await executeCachedBatch(
|
|
@@ -110,7 +116,7 @@ const correct = async <Model extends ILlmSchema.Model>(
|
|
|
110
116
|
|
|
111
117
|
const { tokenUsage } = await ctx.conversate({
|
|
112
118
|
source: "realizeCorrect",
|
|
113
|
-
histories:
|
|
119
|
+
histories: transformRealizeCorrectCastingHistories([
|
|
114
120
|
{
|
|
115
121
|
script: func.content,
|
|
116
122
|
diagnostics: failures.filter((d) => d.file === location),
|
|
@@ -172,7 +178,18 @@ const correct = async <Model extends ILlmSchema.Model>(
|
|
|
172
178
|
},
|
|
173
179
|
);
|
|
174
180
|
|
|
175
|
-
|
|
181
|
+
const newResult: IAutoBeTypeScriptCompileResult = newValidate.result;
|
|
182
|
+
if (newResult.type === "success") {
|
|
183
|
+
return converted.map((c) => c.func);
|
|
184
|
+
} else if (newResult.type === "exception") {
|
|
185
|
+
// Compilation exception, return current functions. because retrying won't help.
|
|
186
|
+
return functions;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (
|
|
190
|
+
newResult.diagnostics.every((d) => !d.file?.startsWith("src/providers"))
|
|
191
|
+
) {
|
|
192
|
+
// No diagnostics related to provider functions, stop correcting
|
|
176
193
|
return converted.map((c) => c.func);
|
|
177
194
|
}
|
|
178
195
|
|
|
@@ -193,9 +210,7 @@ const correct = async <Model extends ILlmSchema.Model>(
|
|
|
193
210
|
const failedLocations: string[] = failed.map((f) => f.location);
|
|
194
211
|
const allDiagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[] = [
|
|
195
212
|
...failures,
|
|
196
|
-
...(
|
|
197
|
-
? newValidate.result.diagnostics
|
|
198
|
-
: []),
|
|
213
|
+
...(newResult.type === "failure" ? newResult.diagnostics : []),
|
|
199
214
|
];
|
|
200
215
|
const relevantDiagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[] =
|
|
201
216
|
filterRelevantDiagnostics(allDiagnostics, failedLocations);
|
|
@@ -211,7 +226,11 @@ const correct = async <Model extends ILlmSchema.Model>(
|
|
|
211
226
|
life - 1,
|
|
212
227
|
);
|
|
213
228
|
|
|
214
|
-
|
|
229
|
+
// Get functions that were not modified (not in converted array)
|
|
230
|
+
const convertedLocations = converted.map(c => c.func.location);
|
|
231
|
+
const unchanged = functions.filter(f => !convertedLocations.includes(f.location));
|
|
232
|
+
|
|
233
|
+
return [...success, ...ignored, ...retriedFunctions, ...unchanged];
|
|
215
234
|
};
|
|
216
235
|
|
|
217
236
|
/**
|