@autobe/agent 0.9.2 → 0.10.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 +11 -4
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +6 -6
- package/lib/context/AutoBeTokenUsage.d.ts +15 -1
- package/lib/context/AutoBeTokenUsage.js +56 -1
- package/lib/context/AutoBeTokenUsage.js.map +1 -1
- package/lib/factory/createAutoBeApplication.js +288 -643
- package/lib/factory/createAutoBeApplication.js.map +1 -1
- package/lib/index.mjs +5057 -7211
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +82 -319
- package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js +0 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyze.js +95 -266
- package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
- package/lib/orchestrate/facade/transformFacadeStateMessage.js +2 -2
- package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +1 -1
- package/lib/orchestrate/index.d.ts +2 -2
- package/lib/orchestrate/index.js +4 -4
- package/lib/orchestrate/index.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +56 -142
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +195 -199
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +75 -172
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +772 -1097
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
- package/lib/orchestrate/interface/transformInterfaceHistories.js +2 -0
- package/lib/orchestrate/interface/transformInterfaceHistories.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js +64 -175
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +552 -1073
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaSchema.js +571 -1119
- package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -1
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +9 -0
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +8 -0
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealize.d.ts +11 -0
- package/lib/orchestrate/realize/orchestrateRealize.js +109 -0
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +25 -0
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js +337 -0
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealizeIntegrator.d.ts +52 -0
- package/lib/orchestrate/realize/orchestrateRealizeIntegrator.js +57 -0
- package/lib/orchestrate/realize/orchestrateRealizeIntegrator.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealizePlanner.d.ts +80 -0
- package/lib/orchestrate/realize/orchestrateRealizePlanner.js +53 -0
- package/lib/orchestrate/realize/orchestrateRealizePlanner.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealizeValidator.d.ts +46 -0
- package/lib/orchestrate/realize/orchestrateRealizeValidator.js +37 -0
- package/lib/orchestrate/realize/orchestrateRealizeValidator.js.map +1 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +33 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.js +3 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.js.map +1 -0
- package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +5 -0
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js +127 -0
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -0
- package/lib/orchestrate/test/compile/completeTestCode.d.ts +2 -0
- package/lib/orchestrate/test/compile/completeTestCode.js +21 -0
- package/lib/orchestrate/test/compile/completeTestCode.js.map +1 -0
- package/lib/orchestrate/test/{filterTestFileName.js → compile/filterTestFileName.js} +1 -1
- package/lib/orchestrate/test/compile/filterTestFileName.js.map +1 -0
- package/lib/orchestrate/test/compile/getTestExternalDeclarations.d.ts +3 -0
- package/lib/orchestrate/test/compile/getTestExternalDeclarations.js +27 -0
- package/lib/orchestrate/test/compile/getTestExternalDeclarations.js.map +1 -0
- package/lib/orchestrate/test/compile/getTestScenarioArtifacts.d.ts +5 -0
- package/lib/orchestrate/test/{compileTestScenario.js → compile/getTestScenarioArtifacts.js} +10 -5
- package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -0
- package/lib/orchestrate/test/orchestrateTest.js +14 -9
- package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +3 -2
- package/lib/orchestrate/test/orchestrateTestCorrect.js +150 -448
- package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.js +272 -530
- package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestWrite.d.ts +3 -2
- package/lib/orchestrate/test/orchestrateTestWrite.js +139 -90
- package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
- package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.d.ts +121 -0
- package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.js +3 -0
- package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.js.map +1 -0
- package/lib/orchestrate/test/structures/IAutoBeTestFunction.d.ts +8 -0
- package/lib/{utils/types/BackoffOptions.js → orchestrate/test/structures/IAutoBeTestFunction.js} +1 -1
- package/lib/orchestrate/test/structures/IAutoBeTestFunction.js.map +1 -0
- package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +14 -2
- package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.d.ts +112 -0
- package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.js +3 -0
- package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.js.map +1 -0
- package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.d.ts +7 -0
- package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.js +3 -0
- package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.js.map +1 -0
- package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +3 -2
- package/lib/orchestrate/test/transformTestCorrectHistories.js +28 -67
- package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
- package/lib/orchestrate/test/transformTestWriteHistories.d.ts +5 -4
- package/lib/orchestrate/test/transformTestWriteHistories.js +168 -43
- package/lib/orchestrate/test/transformTestWriteHistories.js.map +1 -1
- package/lib/structures/IAutoBeConfig.d.ts +11 -0
- package/lib/utils/backoffRetry.d.ts +4 -7
- package/lib/utils/backoffRetry.js +19 -37
- package/lib/utils/backoffRetry.js.map +1 -1
- package/lib/utils/forceRetry.d.ts +1 -0
- package/lib/{orchestrate/orchestrateRealize.js → utils/forceRetry.js} +15 -8
- package/lib/utils/forceRetry.js.map +1 -0
- package/package.json +8 -7
- package/src/AutoBeAgent.ts +17 -3
- package/src/constants/AutoBeSystemPromptConstant.ts +6 -6
- package/src/context/AutoBeTokenUsage.ts +85 -1
- package/src/factory/createAutoBeApplication.ts +2 -3
- package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +8 -3
- package/src/orchestrate/analyze/AutoBeAnalyzeReviewer.ts +0 -1
- package/src/orchestrate/analyze/orchestrateAnalyze.ts +6 -5
- package/src/orchestrate/facade/transformFacadeStateMessage.ts +2 -1
- package/src/orchestrate/index.ts +2 -2
- package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +4 -3
- package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +26 -23
- package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +6 -4
- package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +14 -11
- package/src/orchestrate/interface/transformInterfaceHistories.ts +2 -0
- package/src/orchestrate/prisma/orchestratePrismaComponent.ts +10 -5
- package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +11 -5
- package/src/orchestrate/prisma/orchestratePrismaSchema.ts +16 -8
- package/src/orchestrate/prisma/transformPrismaComponentsHistories.ts +9 -0
- package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +8 -0
- package/src/orchestrate/realize/orchestrateRealize.ts +169 -0
- package/src/orchestrate/realize/orchestrateRealizeCoder.ts +156 -0
- package/src/orchestrate/realize/orchestrateRealizeIntegrator.ts +75 -0
- package/src/orchestrate/realize/orchestrateRealizePlanner.ts +115 -0
- package/src/orchestrate/realize/orchestrateRealizeValidator.ts +64 -0
- package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +36 -0
- package/src/orchestrate/realize/transformRealizeCoderHistories.ts +136 -0
- package/src/orchestrate/test/compile/completeTestCode.ts +35 -0
- package/src/orchestrate/test/{filterTestFileName.ts → compile/filterTestFileName.ts} +1 -1
- package/src/orchestrate/test/compile/getTestExternalDeclarations.ts +24 -0
- package/src/orchestrate/test/{compileTestScenario.ts → compile/getTestScenarioArtifacts.ts} +16 -8
- package/src/orchestrate/test/experimental/orchestrateTestCorrect.ast +240 -0
- package/src/orchestrate/test/experimental/orchestrateTestWrite.ast +316 -0
- package/src/orchestrate/test/experimental/transformTestCorrectHistories.ast +52 -0
- package/src/orchestrate/test/orchestrateTest.ts +33 -16
- package/src/orchestrate/test/orchestrateTestCorrect.ts +109 -497
- package/src/orchestrate/test/orchestrateTestScenario.ts +102 -71
- package/src/orchestrate/test/orchestrateTestWrite.ts +55 -181
- package/src/orchestrate/test/structures/IAutoBeTestCorrectApplication.ts +126 -0
- package/src/orchestrate/test/structures/IAutoBeTestFunction.ts +10 -0
- package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +14 -2
- package/src/orchestrate/test/structures/IAutoBeTestWriteApplication.ts +117 -0
- package/src/orchestrate/test/structures/IAutoBeTestWriteResult.ts +9 -0
- package/src/orchestrate/test/transformTestCorrectHistories.ts +38 -71
- package/src/orchestrate/test/transformTestWriteHistories.ts +88 -46
- package/src/structures/IAutoBeConfig.ts +9 -0
- package/src/utils/backoffRetry.ts +25 -36
- package/src/utils/forceRetry.ts +13 -0
- package/lib/factory/invertOpenApiDocument.d.ts +0 -3
- package/lib/factory/invertOpenApiDocument.js +0 -51
- package/lib/factory/invertOpenApiDocument.js.map +0 -1
- package/lib/orchestrate/orchestrateRealize.d.ts +0 -5
- package/lib/orchestrate/orchestrateRealize.js.map +0 -1
- package/lib/orchestrate/test/compileTestScenario.d.ts +0 -5
- package/lib/orchestrate/test/compileTestScenario.js.map +0 -1
- package/lib/orchestrate/test/filterTestFileName.js.map +0 -1
- package/lib/utils/StringUtil.d.ts +0 -4
- package/lib/utils/StringUtil.js +0 -43
- package/lib/utils/StringUtil.js.map +0 -1
- package/lib/utils/types/BackoffOptions.d.ts +0 -12
- package/lib/utils/types/BackoffOptions.js.map +0 -1
- package/src/factory/invertOpenApiDocument.ts +0 -63
- package/src/orchestrate/orchestrateRealize.ts +0 -18
- package/src/utils/StringUtil.ts +0 -45
- package/src/utils/types/BackoffOptions.ts +0 -15
- /package/lib/orchestrate/test/{filterTestFileName.d.ts → compile/filterTestFileName.d.ts} +0 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgenticaSystemPrompt,
|
|
3
|
+
IAgenticaController,
|
|
4
|
+
MicroAgentica,
|
|
5
|
+
} from "@agentica/core";
|
|
6
|
+
import {
|
|
7
|
+
AutoBeOpenApi,
|
|
8
|
+
AutoBeTest,
|
|
9
|
+
AutoBeTestScenario,
|
|
10
|
+
AutoBeTestWriteEvent,
|
|
11
|
+
} from "@autobe/interface";
|
|
12
|
+
import {
|
|
13
|
+
AutoBeEndpointComparator,
|
|
14
|
+
IAutoBeTextValidateContext,
|
|
15
|
+
validateTestFunction,
|
|
16
|
+
} from "@autobe/utils";
|
|
17
|
+
import {
|
|
18
|
+
ILlmApplication,
|
|
19
|
+
ILlmSchema,
|
|
20
|
+
IValidation,
|
|
21
|
+
OpenApi,
|
|
22
|
+
OpenApiTypeChecker,
|
|
23
|
+
} from "@samchon/openapi";
|
|
24
|
+
import { HashMap, IPointer, Pair } from "tstl";
|
|
25
|
+
import typia, { IJsonSchemaUnit } from "typia";
|
|
26
|
+
|
|
27
|
+
import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
|
|
28
|
+
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
29
|
+
import { assertSchemaModel } from "../../context/assertSchemaModel";
|
|
30
|
+
import { enforceToolCall } from "../../utils/enforceToolCall";
|
|
31
|
+
import { compileTestScenario } from "./compile/compileTestScenario";
|
|
32
|
+
import { IAutoBeTestScenarioArtifacts } from "./structures/IAutoBeTestScenarioArtifacts";
|
|
33
|
+
import { IAutoBeTestWriteResult } from "./structures/IAutoBeTestWriteResult";
|
|
34
|
+
import { transformTestWriteHistories } from "./transformTestWriteHistories";
|
|
35
|
+
|
|
36
|
+
export async function orchestrateTestWrite<Model extends ILlmSchema.Model>(
|
|
37
|
+
ctx: AutoBeContext<Model>,
|
|
38
|
+
scenarios: AutoBeTestScenario[],
|
|
39
|
+
life: number = 4,
|
|
40
|
+
): Promise<IAutoBeTestWriteResult[]> {
|
|
41
|
+
const start: Date = new Date();
|
|
42
|
+
let complete: number = 0;
|
|
43
|
+
|
|
44
|
+
const writes: Array<IAutoBeTestWriteResult | null> = await Promise.all(
|
|
45
|
+
/**
|
|
46
|
+
* Generate test code for each scenario. Maps through plans array to create
|
|
47
|
+
* individual test code implementations. Each scenario is processed to
|
|
48
|
+
* generate corresponding test code and progress events.
|
|
49
|
+
*/
|
|
50
|
+
scenarios.map(
|
|
51
|
+
async (
|
|
52
|
+
scenario: AutoBeTestScenario,
|
|
53
|
+
): Promise<IAutoBeTestWriteResult | null> => {
|
|
54
|
+
const artifacts: IAutoBeTestScenarioArtifacts =
|
|
55
|
+
await compileTestScenario(ctx, scenario);
|
|
56
|
+
const result: ICreateTestCodeProps | null = await (async () => {
|
|
57
|
+
try {
|
|
58
|
+
return await process(ctx, scenario, artifacts, life, null);
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
if (result === null) return null;
|
|
64
|
+
|
|
65
|
+
const event: AutoBeTestWriteEvent = {
|
|
66
|
+
type: "testWrite",
|
|
67
|
+
created_at: start.toISOString(),
|
|
68
|
+
file: {
|
|
69
|
+
location: `test/features/api/${result.domain}/${scenario.functionName}.ts`,
|
|
70
|
+
function: result.function,
|
|
71
|
+
content: await ctx.compiler.test.write({
|
|
72
|
+
scenario,
|
|
73
|
+
document: ctx.state().interface!.document,
|
|
74
|
+
function: result.function,
|
|
75
|
+
}),
|
|
76
|
+
scenario,
|
|
77
|
+
},
|
|
78
|
+
completed: ++complete,
|
|
79
|
+
total: scenarios.length,
|
|
80
|
+
step: ctx.state().interface?.step ?? 0,
|
|
81
|
+
};
|
|
82
|
+
ctx.dispatch(event);
|
|
83
|
+
return {
|
|
84
|
+
artifacts,
|
|
85
|
+
file: event.file,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
return writes.filter((w) => w !== null);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Process function that generates test code for each individual scenario. Takes
|
|
95
|
+
* the AutoBeContext and scenario information as input and uses MicroAgentica to
|
|
96
|
+
* generate appropriate test code through LLM interaction.
|
|
97
|
+
*
|
|
98
|
+
* @param ctx - The AutoBeContext containing model, vendor and configuration
|
|
99
|
+
* @param scenario - The test scenario information to generate code for
|
|
100
|
+
* @param artifacts - The artifacts containing the reference files and schemas
|
|
101
|
+
* @returns Promise resolving to ICreateTestCodeProps containing the generated
|
|
102
|
+
* test code
|
|
103
|
+
*/
|
|
104
|
+
async function process<Model extends ILlmSchema.Model>(
|
|
105
|
+
ctx: AutoBeContext<Model>,
|
|
106
|
+
scenario: AutoBeTestScenario,
|
|
107
|
+
artifacts: IAutoBeTestScenarioArtifacts,
|
|
108
|
+
life: number,
|
|
109
|
+
failure: IValidation.IFailure | null,
|
|
110
|
+
): Promise<ICreateTestCodeProps | null> {
|
|
111
|
+
// function calling
|
|
112
|
+
const trials: IValidation.IFailure[] = [];
|
|
113
|
+
const pointer: IPointer<ICreateTestCodeProps | null> = {
|
|
114
|
+
value: null,
|
|
115
|
+
};
|
|
116
|
+
const agentica = new MicroAgentica({
|
|
117
|
+
model: ctx.model,
|
|
118
|
+
vendor: ctx.vendor,
|
|
119
|
+
config: {
|
|
120
|
+
...(ctx.config ?? {}),
|
|
121
|
+
executor: {
|
|
122
|
+
describe: null,
|
|
123
|
+
},
|
|
124
|
+
systemPrompt: {
|
|
125
|
+
validate: (events) =>
|
|
126
|
+
[
|
|
127
|
+
AgenticaSystemPrompt.VALIDATE_REPEATED.replace(
|
|
128
|
+
"${{HISTORICAL_ERRORS}}",
|
|
129
|
+
JSON.stringify(events.map((e) => e.result.errors)),
|
|
130
|
+
),
|
|
131
|
+
AutoBeSystemPromptConstant.TEST_VALIDATE.replace(
|
|
132
|
+
"${{AutoBeTest.IStatement}}",
|
|
133
|
+
getUnionTypeName(typia.json.schema<AutoBeTest.IStatement>()),
|
|
134
|
+
).replace(
|
|
135
|
+
"${{AutoBeTest.IExpression}}",
|
|
136
|
+
getUnionTypeName(typia.json.schema<AutoBeTest.IExpression>()),
|
|
137
|
+
),
|
|
138
|
+
].join("\n\n"),
|
|
139
|
+
},
|
|
140
|
+
retry: 4,
|
|
141
|
+
},
|
|
142
|
+
histories: transformTestWriteHistories({
|
|
143
|
+
scenario,
|
|
144
|
+
artifacts,
|
|
145
|
+
failure,
|
|
146
|
+
}),
|
|
147
|
+
controllers: [
|
|
148
|
+
createApplication({
|
|
149
|
+
model: ctx.model,
|
|
150
|
+
document: ctx.state().interface!.document,
|
|
151
|
+
build: (next) => {
|
|
152
|
+
pointer.value = next;
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
enforceToolCall(agentica);
|
|
158
|
+
agentica.on("validate", (e) => {
|
|
159
|
+
trials.push(e.result);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
await agentica.conversate("Create e2e test functions.").finally(() => {
|
|
163
|
+
const tokenUsage = agentica.getTokenUsage();
|
|
164
|
+
ctx.usage().record(tokenUsage, ["test"]);
|
|
165
|
+
});
|
|
166
|
+
if (pointer.value === null) {
|
|
167
|
+
console.log(
|
|
168
|
+
"failed to pass validation",
|
|
169
|
+
(trials.at(-1)?.data as ICreateTestCodeProps | undefined)?.function.draft,
|
|
170
|
+
trials.map((t) => t.errors.map((e) => e.path)),
|
|
171
|
+
JSON.stringify(trials.at(-1), null, 2),
|
|
172
|
+
);
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
console.log("Function calling success", trials.length + 1);
|
|
176
|
+
|
|
177
|
+
// custom validation by compiler
|
|
178
|
+
const document: AutoBeOpenApi.IDocument = ctx.state().interface!.document;
|
|
179
|
+
const errors: IValidation.IError[] | null = await ctx.compiler.test.validate({
|
|
180
|
+
document,
|
|
181
|
+
function: pointer.value.function,
|
|
182
|
+
});
|
|
183
|
+
return errors === null || life <= 0
|
|
184
|
+
? pointer.value
|
|
185
|
+
: process(ctx, scenario, artifacts, --life, {
|
|
186
|
+
success: false,
|
|
187
|
+
data: pointer.value,
|
|
188
|
+
errors,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function getUnionTypeName(unit: IJsonSchemaUnit): string {
|
|
193
|
+
if (OpenApiTypeChecker.isReference(unit.schema) === false) return "unknown";
|
|
194
|
+
|
|
195
|
+
const typeName: string = unit.schema.$ref.split("/").pop() ?? "";
|
|
196
|
+
const schema: OpenApi.IJsonSchema | undefined =
|
|
197
|
+
unit.components.schemas?.[typeName];
|
|
198
|
+
if (schema === undefined || OpenApiTypeChecker.isOneOf(schema) === false)
|
|
199
|
+
return "unknown";
|
|
200
|
+
return schema.oneOf
|
|
201
|
+
.filter(OpenApiTypeChecker.isReference)
|
|
202
|
+
.map((r) => r.$ref.split("/").pop() ?? "")
|
|
203
|
+
.join(" | ");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function createApplication<Model extends ILlmSchema.Model>(props: {
|
|
207
|
+
model: Model;
|
|
208
|
+
document: AutoBeOpenApi.IDocument;
|
|
209
|
+
build: (next: ICreateTestCodeProps) => void;
|
|
210
|
+
}): IAgenticaController.IClass<Model> {
|
|
211
|
+
assertSchemaModel(props.model);
|
|
212
|
+
|
|
213
|
+
const endpoints: HashMap<AutoBeOpenApi.IEndpoint, AutoBeOpenApi.IOperation> =
|
|
214
|
+
new HashMap(
|
|
215
|
+
props.document.operations.map(
|
|
216
|
+
(op) =>
|
|
217
|
+
new Pair(
|
|
218
|
+
{
|
|
219
|
+
method: op.method,
|
|
220
|
+
path: op.path,
|
|
221
|
+
},
|
|
222
|
+
op,
|
|
223
|
+
),
|
|
224
|
+
),
|
|
225
|
+
AutoBeEndpointComparator.hashCode,
|
|
226
|
+
AutoBeEndpointComparator.equals,
|
|
227
|
+
);
|
|
228
|
+
const application: ILlmApplication<Model> = collection[
|
|
229
|
+
props.model
|
|
230
|
+
] as unknown as ILlmApplication<Model>;
|
|
231
|
+
application.functions[0].validate = (
|
|
232
|
+
input: unknown,
|
|
233
|
+
): IValidation<unknown> => {
|
|
234
|
+
const result: IValidation<ICreateTestCodeProps> =
|
|
235
|
+
typia.validate<ICreateTestCodeProps>(input);
|
|
236
|
+
if (result.success === false) return result;
|
|
237
|
+
|
|
238
|
+
const context: IAutoBeTextValidateContext = {
|
|
239
|
+
function: result.data.function,
|
|
240
|
+
document: props.document,
|
|
241
|
+
endpoints,
|
|
242
|
+
errors: [],
|
|
243
|
+
};
|
|
244
|
+
validateTestFunction(context);
|
|
245
|
+
return context.errors.length === 0
|
|
246
|
+
? result
|
|
247
|
+
: {
|
|
248
|
+
success: false,
|
|
249
|
+
data: result.data,
|
|
250
|
+
errors: context.errors,
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
protocol: "class",
|
|
256
|
+
name: "Create Test Code",
|
|
257
|
+
application,
|
|
258
|
+
execute: {
|
|
259
|
+
createTestCode: (next) => {
|
|
260
|
+
props.build(next);
|
|
261
|
+
},
|
|
262
|
+
} satisfies IApplication,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const claude = typia.llm.application<
|
|
267
|
+
IApplication,
|
|
268
|
+
"claude",
|
|
269
|
+
{ reference: true }
|
|
270
|
+
>();
|
|
271
|
+
const collection = {
|
|
272
|
+
chatgpt: typia.llm.application<
|
|
273
|
+
IApplication,
|
|
274
|
+
"chatgpt",
|
|
275
|
+
{ reference: true }
|
|
276
|
+
>(),
|
|
277
|
+
claude,
|
|
278
|
+
llama: claude,
|
|
279
|
+
deepseek: claude,
|
|
280
|
+
"3.1": claude,
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
interface IApplication {
|
|
284
|
+
createTestCode(props: ICreateTestCodeProps): void;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
interface ICreateTestCodeProps {
|
|
288
|
+
/**
|
|
289
|
+
* Functional domain classification for test organization.
|
|
290
|
+
*
|
|
291
|
+
* Determines file structure and test categorization based on API
|
|
292
|
+
* functionality. Used for organizing tests into logical groups and directory
|
|
293
|
+
* hierarchies.
|
|
294
|
+
*
|
|
295
|
+
* ### Naming Rules:
|
|
296
|
+
*
|
|
297
|
+
* - Lowercase English words only
|
|
298
|
+
* - Singular nouns (e.g., "article", "user", "comment")
|
|
299
|
+
* - Kebab-case for compound words (e.g., "user-profile", "payment-method")
|
|
300
|
+
* - Match primary API resource being tested
|
|
301
|
+
* - Domain Name must be named only one word.
|
|
302
|
+
*
|
|
303
|
+
* ### Domain Examples:
|
|
304
|
+
*
|
|
305
|
+
* - `article` → Article management operations
|
|
306
|
+
* - `comment` → Comment-related functionality
|
|
307
|
+
* - `auth` → Authentication and authorization
|
|
308
|
+
* - `user` → User management operations
|
|
309
|
+
* - `payment` → Payment processing
|
|
310
|
+
* - `notification` → Notification system
|
|
311
|
+
*/
|
|
312
|
+
domain: string;
|
|
313
|
+
|
|
314
|
+
/** E2E test function implementation. */
|
|
315
|
+
function: AutoBeTest.IFunction;
|
|
316
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IAgenticaHistoryJson } from "@agentica/core";
|
|
2
|
+
import { IAutoBeTypeScriptCompileResult } from "@autobe/interface";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
|
|
5
|
+
import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
|
|
6
|
+
import { IAutoBeTestWriteResult } from "./structures/IAutoBeTestWriteResult";
|
|
7
|
+
|
|
8
|
+
export const transformTestCorrectHistories = (
|
|
9
|
+
// ctx: AutoBeContext<Model>,
|
|
10
|
+
written: IAutoBeTestWriteResult,
|
|
11
|
+
failure: IAutoBeTypeScriptCompileResult.IFailure,
|
|
12
|
+
): Array<
|
|
13
|
+
IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
|
|
14
|
+
> => {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
id: v4(),
|
|
18
|
+
created_at: new Date().toISOString(),
|
|
19
|
+
type: "systemMessage",
|
|
20
|
+
text: AutoBeSystemPromptConstant.TEST_WRITE,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: v4(),
|
|
24
|
+
created_at: new Date().toISOString(),
|
|
25
|
+
type: "assistantMessage",
|
|
26
|
+
text: [
|
|
27
|
+
"## Original Code",
|
|
28
|
+
"## `AutoBeTest.IFunction` data",
|
|
29
|
+
"```json",
|
|
30
|
+
JSON.stringify(written.file.function),
|
|
31
|
+
"```",
|
|
32
|
+
"## Generated TypeScript Code",
|
|
33
|
+
"```typescript",
|
|
34
|
+
written.file.content,
|
|
35
|
+
"```",
|
|
36
|
+
"",
|
|
37
|
+
"## Compile Errors",
|
|
38
|
+
"Fix the compilation error in the provided code.",
|
|
39
|
+
"",
|
|
40
|
+
"```json",
|
|
41
|
+
JSON.stringify(failure.diagnostics),
|
|
42
|
+
"```",
|
|
43
|
+
].join("\n"),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: v4(),
|
|
47
|
+
created_at: new Date().toISOString(),
|
|
48
|
+
type: "systemMessage",
|
|
49
|
+
text: AutoBeSystemPromptConstant.TEST_CORRECT,
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AutoBeAssistantMessageHistory,
|
|
3
3
|
AutoBeOpenApi,
|
|
4
|
+
AutoBeTestFile,
|
|
4
5
|
AutoBeTestHistory,
|
|
6
|
+
AutoBeTestScenarioEvent,
|
|
5
7
|
AutoBeTestValidateEvent,
|
|
6
|
-
|
|
8
|
+
IAutoBeTypeScriptCompileResult,
|
|
7
9
|
} from "@autobe/interface";
|
|
8
10
|
import { ILlmSchema } from "@samchon/openapi";
|
|
9
11
|
import { v4 } from "uuid";
|
|
@@ -13,6 +15,7 @@ import { IAutoBeApplicationProps } from "../../context/IAutoBeApplicationProps";
|
|
|
13
15
|
import { orchestrateTestCorrect } from "./orchestrateTestCorrect";
|
|
14
16
|
import { orchestrateTestScenario } from "./orchestrateTestScenario";
|
|
15
17
|
import { orchestrateTestWrite } from "./orchestrateTestWrite";
|
|
18
|
+
import { IAutoBeTestWriteResult } from "./structures/IAutoBeTestWriteResult";
|
|
16
19
|
|
|
17
20
|
export const orchestrateTest =
|
|
18
21
|
<Model extends ILlmSchema.Model>(ctx: AutoBeContext<Model>) =>
|
|
@@ -45,41 +48,55 @@ export const orchestrateTest =
|
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
// PLAN
|
|
48
|
-
const
|
|
51
|
+
const scenarioEvent: AutoBeTestScenarioEvent =
|
|
52
|
+
await orchestrateTestScenario(ctx);
|
|
53
|
+
ctx.dispatch(scenarioEvent);
|
|
49
54
|
|
|
50
55
|
// TEST CODE
|
|
51
|
-
const
|
|
56
|
+
const written: IAutoBeTestWriteResult[] = await orchestrateTestWrite(
|
|
52
57
|
ctx,
|
|
53
|
-
scenarios,
|
|
58
|
+
scenarioEvent.scenarios,
|
|
54
59
|
);
|
|
55
|
-
|
|
56
|
-
const correct: AutoBeTestValidateEvent = await orchestrateTestCorrect(
|
|
60
|
+
const corrects: AutoBeTestValidateEvent[] = await orchestrateTestCorrect(
|
|
57
61
|
ctx,
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
written,
|
|
63
|
+
);
|
|
64
|
+
const success: AutoBeTestValidateEvent[] = corrects.filter(
|
|
65
|
+
(c) => c.result.type === "success",
|
|
60
66
|
);
|
|
67
|
+
|
|
68
|
+
// DO COMPILE
|
|
69
|
+
const files: AutoBeTestFile[] = success.map((c) => c.file);
|
|
70
|
+
const compiled: IAutoBeTypeScriptCompileResult =
|
|
71
|
+
await ctx.compiler.test.compile({
|
|
72
|
+
files: {
|
|
73
|
+
...Object.fromEntries(
|
|
74
|
+
Object.entries(ctx.state().interface!.files).filter(
|
|
75
|
+
([key]) => key.startsWith("src/api") === true,
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
...Object.fromEntries(files.map((f) => [f.location, f.content])),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
61
82
|
const history: AutoBeTestHistory = {
|
|
62
83
|
type: "test",
|
|
63
84
|
id: v4(),
|
|
64
85
|
completed_at: new Date().toISOString(),
|
|
65
86
|
created_at: start.toISOString(),
|
|
66
|
-
files
|
|
67
|
-
compiled
|
|
87
|
+
files,
|
|
88
|
+
compiled,
|
|
68
89
|
reason: "Step to the test generation referencing the interface",
|
|
69
90
|
step: ctx.state().interface?.step ?? 0,
|
|
70
91
|
};
|
|
71
92
|
ctx.dispatch({
|
|
72
93
|
type: "testComplete",
|
|
73
94
|
created_at: start.toISOString(),
|
|
74
|
-
files:
|
|
75
|
-
|
|
76
|
-
.reduce((acc, cur) => Object.assign(acc, cur), {}),
|
|
77
|
-
compiled: correct.result,
|
|
95
|
+
files: Object.fromEntries(files.map((f) => [f.location, f.content])),
|
|
96
|
+
compiled,
|
|
78
97
|
step: ctx.state().interface?.step ?? 0,
|
|
79
98
|
});
|
|
80
|
-
|
|
81
99
|
ctx.state().test = history;
|
|
82
100
|
ctx.histories().push(history);
|
|
83
|
-
|
|
84
101
|
return history;
|
|
85
102
|
};
|