@autobe/agent 0.11.2 → 0.13.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 (72) hide show
  1. package/lib/AutoBeAgent.d.ts +3 -146
  2. package/lib/AutoBeAgent.js +6 -180
  3. package/lib/AutoBeAgent.js.map +1 -1
  4. package/lib/AutoBeAgentBase.d.ts +18 -0
  5. package/lib/AutoBeAgentBase.js +54 -0
  6. package/lib/AutoBeAgentBase.js.map +1 -0
  7. package/lib/AutoBeMockAgent.d.ts +14 -0
  8. package/lib/AutoBeMockAgent.js +136 -0
  9. package/lib/AutoBeMockAgent.js.map +1 -0
  10. package/lib/constants/AutoBeSystemPromptConstant.d.ts +8 -4
  11. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  12. package/lib/factory/getAutoBeGenerated.d.ts +3 -4
  13. package/lib/factory/getAutoBeGenerated.js +6 -250
  14. package/lib/factory/getAutoBeGenerated.js.map +1 -1
  15. package/lib/index.js +2 -0
  16. package/lib/index.js.map +1 -1
  17. package/lib/index.mjs +886 -396
  18. package/lib/index.mjs.map +1 -1
  19. package/lib/orchestrate/analyze/orchestrateAnalyze.js +6 -1
  20. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  21. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.d.ts +4 -1
  22. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js +8 -3
  23. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js.map +1 -1
  24. package/lib/orchestrate/realize/orchestrateRealize.js +11 -2
  25. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
  26. package/lib/orchestrate/realize/orchestrateRealizeCoder.js +46 -15
  27. package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
  28. package/lib/orchestrate/realize/orchestrateRealizeDecorator.d.ts +10 -0
  29. package/lib/orchestrate/realize/orchestrateRealizeDecorator.js +545 -0
  30. package/lib/orchestrate/realize/orchestrateRealizeDecorator.js.map +1 -0
  31. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +12 -9
  32. package/lib/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.d.ts +85 -0
  33. package/lib/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.js +3 -0
  34. package/lib/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.js.map +1 -0
  35. package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +1 -1
  36. package/lib/orchestrate/realize/transformRealizeCoderHistories.js +24 -30
  37. package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
  38. package/lib/orchestrate/realize/transformRealizeDecorator.d.ts +4 -0
  39. package/lib/orchestrate/realize/transformRealizeDecorator.js +32 -0
  40. package/lib/orchestrate/realize/transformRealizeDecorator.js.map +1 -0
  41. package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.d.ts +6 -0
  42. package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.js +49 -0
  43. package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.js.map +1 -0
  44. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +30 -11
  45. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -1
  46. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  47. package/lib/orchestrate/test/orchestrateTestCorrect.js +2 -1
  48. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  49. package/lib/utils/backoffRetry.d.ts +18 -0
  50. package/lib/utils/backoffRetry.js +38 -0
  51. package/lib/utils/backoffRetry.js.map +1 -1
  52. package/package.json +8 -8
  53. package/src/AutoBeAgent.ts +10 -203
  54. package/src/AutoBeAgentBase.ts +78 -0
  55. package/src/AutoBeMockAgent.ts +164 -0
  56. package/src/constants/AutoBeSystemPromptConstant.ts +8 -4
  57. package/src/factory/getAutoBeGenerated.ts +8 -13
  58. package/src/index.ts +3 -1
  59. package/src/orchestrate/analyze/orchestrateAnalyze.ts +7 -1
  60. package/src/orchestrate/analyze/writeDocumentUntilReviewPassed.ts +14 -1
  61. package/src/orchestrate/realize/orchestrateRealize.ts +11 -0
  62. package/src/orchestrate/realize/orchestrateRealizeCoder.ts +26 -4
  63. package/src/orchestrate/realize/orchestrateRealizeDecorator.ts +286 -0
  64. package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +12 -9
  65. package/src/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.ts +94 -0
  66. package/src/orchestrate/realize/transformRealizeCoderHistories.ts +22 -29
  67. package/src/orchestrate/realize/transformRealizeDecorator.ts +37 -0
  68. package/src/orchestrate/realize/transformRealizeDecoratorCorrectHistories.ts +58 -0
  69. package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +34 -9
  70. package/src/orchestrate/test/orchestrateTest.ts +1 -0
  71. package/src/orchestrate/test/orchestrateTestCorrect.ts +1 -1
  72. package/src/utils/backoffRetry.ts +56 -0
@@ -0,0 +1,164 @@
1
+ import {
2
+ AutoBeAssistantMessageHistory,
3
+ AutoBeEvent,
4
+ AutoBeEventSnapshot,
5
+ AutoBeHistory,
6
+ AutoBeUserMessageContent,
7
+ AutoBeUserMessageHistory,
8
+ IAutoBeAgent,
9
+ IAutoBeCompiler,
10
+ IAutoBeCompilerListener,
11
+ } from "@autobe/interface";
12
+ import { Singleton, sleep_for } from "tstl";
13
+ import { v4 } from "uuid";
14
+
15
+ import { AutoBeAgentBase } from "./AutoBeAgentBase";
16
+ import { AutoBeState } from "./context/AutoBeState";
17
+ import { AutoBeTokenUsage } from "./context/AutoBeTokenUsage";
18
+ import { createAutoBeState } from "./factory/createAutoBeState";
19
+
20
+ /** @internal */
21
+ export class AutoBeMockAgent extends AutoBeAgentBase implements IAutoBeAgent {
22
+ private readonly props_: AutoBeMockAgent.IProps;
23
+ private readonly histories_: AutoBeHistory[];
24
+ private readonly compiler_: Singleton<Promise<IAutoBeCompiler>>;
25
+ private token_usage_: AutoBeTokenUsage;
26
+
27
+ public constructor(props: AutoBeMockAgent.IProps) {
28
+ super({
29
+ compiler: () => this.compiler_.get(),
30
+ state: () => createAutoBeState(this.histories_),
31
+ });
32
+ this.props_ = props;
33
+ this.histories_ = [];
34
+ this.compiler_ = new Singleton(async () =>
35
+ props.compiler({
36
+ realize: {
37
+ test: {
38
+ onOperation: async () => {},
39
+ onReset: async () => {},
40
+ },
41
+ },
42
+ }),
43
+ );
44
+ this.token_usage_ = new AutoBeTokenUsage();
45
+ }
46
+
47
+ public async conversate(
48
+ content: string | AutoBeUserMessageContent | AutoBeUserMessageContent[],
49
+ ): Promise<AutoBeHistory[]> {
50
+ // THE USER-MESSAGE
51
+ const userMessage: AutoBeUserMessageHistory = {
52
+ id: v4(),
53
+ type: "userMessage",
54
+ contents:
55
+ typeof content === "string"
56
+ ? [
57
+ {
58
+ type: "text",
59
+ text: content,
60
+ },
61
+ ]
62
+ : Array.isArray(content)
63
+ ? content
64
+ : [content],
65
+ created_at: new Date().toISOString(),
66
+ };
67
+ void this.dispatch(userMessage).catch(() => {});
68
+
69
+ // ALREADY REALIZED CASE
70
+ const state: AutoBeState = createAutoBeState(this.histories_);
71
+ if (state.test !== null) {
72
+ await sleep_for(2_000);
73
+ const assistantMessage: AutoBeAssistantMessageHistory = {
74
+ id: v4(),
75
+ type: "assistantMessage",
76
+ text: [
77
+ "You've reached to the test agent.",
78
+ "",
79
+ "The realize agent would be developed until 2025-08-31.",
80
+ "",
81
+ "Thanks for using AutoBE!",
82
+ ].join("\n"),
83
+ created_at: new Date().toISOString(),
84
+ completed_at: new Date().toISOString(),
85
+ };
86
+ void this.dispatch(assistantMessage).catch(() => {});
87
+ this.histories_.push(userMessage, assistantMessage);
88
+ return this.histories_;
89
+ }
90
+ const take = async (
91
+ type: "analyze" | "prisma" | "interface" | "test",
92
+ ): Promise<void> => {
93
+ for (const s of this.getEventSnapshots(type)) {
94
+ await sleep_for(sleepMap[s.event.type] ?? 500);
95
+ void this.dispatch(s.event).catch(() => {});
96
+ this.token_usage_ = new AutoBeTokenUsage(s.tokenUsage);
97
+ }
98
+ this.histories_.push(userMessage);
99
+ this.histories_.push(
100
+ this.props_.preset.histories.find((h) => h.type === type)!,
101
+ );
102
+ };
103
+ if (state.analyze === null) await take("analyze");
104
+ else if (state.prisma === null) await take("prisma");
105
+ else if (state.interface === null) await take("interface");
106
+ else if (state.test === null) await take("test");
107
+ return this.histories_;
108
+ }
109
+
110
+ public getHistories(): AutoBeHistory[] {
111
+ return this.histories_;
112
+ }
113
+
114
+ public getTokenUsage(): AutoBeTokenUsage {
115
+ return this.token_usage_;
116
+ }
117
+
118
+ private getEventSnapshots(
119
+ state: "analyze" | "prisma" | "interface" | "test",
120
+ ): AutoBeEventSnapshot[] {
121
+ return this.props_.preset[state];
122
+ }
123
+ }
124
+ export namespace AutoBeMockAgent {
125
+ export interface IProps {
126
+ compiler: (
127
+ listener: IAutoBeCompilerListener,
128
+ ) => IAutoBeCompiler | Promise<IAutoBeCompiler>;
129
+ preset: IPreset;
130
+ }
131
+ export interface IPreset {
132
+ histories: AutoBeHistory[];
133
+ analyze: AutoBeEventSnapshot[];
134
+ prisma: AutoBeEventSnapshot[];
135
+ interface: AutoBeEventSnapshot[];
136
+ test: AutoBeEventSnapshot[];
137
+ }
138
+ }
139
+
140
+ const sleepMap: Partial<Record<AutoBeEvent.Type, number>> = {
141
+ analyzeStart: 1_000,
142
+ analyzeWrite: 500,
143
+ analyzeReview: 300,
144
+ analyzeComplete: 1_000,
145
+ prismaStart: 1_000,
146
+ prismaComponents: 1_000,
147
+ prismaSchemas: 500,
148
+ prismaValidate: 2_000,
149
+ prismaCorrect: 500,
150
+ prismaInsufficient: 1_000,
151
+ prismaComplete: 1_000,
152
+ interfaceStart: 1_000,
153
+ interfaceEndpoints: 1_000,
154
+ interfaceOperations: 400,
155
+ interfaceComponents: 400,
156
+ interfaceComplement: 2_000,
157
+ interfaceComplete: 1_000,
158
+ testStart: 1_000,
159
+ testScenario: 1_000,
160
+ testWrite: 40,
161
+ testValidate: 100,
162
+ testCorrect: 100,
163
+ testComplete: 1_000,
164
+ };