@autobe/agent 0.23.1 → 0.24.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.
Files changed (103) hide show
  1. package/lib/constants/AutoBeSystemPromptConstant.d.ts +30 -29
  2. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  3. package/lib/factory/consentFunctionCall.js +1 -1
  4. package/lib/factory/consentFunctionCall.js.map +1 -1
  5. package/lib/factory/createAutoBeContext.js +3 -3
  6. package/lib/factory/createAutoBeContext.js.map +1 -1
  7. package/lib/index.mjs +683 -260
  8. package/lib/index.mjs.map +1 -1
  9. package/lib/orchestrate/analyze/histories/transformAnalyzeReviewHistories.js +1 -1
  10. package/lib/orchestrate/analyze/histories/transformAnalyzeReviewHistories.js.map +1 -1
  11. package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioHistories.js +2 -2
  12. package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioHistories.js.map +1 -1
  13. package/lib/orchestrate/analyze/histories/transformAnalyzeWriteHistories.js +1 -1
  14. package/lib/orchestrate/analyze/histories/transformAnalyzeWriteHistories.js.map +1 -1
  15. package/lib/orchestrate/common/histories/transformCommonCorrectCastingHistories.js +1 -1
  16. package/lib/orchestrate/common/histories/transformCommonCorrectCastingHistories.js.map +1 -1
  17. package/lib/orchestrate/common/histories/transformCommonCorrectDateHistories.d.ts +9 -0
  18. package/lib/orchestrate/common/histories/transformCommonCorrectDateHistories.js +48 -0
  19. package/lib/orchestrate/common/histories/transformCommonCorrectDateHistories.js.map +1 -0
  20. package/lib/orchestrate/common/structures/IAutoBeCommonCorrectDateApplication.d.ts +35 -0
  21. package/lib/orchestrate/common/structures/IAutoBeCommonCorrectDateApplication.js +3 -0
  22. package/lib/orchestrate/common/structures/IAutoBeCommonCorrectDateApplication.js.map +1 -0
  23. package/lib/orchestrate/facade/transformFacadeStateMessage.js +1 -1
  24. package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +1 -1
  25. package/lib/orchestrate/interface/histories/transformInterfaceAuthorizationsHistories.js +1 -1
  26. package/lib/orchestrate/interface/histories/transformInterfaceAuthorizationsHistories.js.map +1 -1
  27. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js +3 -3
  28. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js.map +1 -1
  29. package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js +1 -1
  30. package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js.map +1 -1
  31. package/lib/orchestrate/interface/histories/transformInterfaceEndpointsReviewHistories.js +2 -2
  32. package/lib/orchestrate/interface/histories/transformInterfaceEndpointsReviewHistories.js.map +1 -1
  33. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js +2 -2
  34. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js.map +1 -1
  35. package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js +1 -1
  36. package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js.map +1 -1
  37. package/lib/orchestrate/interface/histories/transformInterfaceOperationsReviewHistories.js +2 -2
  38. package/lib/orchestrate/interface/histories/transformInterfaceOperationsReviewHistories.js.map +1 -1
  39. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js +1 -1
  40. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js.map +1 -1
  41. package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js +2 -2
  42. package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js.map +1 -1
  43. package/lib/orchestrate/prisma/histories/transformPrismaComponentsHistories.js +1 -1
  44. package/lib/orchestrate/prisma/histories/transformPrismaComponentsHistories.js.map +1 -1
  45. package/lib/orchestrate/prisma/histories/transformPrismaCorrectHistories.js +1 -1
  46. package/lib/orchestrate/prisma/histories/transformPrismaCorrectHistories.js.map +1 -1
  47. package/lib/orchestrate/prisma/histories/transformPrismaReviewHistories.js +2 -2
  48. package/lib/orchestrate/prisma/histories/transformPrismaReviewHistories.js.map +1 -1
  49. package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistories.js +1 -1
  50. package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistories.js.map +1 -1
  51. package/lib/orchestrate/realize/histories/transformRealizeAuthorization.js +1 -1
  52. package/lib/orchestrate/realize/histories/transformRealizeAuthorization.js.map +1 -1
  53. package/lib/orchestrate/realize/histories/transformRealizeAuthorizationCorrectHistories.js +2 -2
  54. package/lib/orchestrate/realize/histories/transformRealizeAuthorizationCorrectHistories.js.map +1 -1
  55. package/lib/orchestrate/realize/histories/transformRealizeCorrectHistories.js +2 -2
  56. package/lib/orchestrate/realize/histories/transformRealizeCorrectHistories.js.map +1 -1
  57. package/lib/orchestrate/realize/histories/transformRealizeWriteHistories.js +2 -2
  58. package/lib/orchestrate/realize/histories/transformRealizeWriteHistories.js.map +1 -1
  59. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js +4 -3
  60. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js.map +1 -1
  61. package/lib/orchestrate/realize/orchestrateRealize.js +6 -10
  62. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
  63. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js +46 -61
  64. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js.map +1 -1
  65. package/lib/orchestrate/realize/orchestrateRealizeCorrectDate.d.ts +4 -0
  66. package/lib/orchestrate/realize/orchestrateRealizeCorrectDate.js +540 -0
  67. package/lib/orchestrate/realize/orchestrateRealizeCorrectDate.js.map +1 -0
  68. package/lib/orchestrate/realize/orchestrateRealizeWrite.js +37 -55
  69. package/lib/orchestrate/realize/orchestrateRealizeWrite.js.map +1 -1
  70. package/lib/orchestrate/realize/structures/IAutoBeRealizeCorrectApplication.d.ts +8 -8
  71. package/lib/orchestrate/realize/structures/IAutoBeRealizeWriteApplication.d.ts +20 -264
  72. package/lib/orchestrate/realize/utils/filterDiagnostics.d.ts +13 -0
  73. package/lib/orchestrate/realize/utils/filterDiagnostics.js +20 -0
  74. package/lib/orchestrate/realize/utils/filterDiagnostics.js.map +1 -0
  75. package/lib/orchestrate/test/histories/transformTestCorrectHistories.js +1 -1
  76. package/lib/orchestrate/test/histories/transformTestCorrectHistories.js.map +1 -1
  77. package/lib/orchestrate/test/histories/transformTestCorrectInvalidRequestHistories.js +1 -1
  78. package/lib/orchestrate/test/histories/transformTestCorrectInvalidRequestHistories.js.map +1 -1
  79. package/lib/orchestrate/test/histories/transformTestScenarioHistories.js +1 -1
  80. package/lib/orchestrate/test/histories/transformTestScenarioHistories.js.map +1 -1
  81. package/lib/orchestrate/test/histories/transformTestWriteHistories.js +1 -1
  82. package/lib/orchestrate/test/histories/transformTestWriteHistories.js.map +1 -1
  83. package/lib/structures/IAutoBeConfig.d.ts +34 -1
  84. package/lib/utils/{TimeoutConversation.d.ts → TimedConversation.d.ts} +2 -2
  85. package/lib/utils/{TimeoutConversation.js → TimedConversation.js} +20 -6
  86. package/lib/utils/TimedConversation.js.map +1 -0
  87. package/package.json +6 -6
  88. package/src/constants/AutoBeSystemPromptConstant.ts +30 -29
  89. package/src/factory/createAutoBeContext.ts +5 -5
  90. package/src/orchestrate/common/histories/transformCommonCorrectDateHistories.ts +60 -0
  91. package/src/orchestrate/common/structures/IAutoBeCommonCorrectDateApplication.ts +40 -0
  92. package/src/orchestrate/realize/histories/transformRealizeWriteHistories.ts +1 -1
  93. package/src/orchestrate/realize/orchestRateRealizeCorrectCasting.ts +4 -3
  94. package/src/orchestrate/realize/orchestrateRealize.ts +22 -16
  95. package/src/orchestrate/realize/orchestrateRealizeCorrect.ts +44 -16
  96. package/src/orchestrate/realize/orchestrateRealizeCorrectDate.ts +372 -0
  97. package/src/orchestrate/realize/orchestrateRealizeWrite.ts +3 -3
  98. package/src/orchestrate/realize/structures/IAutoBeRealizeCorrectApplication.ts +8 -10
  99. package/src/orchestrate/realize/structures/IAutoBeRealizeWriteApplication.ts +21 -267
  100. package/src/orchestrate/realize/utils/filterDiagnostics.ts +21 -0
  101. package/src/structures/IAutoBeConfig.ts +34 -1
  102. package/src/utils/{TimeoutConversation.ts → TimedConversation.ts} +18 -3
  103. package/lib/utils/TimeoutConversation.js.map +0 -1
@@ -37,7 +37,7 @@ import { IAutoBeApplication } from "../context/IAutoBeApplication";
37
37
  import { IAutoBeConfig } from "../structures/IAutoBeConfig";
38
38
  import { IAutoBeVendor } from "../structures/IAutoBeVendor";
39
39
  import { AutoBeTimeoutError } from "../utils/AutoBeTimeoutError";
40
- import { TimeoutConversation } from "../utils/TimeoutConversation";
40
+ import { TimedConversation } from "../utils/TimedConversation";
41
41
  import { consentFunctionCall } from "./consentFunctionCall";
42
42
  import { getCriticalCompiler } from "./getCriticalCompiler";
43
43
 
@@ -57,7 +57,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
57
57
  {
58
58
  retry: props.config.retry ?? AutoBeConfigConstant.RETRY,
59
59
  locale: props.config.locale ?? "en-US",
60
- timeout: props.config.timeout ?? AutoBeConfigConstant.TIMEOUT,
60
+ timeout: props.config.timeout ?? null,
61
61
  };
62
62
  const critical: Semaphore = new Semaphore(2);
63
63
  return {
@@ -152,8 +152,8 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
152
152
  if (closure) closure(agent);
153
153
 
154
154
  // DO CONVERSATE
155
- const result: TimeoutConversation.IResult<Model> =
156
- await TimeoutConversation.process({
155
+ const result: TimedConversation.IResult<Model> =
156
+ await TimedConversation.process({
157
157
  agent,
158
158
  timeout: config.timeout,
159
159
  message: next.message,
@@ -174,7 +174,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
174
174
  type: "vendorTimeout",
175
175
  id: v7(),
176
176
  source: next.source,
177
- timeout: config.timeout,
177
+ timeout: config.timeout!,
178
178
  retry: trial.timeout++,
179
179
  created_at: new Date().toISOString(),
180
180
  })
@@ -0,0 +1,60 @@
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
+ /** Transform date correction histories for AI conversation */
14
+ export const transformCommonCorrectDateHistories = (
15
+ failures: IFailure[],
16
+ ): Array<
17
+ IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
18
+ > => [
19
+ {
20
+ id: v7(),
21
+ created_at: new Date().toISOString(),
22
+ type: "systemMessage",
23
+ text: AutoBeSystemPromptConstant.REALIZE_DATE,
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 Date Type Failure" : "Previous Date Type Failure"}
33
+
34
+ ## Generated TypeScript Code
35
+ \`\`\`typescript
36
+ ${f.script}
37
+ \`\`\`
38
+
39
+ ## Date-Related Compile Errors
40
+ ${f.diagnostics
41
+ .map((d) => {
42
+ const location = d.file
43
+ ? `[${d.file}${d.start ? `:${d.start}` : ""}]`
44
+ : "[Unknown location]";
45
+ const code = d.code ? `TS${d.code}` : "";
46
+ const messageText = d.messageText || "Date type error";
47
+ return `- ${location} ${code}: ${messageText}`;
48
+ })
49
+ .join("\n")}
50
+
51
+ ## Required Fixes:
52
+ - Replace all Date type declarations with string & tags.Format<"date-time">
53
+ - Wrap Date objects with toISOStringSafe(value)
54
+ - Check null/undefined BEFORE calling toISOStringSafe (it doesn't accept null)
55
+ - Remove Date variable declarations (const now = new Date() is forbidden)
56
+ - toISOStringSafe requires a parameter - it's not optional
57
+ `,
58
+ }) satisfies IAgenticaHistoryJson.IAssistantMessage,
59
+ ),
60
+ ];
@@ -0,0 +1,40 @@
1
+ import typia from "typia";
2
+
3
+ /** Application interface for Date type correction in generated code */
4
+ export interface IAutoBeCommonCorrectDateApplication {
5
+ /**
6
+ * Rewrite the function to fix Date type issues
7
+ *
8
+ * @param props - Correction properties
9
+ */
10
+ rewrite(props: IAutoBeCommonCorrectDateApplication.IProps): void;
11
+
12
+ /** Reject the correction task if Date issues cannot be fixed */
13
+ reject(): void;
14
+ }
15
+
16
+ export namespace IAutoBeCommonCorrectDateApplication {
17
+ /** Properties for Date type correction */
18
+ export interface IProps {
19
+ /** The correction revision containing the fixed code */
20
+ revise: {
21
+ /** Optional: Analysis of Date type errors found */
22
+ analysis?: string & typia.tags.MaxLength<4000>;
23
+
24
+ /** Optional: Strategy for fixing Date issues */
25
+ strategy?: string & typia.tags.MaxLength<2000>;
26
+
27
+ /**
28
+ * Final corrected code with all Date type issues resolved
29
+ *
30
+ * Must follow these rules:
31
+ *
32
+ * - No ': Date' type declarations
33
+ * - All dates use 'string & tags.Format<"date-time">'
34
+ * - All Date objects wrapped with toISOStringSafe()
35
+ * - Null checks before toISOStringSafe()
36
+ */
37
+ final: string;
38
+ };
39
+ }
40
+ }
@@ -114,7 +114,7 @@ export const transformRealizeWriteHistories = (props: {
114
114
  created_at: new Date().toISOString(),
115
115
  type: "systemMessage",
116
116
  text: AutoBeSystemPromptConstant.REALIZE_WRITE_ARTIFACT.replaceAll(
117
- `{prisma_schemas}`,
117
+ `{prismaSchemas}`,
118
118
  JSON.stringify(props.state.prisma.schemas),
119
119
  )
120
120
  .replaceAll(
@@ -131,8 +131,8 @@ const correct = async <Model extends ILlmSchema.Model>(
131
131
 
132
132
  Most casting errors are caused by type mismatches between Date types and
133
133
  string & tags.Format<'date-time'>. To fix these:
134
- - Use the pre-provided toISOStringSafe() function to convert Date to string
135
- - Or use Date object's .toISOString() method
134
+ - Use ONLY the pre-provided toISOStringSafe() function to convert Date to string
135
+ - Do NOT use .toISOString() method directly (use toISOStringSafe instead)
136
136
  - Never use Date type directly in declarations or return values
137
137
 
138
138
  You don't need to explain me anything, but just fix or give it up
@@ -225,7 +225,8 @@ const diagnose = (event: AutoBeRealizeValidateEvent): string[] => {
225
225
  const diagnostics = event.result.diagnostics;
226
226
  const locations = diagnostics
227
227
  .map((d) => d.file)
228
- .filter((f): f is string => f !== null);
228
+ .filter((f): f is string => f !== null)
229
+ .filter((f) => f.startsWith("src/providers"));
229
230
 
230
231
  return Array.from(new Set(locations));
231
232
  };
@@ -19,6 +19,7 @@ import { compileRealizeFiles } from "./internal/compileRealizeFiles";
19
19
  import { orchestrateRealizeCorrectCasting } from "./orchestRateRealizeCorrectCasting";
20
20
  import { orchestrateRealizeAuthorization } from "./orchestrateRealizeAuthorization";
21
21
  import { orchestrateRealizeCorrect } from "./orchestrateRealizeCorrect";
22
+ import { orchestrateRealizeCorrectDate } from "./orchestrateRealizeCorrectDate";
22
23
  import { orchestrateRealizeWrite } from "./orchestrateRealizeWrite";
23
24
  import { IAutoBeRealizeFunctionFailure } from "./structures/IAutoBeRealizeFunctionFailure";
24
25
  import { IAutoBeRealizeScenarioResult } from "./structures/IAutoBeRealizeScenarioResult";
@@ -110,34 +111,39 @@ export const orchestrateRealize =
110
111
  authorizations,
111
112
  functions,
112
113
  reviewProgress,
114
+ parseInt((ctx.retry / 2).toString()),
113
115
  );
114
116
 
115
- console.log("converted end");
116
- console.log("converted end");
117
- console.log("converted end");
118
- console.log("converted end");
119
- console.log("converted end");
120
- console.log("converted end");
121
- const corrected: AutoBeRealizeFunction[] = await orchestrateRealizeCorrect(
122
- ctx,
123
- scenarios,
124
- authorizations,
125
- converted,
126
- [] satisfies IAutoBeRealizeFunctionFailure[],
127
- reviewProgress,
128
- );
117
+ const correctedDate: AutoBeRealizeFunction[] =
118
+ await orchestrateRealizeCorrectDate(
119
+ ctx,
120
+ authorizations,
121
+ converted,
122
+ reviewProgress,
123
+ parseInt((ctx.retry / 2).toString()),
124
+ );
125
+
126
+ const totalCorrected: AutoBeRealizeFunction[] =
127
+ await orchestrateRealizeCorrect(
128
+ ctx,
129
+ scenarios,
130
+ authorizations,
131
+ correctedDate,
132
+ [] satisfies IAutoBeRealizeFunctionFailure[],
133
+ reviewProgress,
134
+ );
129
135
 
130
136
  const compiler: IAutoBeCompiler = await ctx.compiler();
131
137
  const controllers: Record<string, string> =
132
138
  await compiler.realize.controller({
133
139
  document: ctx.state().interface!.document,
134
- functions: corrected,
140
+ functions: totalCorrected,
135
141
  authorizations,
136
142
  });
137
143
 
138
144
  const { result } = await compileRealizeFiles(ctx, {
139
145
  authorizations,
140
- functions: corrected,
146
+ functions: totalCorrected,
141
147
  });
142
148
 
143
149
  return ctx.dispatch({
@@ -18,6 +18,7 @@ import { compileRealizeFiles } from "./internal/compileRealizeFiles";
18
18
  import { IAutoBeRealizeCorrectApplication } from "./structures/IAutoBeRealizeCorrectApplication";
19
19
  import { IAutoBeRealizeFunctionFailure } from "./structures/IAutoBeRealizeFunctionFailure";
20
20
  import { IAutoBeRealizeScenarioResult } from "./structures/IAutoBeRealizeScenarioResult";
21
+ import { filterDiagnostics } from "./utils/filterDiagnostics";
21
22
  import { getRealizeWriteDto } from "./utils/getRealizeWriteDto";
22
23
  import { replaceImportStatements } from "./utils/replaceImportStatements";
23
24
 
@@ -42,7 +43,10 @@ export async function orchestrateRealizeCorrect<Model extends ILlmSchema.Model>(
42
43
  const diagnostics = event.result.diagnostics;
43
44
  const locations: string[] = Array.from(
44
45
  new Set(
45
- diagnostics.map((d) => d.file).filter((f): f is string => f !== null),
46
+ diagnostics
47
+ .map((d) => d.file)
48
+ .filter((f): f is string => f !== null)
49
+ .filter((f) => f.startsWith("src/providers")),
46
50
  ),
47
51
  );
48
52
 
@@ -53,9 +57,15 @@ export async function orchestrateRealizeCorrect<Model extends ILlmSchema.Model>(
53
57
  diagnostics.forEach((diagnostic) => {
54
58
  const location: string | null = diagnostic.file;
55
59
  if (location === null) return;
60
+ if (!location.startsWith("src/providers")) return;
56
61
 
57
62
  if (!diagnosticsByFile[location]) {
58
- const func = functions.find((f) => f.location === location)!;
63
+ const func = functions.find((f) => f.location === location);
64
+
65
+ if (!func) {
66
+ return;
67
+ }
68
+
59
69
  const failure: IAutoBeRealizeFunctionFailure = {
60
70
  function: func,
61
71
  diagnostics: [],
@@ -65,13 +75,21 @@ export async function orchestrateRealizeCorrect<Model extends ILlmSchema.Model>(
65
75
  diagnosticsByFile[location].diagnostics.push(diagnostic);
66
76
  });
67
77
 
68
- await correct(
78
+ const newFailures: IAutoBeRealizeFunctionFailure[] = [
79
+ ...failures,
80
+ ...Object.values(diagnosticsByFile),
81
+ ];
82
+
83
+ const corrected: AutoBeRealizeFunction[] = await correct(
69
84
  ctx,
70
85
  locations,
71
86
  scenarios,
72
87
  authorizations,
73
88
  functions,
74
- [...failures, ...Object.values(diagnosticsByFile)],
89
+ filterDiagnostics(
90
+ newFailures,
91
+ functions.map((fn) => fn.location),
92
+ ),
75
93
  progress,
76
94
  );
77
95
 
@@ -79,8 +97,11 @@ export async function orchestrateRealizeCorrect<Model extends ILlmSchema.Model>(
79
97
  ctx,
80
98
  scenarios,
81
99
  authorizations,
82
- functions,
83
- [...failures, ...Object.values(diagnosticsByFile)],
100
+ corrected,
101
+ filterDiagnostics(
102
+ newFailures,
103
+ corrected.map((c) => c.location),
104
+ ),
84
105
  progress,
85
106
  life - 1,
86
107
  );
@@ -95,25 +116,30 @@ async function correct<Model extends ILlmSchema.Model>(
95
116
  failures: IAutoBeRealizeFunctionFailure[],
96
117
  progress: AutoBeProgressEventBase,
97
118
  ): Promise<AutoBeRealizeFunction[]> {
98
- return executeCachedBatch(
119
+ const result: AutoBeRealizeFunction[] = await executeCachedBatch(
99
120
  locations.map((location) => async (): Promise<AutoBeRealizeFunction> => {
100
121
  const scenario = scenarios.find((el) => el.location === location);
101
- const func = functions.find((el) => el.location === location)!;
102
- const ReailzeFunctionFailures: IAutoBeRealizeFunctionFailure[] =
103
- failures.filter((f) => f.function.location === location);
122
+ const func = functions.find((el) => el.location === location);
123
+
124
+ if (!func) {
125
+ throw new Error("No function found for location: " + location);
126
+ }
104
127
 
105
- if (ReailzeFunctionFailures.length && scenario) {
128
+ const RealizeFunctionFailures: IAutoBeRealizeFunctionFailure[] =
129
+ failures.filter((f) => f.function?.location === location);
130
+
131
+ if (RealizeFunctionFailures.length && scenario) {
106
132
  try {
107
133
  const correctEvent = await step(ctx, {
108
134
  totalAuthorizations: authorizations,
109
135
  authorization: scenario.decoratorEvent ?? null,
110
136
  scenario,
111
137
  function: func,
112
- failures: ReailzeFunctionFailures,
138
+ failures: RealizeFunctionFailures,
113
139
  progress: progress,
114
140
  });
115
141
 
116
- func.content = correctEvent.content;
142
+ return { ...func, content: correctEvent.content };
117
143
  } catch (err) {
118
144
  return func;
119
145
  }
@@ -122,6 +148,8 @@ async function correct<Model extends ILlmSchema.Model>(
122
148
  return func;
123
149
  }),
124
150
  );
151
+
152
+ return result;
125
153
  }
126
154
 
127
155
  async function step<Model extends ILlmSchema.Model>(
@@ -168,9 +196,9 @@ async function step<Model extends ILlmSchema.Model>(
168
196
  if (pointer.value === null)
169
197
  throw new Error("Failed to correct implementation code.");
170
198
 
171
- pointer.value.revise.implementationCode = await replaceImportStatements(ctx, {
199
+ pointer.value.revise.final = await replaceImportStatements(ctx, {
172
200
  operation: props.scenario.operation,
173
- code: pointer.value.revise.implementationCode,
201
+ code: pointer.value.revise.final,
174
202
  decoratorType: props.authorization?.payload.name,
175
203
  });
176
204
 
@@ -178,7 +206,7 @@ async function step<Model extends ILlmSchema.Model>(
178
206
  type: "realizeCorrect",
179
207
  id: v7(),
180
208
  location: props.scenario.location,
181
- content: pointer.value.revise.implementationCode,
209
+ content: pointer.value.revise.final,
182
210
  tokenUsage,
183
211
  completed: ++props.progress.completed,
184
212
  total: props.progress.total,