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