@autobe/agent 0.25.4 → 0.25.5

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.
Files changed (32) hide show
  1. package/lib/AutoBeMockAgent.js +1 -1
  2. package/lib/AutoBeMockAgent.js.map +1 -1
  3. package/lib/index.mjs +1943 -1422
  4. package/lib/index.mjs.map +1 -1
  5. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.d.ts +1 -0
  6. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js +370 -275
  7. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js.map +1 -1
  8. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js +370 -275
  9. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js.map +1 -1
  10. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js +304 -221
  11. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js.map +1 -1
  12. package/lib/orchestrate/realize/orchestrateRealizeWrite.js +303 -220
  13. package/lib/orchestrate/realize/orchestrateRealizeWrite.js.map +1 -1
  14. package/lib/orchestrate/test/orchestrateTestCorrect.js +17 -22
  15. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  16. package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js +372 -277
  17. package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js.map +1 -1
  18. package/lib/orchestrate/test/orchestrateTestWrite.js +322 -350
  19. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  20. package/lib/utils/validateEmptyCode.d.ts +8 -0
  21. package/lib/utils/validateEmptyCode.js +35 -0
  22. package/lib/utils/validateEmptyCode.js.map +1 -0
  23. package/package.json +5 -5
  24. package/src/AutoBeMockAgent.ts +1 -1
  25. package/src/orchestrate/common/orchestrateCommonCorrectCasting.ts +52 -10
  26. package/src/orchestrate/realize/orchestRateRealizeCorrectCasting.ts +58 -17
  27. package/src/orchestrate/realize/orchestrateRealizeCorrect.ts +51 -15
  28. package/src/orchestrate/realize/orchestrateRealizeWrite.ts +46 -12
  29. package/src/orchestrate/test/orchestrateTestCorrect.ts +17 -24
  30. package/src/orchestrate/test/orchestrateTestCorrectInvalidRequest.ts +57 -10
  31. package/src/orchestrate/test/orchestrateTestWrite.ts +41 -10
  32. package/src/utils/validateEmptyCode.ts +41 -0
@@ -3,13 +3,19 @@ import {
3
3
  AutoBeTestValidateEvent,
4
4
  } from "@autobe/interface";
5
5
  import { StringUtil } from "@autobe/utils";
6
- import { ILlmApplication, ILlmController, ILlmSchema } from "@samchon/openapi";
6
+ import {
7
+ ILlmApplication,
8
+ ILlmController,
9
+ ILlmSchema,
10
+ IValidation,
11
+ } from "@samchon/openapi";
7
12
  import { IPointer } from "tstl";
8
13
  import typia from "typia";
9
14
  import { v7 } from "uuid";
10
15
 
11
16
  import { AutoBeContext } from "../../context/AutoBeContext";
12
17
  import { assertSchemaModel } from "../../context/assertSchemaModel";
18
+ import { validateEmptyCode } from "../../utils/validateEmptyCode";
13
19
  import { completeTestCode } from "./compile/completeTestCode";
14
20
  import { transformTestCorrectInvalidRequestHistories } from "./histories/transformTestCorrectInvalidRequestHistories";
15
21
  import { IAutoBeTestCorrectInvalidRequestApplication } from "./structures/IAutoBeTestCorrectInvalidRequestApplication";
@@ -65,6 +71,7 @@ const correct = async <Model extends ILlmSchema.Model>(
65
71
  ),
66
72
  controller: createController({
67
73
  model: ctx.model,
74
+ functionName: write.scenario.functionName,
68
75
  then: (next) => {
69
76
  pointer.value = next;
70
77
  },
@@ -123,13 +130,31 @@ const correct = async <Model extends ILlmSchema.Model>(
123
130
 
124
131
  const createController = <Model extends ILlmSchema.Model>(props: {
125
132
  model: Model;
133
+ functionName: string;
126
134
  then: (next: IAutoBeTestCorrectInvalidRequestApplication.IProps) => void;
127
135
  reject: () => void;
128
136
  }): ILlmController<Model> => {
129
137
  assertSchemaModel(props.model);
138
+ const validate: Validator = (input) => {
139
+ const result: IValidation<IAutoBeTestCorrectInvalidRequestApplication.IProps> =
140
+ typia.validate<IAutoBeTestCorrectInvalidRequestApplication.IProps>(input);
141
+ if (result.success === false) return result;
142
+ const errors: IValidation.IError[] = validateEmptyCode({
143
+ functionName: props.functionName,
144
+ draft: result.data.draft,
145
+ revise: result.data.revise,
146
+ });
147
+ return errors.length
148
+ ? {
149
+ success: false,
150
+ errors,
151
+ data: result.data,
152
+ }
153
+ : result;
154
+ };
130
155
  const application = collection[
131
156
  props.model === "chatgpt" ? "chatgpt" : "claude"
132
- ] satisfies ILlmApplication<any> as any as ILlmApplication<Model>;
157
+ ](validate) satisfies ILlmApplication<any> as any as ILlmApplication<Model>;
133
158
  return {
134
159
  protocol: "class",
135
160
  name: "correctInvalidRequest",
@@ -146,12 +171,34 @@ const createController = <Model extends ILlmSchema.Model>(props: {
146
171
  };
147
172
 
148
173
  const collection = {
149
- chatgpt: typia.llm.application<
150
- IAutoBeTestCorrectInvalidRequestApplication,
151
- "chatgpt"
152
- >(),
153
- claude: typia.llm.application<
154
- IAutoBeTestCorrectInvalidRequestApplication,
155
- "claude"
156
- >(),
174
+ chatgpt: (validate: Validator) =>
175
+ typia.llm.application<
176
+ IAutoBeTestCorrectInvalidRequestApplication,
177
+ "chatgpt"
178
+ >({
179
+ validate: {
180
+ rewrite: validate,
181
+ reject: () => ({
182
+ success: true,
183
+ data: undefined,
184
+ }),
185
+ },
186
+ }),
187
+ claude: (validate: Validator) =>
188
+ typia.llm.application<
189
+ IAutoBeTestCorrectInvalidRequestApplication,
190
+ "claude"
191
+ >({
192
+ validate: {
193
+ rewrite: validate,
194
+ reject: () => ({
195
+ success: true,
196
+ data: undefined,
197
+ }),
198
+ },
199
+ }),
157
200
  };
201
+
202
+ type Validator = (
203
+ input: unknown,
204
+ ) => IValidation<IAutoBeTestCorrectInvalidRequestApplication.IProps>;
@@ -4,7 +4,7 @@ import {
4
4
  AutoBeTestScenario,
5
5
  AutoBeTestWriteEvent,
6
6
  } from "@autobe/interface";
7
- import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
7
+ import { ILlmApplication, ILlmSchema, IValidation } from "@samchon/openapi";
8
8
  import { IPointer } from "tstl";
9
9
  import typia from "typia";
10
10
  import { NamingConvention } from "typia/lib/utils/NamingConvention";
@@ -13,6 +13,7 @@ import { v7 } from "uuid";
13
13
  import { AutoBeContext } from "../../context/AutoBeContext";
14
14
  import { assertSchemaModel } from "../../context/assertSchemaModel";
15
15
  import { executeCachedBatch } from "../../utils/executeCachedBatch";
16
+ import { validateEmptyCode } from "../../utils/validateEmptyCode";
16
17
  import { completeTestCode } from "./compile/completeTestCode";
17
18
  import { getTestScenarioArtifacts } from "./compile/getTestScenarioArtifacts";
18
19
  import { transformTestWriteHistories } from "./histories/transformTestWriteHistories";
@@ -85,6 +86,7 @@ async function process<Model extends ILlmSchema.Model>(
85
86
  }),
86
87
  controller: createController({
87
88
  model: ctx.model,
89
+ functionName: props.scenario.functionName,
88
90
  build: (next) => {
89
91
  next.domain = NamingConvention.snake(next.domain);
90
92
  pointer.value = next;
@@ -129,13 +131,33 @@ async function process<Model extends ILlmSchema.Model>(
129
131
 
130
132
  function createController<Model extends ILlmSchema.Model>(props: {
131
133
  model: Model;
134
+ functionName: string;
132
135
  build: (next: IAutoBeTestWriteApplication.IProps) => void;
133
136
  }): IAgenticaController.IClass<Model> {
134
137
  assertSchemaModel(props.model);
135
138
 
139
+ const validate: Validator = (input) => {
140
+ const result: IValidation<IAutoBeTestWriteApplication.IProps> =
141
+ typia.validate<IAutoBeTestWriteApplication.IProps>(input);
142
+ if (result.success === false) return result;
143
+ const errors: IValidation.IError[] = validateEmptyCode({
144
+ functionName: props.functionName,
145
+ draft: result.data.draft,
146
+ revise: result.data.revise,
147
+ });
148
+ return errors.length
149
+ ? {
150
+ success: false,
151
+ errors,
152
+ data: result.data,
153
+ }
154
+ : result;
155
+ };
136
156
  const application: ILlmApplication<Model> = collection[
137
- props.model
138
- ] satisfies ILlmApplication<any> as unknown as ILlmApplication<Model>;
157
+ props.model === "chatgpt" ? "chatgpt" : "claude"
158
+ ](
159
+ validate,
160
+ ) satisfies ILlmApplication<any> as unknown as ILlmApplication<Model>;
139
161
  return {
140
162
  protocol: "class",
141
163
  name: "Create Test Code",
@@ -148,12 +170,21 @@ function createController<Model extends ILlmSchema.Model>(props: {
148
170
  };
149
171
  }
150
172
 
151
- const claude = typia.llm.application<IAutoBeTestWriteApplication, "claude">();
152
173
  const collection = {
153
- chatgpt: typia.llm.application<IAutoBeTestWriteApplication, "chatgpt">(),
154
- claude,
155
- llama: claude,
156
- deepseek: claude,
157
- "3.1": claude,
158
- "3.0": typia.llm.application<IAutoBeTestWriteApplication, "3.0">(),
174
+ chatgpt: (validate: Validator) =>
175
+ typia.llm.application<IAutoBeTestWriteApplication, "chatgpt">({
176
+ validate: {
177
+ write: validate,
178
+ },
179
+ }),
180
+ claude: (validate: Validator) =>
181
+ typia.llm.application<IAutoBeTestWriteApplication, "claude">({
182
+ validate: {
183
+ write: validate,
184
+ },
185
+ }),
159
186
  };
187
+
188
+ type Validator = (
189
+ input: unknown,
190
+ ) => IValidation<IAutoBeTestWriteApplication.IProps>;
@@ -0,0 +1,41 @@
1
+ import { StringUtil } from "@autobe/utils";
2
+ import { IValidation } from "typia";
3
+
4
+ export const validateEmptyCode = (props: {
5
+ functionName: string;
6
+ draft: string;
7
+ revise: {
8
+ final: string | null;
9
+ };
10
+ }): IValidation.IError[] => {
11
+ const errors: IValidation.IError[] = [];
12
+ if (props.draft.includes(props.functionName) === false)
13
+ errors.push({
14
+ path: "$input.draft",
15
+ expected: `string (including function named '${props.functionName}')`,
16
+ value: props.draft,
17
+ description: description(props.functionName),
18
+ });
19
+ if (
20
+ props.revise.final !== null &&
21
+ props.revise.final.includes(props.functionName) === false
22
+ )
23
+ errors.push({
24
+ path: "$input.revise.final",
25
+ expected: `string (including function named '${props.functionName}')`,
26
+ value: props.revise.final,
27
+ description: description(props.functionName),
28
+ });
29
+ return errors;
30
+ };
31
+
32
+ const description = (func: string): string => StringUtil.trim`
33
+ The function ${func} does not exist in the provided code snippet.
34
+
35
+ The first reason of the non-existence is that the code snippet is empty,
36
+ and the second reason is that AI has written different function name
37
+ by mistake.
38
+
39
+ Please make sure that the code snippet includes the function ${func}.
40
+ Note that, you never have to write empty code or different function name.
41
+ `;