@autobe/agent 0.29.1 → 0.29.2

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 (38) hide show
  1. package/lib/AutoBeAgent.d.ts +2 -1
  2. package/lib/AutoBeAgent.js +13 -4
  3. package/lib/AutoBeAgent.js.map +1 -1
  4. package/lib/AutoBeAgentBase.d.ts +2 -3
  5. package/lib/AutoBeAgentBase.js +1 -8
  6. package/lib/AutoBeAgentBase.js.map +1 -1
  7. package/lib/AutoBeMockAgent.js +13 -4
  8. package/lib/AutoBeMockAgent.js.map +1 -1
  9. package/lib/factory/getAutoBeGenerated.d.ts +7 -1
  10. package/lib/factory/getAutoBeGenerated.js +138 -33
  11. package/lib/factory/getAutoBeGenerated.js.map +1 -1
  12. package/lib/factory/getAutoBeRealizeGenerated.js +2 -2
  13. package/lib/factory/getAutoBeRealizeGenerated.js.map +1 -1
  14. package/lib/factory/getCriticalCompiler.js +2 -4
  15. package/lib/factory/getCriticalCompiler.js.map +1 -1
  16. package/lib/index.mjs +136 -75
  17. package/lib/index.mjs.map +1 -1
  18. package/lib/orchestrate/realize/internal/compileRealizeFiles.js +2 -1
  19. package/lib/orchestrate/realize/internal/compileRealizeFiles.js.map +1 -1
  20. package/lib/orchestrate/realize/orchestrateRealizeAuthorizationWrite.js +2 -1
  21. package/lib/orchestrate/realize/orchestrateRealizeAuthorizationWrite.js.map +1 -1
  22. package/lib/orchestrate/realize/utils/getRealizeWriteDto.js +1 -1
  23. package/lib/orchestrate/realize/utils/getRealizeWriteDto.js.map +1 -1
  24. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js +1 -1
  25. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -1
  26. package/lib/orchestrate/test/orchestrateTestCorrect.js +1 -1
  27. package/package.json +5 -5
  28. package/src/AutoBeAgent.ts +15 -4
  29. package/src/AutoBeAgentBase.ts +3 -12
  30. package/src/AutoBeMockAgent.ts +15 -4
  31. package/src/factory/getAutoBeGenerated.ts +203 -42
  32. package/src/factory/getAutoBeRealizeGenerated.ts +0 -1
  33. package/src/factory/getCriticalCompiler.ts +3 -5
  34. package/src/orchestrate/realize/internal/compileRealizeFiles.ts +4 -4
  35. package/src/orchestrate/realize/orchestrateRealizeAuthorizationWrite.ts +2 -1
  36. package/src/orchestrate/realize/utils/getRealizeWriteDto.ts +1 -2
  37. package/src/orchestrate/test/compile/getTestScenarioArtifacts.ts +1 -1
  38. package/src/orchestrate/test/orchestrateTestCorrect.ts +1 -1
package/lib/index.mjs CHANGED
@@ -30,55 +30,6 @@ import * as __typia_transform__isUniqueItems from "typia/lib/internal/_isUniqueI
30
30
 
31
31
  import * as __typia_transform__createStandardSchema from "typia/lib/internal/_createStandardSchema.js";
32
32
 
33
- const getAutoBeRealizeGenerated = async props => ({
34
- ...Object.fromEntries(props.functions.map(f => [ f.location, f.content ])),
35
- ...Object.fromEntries(props.authorizations.map(auth => [ [ auth.decorator.location, auth.decorator.content ], [ auth.provider.location, auth.provider.content ], [ auth.payload.location, auth.payload.content ] ]).flat()),
36
- ...await props.compiler.realize.getTemplate(props.options),
37
- ...await props.compiler.realize.controller({
38
- document: props.document,
39
- functions: props.functions,
40
- authorizations: props.authorizations
41
- })
42
- });
43
-
44
- async function getAutoBeGenerated(compiler, state, histories, tokenUsage, options) {
45
- const ret = {};
46
- if (state.analyze === null) return {};
47
- Object.assign(ret, Object.fromEntries(state.analyze.files.map(file => [ `docs/analysis/${file.filename.split("/").at(-1)}`, file.content ])));
48
- if (options?.stage === "analyze") return ret;
49
- if (state.prisma?.step === state.analyze.step) {
50
- const schemaFiles = (options?.dbms ?? "postgres") === "postgres" ? state.prisma.schemas : await compiler.prisma.write(state.prisma.result.data, options.dbms);
51
- Object.assign(ret, Object.fromEntries(Object.entries(schemaFiles).map(([key, value]) => [ `prisma/schema/${key.split("/").at(-1)}`, value ])), {
52
- "autobe/prisma.json": JSON.stringify(state.prisma.result.data)
53
- });
54
- if (state.prisma.compiled.type === "success") ret["docs/ERD.md"] = state.prisma.compiled.document; else if (state.prisma.compiled.type === "failure") ret["prisma/compile-error-reason.log"] = state.prisma.compiled.reason;
55
- }
56
- if (options?.stage === "prisma") return ret;
57
- if (state.interface?.step === state.analyze.step) {
58
- const files = await compiler.interface.write(state.interface.document);
59
- Object.assign(ret, state.test?.step === state.interface.step ? Object.fromEntries(Object.entries(files).filter(([key]) => key.startsWith("test/features/") === false)) : files, {
60
- "autobe/document.json": JSON.stringify(state.interface.document)
61
- });
62
- }
63
- if (options?.stage === "interface") return ret;
64
- if (state.test?.step === state.analyze.step) Object.assign(ret, Object.fromEntries(state.test.files.map(f => [ f.location, f.content ])), await compiler.test.getTemplate());
65
- if (state.realize?.step === state.analyze.step) Object.assign(ret, await getAutoBeRealizeGenerated({
66
- compiler,
67
- document: state.interface.document,
68
- authorizations: state.realize.authorizations,
69
- functions: state.realize.functions,
70
- options: {
71
- dbms: options?.dbms ?? "postgres"
72
- }
73
- }));
74
- if (options?.stage === "test") return ret;
75
- Object.assign(ret, {
76
- "autobe/histories.json": JSON.stringify(histories),
77
- "autobe/tokenUsage.json": JSON.stringify(tokenUsage)
78
- });
79
- return ret;
80
- }
81
-
82
33
  function emplaceMap(dict, key, generator) {
83
34
  const oldbie = dict.get(key);
84
35
  if (oldbie !== undefined) {
@@ -90,13 +41,9 @@ function emplaceMap(dict, key, generator) {
90
41
  }
91
42
 
92
43
  class AutoBeAgentBase {
93
- constructor(asset) {
94
- this.asset = asset;
44
+ constructor() {
95
45
  this.listeners_ = new Map;
96
46
  }
97
- async getFiles(options) {
98
- return getAutoBeGenerated(await this.asset.compiler(), this.asset.state(), this.getHistories(), this.getTokenUsage(), options);
99
- }
100
47
  on(type, listener) {
101
48
  emplaceMap(this.listeners_, type, () => new Set).add(listener);
102
49
  return this;
@@ -605,10 +552,9 @@ const getCriticalCompiler = (critical, compiler) => {
605
552
  write: (app, dmbs) => lock(() => compiler.prisma.write(app, dmbs))
606
553
  },
607
554
  interface: {
608
- write: doc => lock(() => compiler.interface.write(doc)),
555
+ write: (doc, exclude) => lock(() => compiler.interface.write(doc, exclude)),
609
556
  transform: doc => lock(() => compiler.interface.transform(doc)),
610
- invert: doc => lock(() => compiler.interface.invert(doc)),
611
- getTemplate: () => lock(() => compiler.interface.getTemplate())
557
+ invert: doc => lock(() => compiler.interface.invert(doc))
612
558
  },
613
559
  typescript: {
614
560
  compile: props => lock(() => compiler.typescript.compile(props)),
@@ -619,14 +565,13 @@ const getCriticalCompiler = (critical, compiler) => {
619
565
  compile: props => lock(() => compiler.test.compile(props)),
620
566
  validate: props => lock(() => compiler.test.validate(props)),
621
567
  write: props => lock(() => compiler.test.write(props)),
622
- getExternal: () => lock(() => compiler.test.getExternal()),
623
- getTemplate: () => lock(() => compiler.test.getTemplate())
568
+ getExternal: () => lock(() => compiler.test.getExternal())
624
569
  },
625
570
  realize: {
626
571
  controller: props => lock(() => compiler.realize.controller(props)),
627
- test: props => lock(() => compiler.realize.test(props)),
628
- getTemplate: options => lock(() => compiler.realize.getTemplate(options))
629
- }
572
+ test: props => lock(() => compiler.realize.test(props))
573
+ },
574
+ getTemplate: options => lock(() => compiler.getTemplate(options))
630
575
  };
631
576
  };
632
577
 
@@ -963,6 +908,108 @@ const createAutoBeState = histories => {
963
908
  };
964
909
  };
965
910
 
911
+ const getAutoBeRealizeGenerated = async props => ({
912
+ ...Object.fromEntries(props.functions.map(f => [ f.location, f.content ])),
913
+ ...Object.fromEntries(props.authorizations.map(auth => [ [ auth.decorator.location, auth.decorator.content ], [ auth.provider.location, auth.provider.content ], [ auth.payload.location, auth.payload.content ] ]).flat()),
914
+ ...await props.compiler.realize.controller({
915
+ document: props.document,
916
+ functions: props.functions,
917
+ authorizations: props.authorizations
918
+ })
919
+ });
920
+
921
+ async function getAutoBeGenerated(props) {
922
+ const options = {
923
+ phase: props.options?.phase ?? props.state.realize ? "realize" : props.state.test ? "test" : props.state.interface ? "interface" : "analyze",
924
+ dbms: props.options?.dbms ?? "postgres"
925
+ };
926
+ const ret = await props.compiler.getTemplate(options);
927
+ ret["README.md"] = writeReadMe(props.state, ret["README.md"]);
928
+ if (props.state.analyze === null) return ret;
929
+ Object.assign(ret, Object.fromEntries(props.state.analyze.files.map(file => [ `docs/analysis/${file.filename.split("/").at(-1)}`, file.content ])));
930
+ if (props.options?.phase === "analyze") return ret;
931
+ if (props.state.prisma?.step === props.state.analyze.step) {
932
+ const schemaFiles = (options?.dbms ?? "postgres") === "postgres" ? props.state.prisma.schemas : await props.compiler.prisma.write(props.state.prisma.result.data, options.dbms);
933
+ Object.assign(ret, Object.fromEntries(Object.entries(schemaFiles).map(([key, value]) => [ `prisma/schema/${key.split("/").at(-1)}`, value ])), {
934
+ "autobe/prisma.json": JSON.stringify(props.state.prisma.result.data)
935
+ });
936
+ if (props.state.prisma.compiled.type === "success") ret["docs/ERD.md"] = props.state.prisma.compiled.document; else if (props.state.prisma.compiled.type === "failure") ret["prisma/compile-error-reason.log"] = props.state.prisma.compiled.reason;
937
+ }
938
+ if (props.options?.phase === "prisma") return ret;
939
+ if (props.state.interface?.step === props.state.analyze.step) {
940
+ const files = await props.compiler.interface.write(props.state.interface.document, Object.keys(ret));
941
+ Object.assign(ret, props.state.test?.step === props.state.interface.step ? Object.fromEntries(Object.entries(files).filter(([key]) => key.startsWith("test/features/") === false)) : files, {
942
+ "autobe/document.json": JSON.stringify(props.state.interface.document)
943
+ });
944
+ }
945
+ if (props.options?.phase === "interface") return ret;
946
+ if (props.state.test?.step === props.state.analyze.step) Object.assign(ret, Object.fromEntries(props.state.test.files.map(f => [ f.location, f.content ])));
947
+ if (props.state.realize?.step === props.state.analyze.step) Object.assign(ret, await getAutoBeRealizeGenerated({
948
+ compiler: props.compiler,
949
+ document: props.state.interface.document,
950
+ authorizations: props.state.realize.authorizations,
951
+ functions: props.state.realize.functions,
952
+ options: {
953
+ dbms: options?.dbms ?? "postgres"
954
+ }
955
+ }));
956
+ if (props.options?.phase === "test") return ret;
957
+ Object.assign(ret, {
958
+ "autobe/histories.json": JSON.stringify(props.histories),
959
+ "autobe/tokenUsage.json": JSON.stringify(props.tokenUsage)
960
+ });
961
+ return ret;
962
+ }
963
+
964
+ function writeReadMe(state, readme) {
965
+ const emoji = history => history ? success(history) ? "✅" : "❌" : "⬜";
966
+ return readme.replaceAll("{{ANALYSIS_EMOJI}}", emoji(state.analyze)).replaceAll("{{PRISMA_EMOJI}}", emoji(state.prisma)).replaceAll("{{INTERFACE_EMOJI}}", emoji(state.interface)).replaceAll("{{TEST_EMOJI}}", emoji(state.test)).replaceAll("{{REALIZE_EMOJI}}", emoji(state.realize)).replaceAll("{{BENCHMARK_AGGREGATE}}", writeBenchmarkAggregate(state)).replaceAll("{{BENCHMARK_FUNCTION_CALLING}}", writeBenchmarkFunctionCalling(state));
967
+ }
968
+
969
+ function writeBenchmarkAggregate(state) {
970
+ return [ "analyze", "prisma", "interface", "test", "realize" ].map(key => {
971
+ const h = state[key];
972
+ if (h === null) return `⬜ ${key} | | | | `;
973
+ return [ `${success(h) ? "✅" : "❌"} ${h.type}`, Object.entries(label(h)).map(([k, v]) => `${k}: ${v.toLocaleString()}`).join(", "), (h.aggregates.total.metric.success / h.aggregates.total.metric.attempt * 100).toFixed(2) + " %", h.aggregates.total.tokenUsage.total.toLocaleString(), Math.round((new Date(h.completed_at).getTime() - new Date(h.created_at).getTime()) / 1e3) + " sec" ].join(" | ");
974
+ }).join("\n");
975
+ }
976
+
977
+ function writeBenchmarkFunctionCalling(state) {
978
+ const aggregates = AutoBeProcessAggregateFactory.reduce([ state.analyze, state.prisma, state.interface, state.test, state.realize ].filter(h => h !== null).map(h => h.aggregates));
979
+ return Object.entries(aggregates).map(([key, value]) => [ key, value.metric.attempt.toLocaleString(), value.metric.validationFailure.toLocaleString(), value.metric.invalidJson.toLocaleString(), value.metric.success.toLocaleString(), (value.metric.success / value.metric.attempt * 100).toFixed(2) + " %" ].join(" | ")).join("\n");
980
+ }
981
+
982
+ function success(history) {
983
+ if (history.type === "analyze") return true; else if (history.type === "interface") return history.missed.length === 0; else if (history.type === "prisma" || history.type === "test" || history.type === "realize") return history.compiled.type === "success";
984
+ throw new Error("Unknown history type encountered.");
985
+ }
986
+
987
+ function label(history) {
988
+ if (history.type === "analyze") return {
989
+ actors: history.actors.length,
990
+ documents: history.files.length
991
+ }; else if (history.type === "prisma") return {
992
+ namespaces: history.result.data.files.length,
993
+ models: history.result.data.files.map(f => f.models).flat().length
994
+ }; else if (history.type === "interface") return {
995
+ operations: history.document.operations.length,
996
+ schemas: Object.keys(history.document.components.schemas).length
997
+ }; else if (history.type === "test") {
998
+ return {
999
+ functions: history.files.length,
1000
+ ...history.compiled.type === "failure" ? {
1001
+ errors: new Set(history.compiled.diagnostics.map(d => d.file ?? "")).size
1002
+ } : {}
1003
+ };
1004
+ } else if (history.type === "realize") return {
1005
+ functions: history.functions.length,
1006
+ ...history.compiled.type === "failure" ? {
1007
+ errors: new Set(history.compiled.diagnostics.map(d => d.file ?? "")).size
1008
+ } : {}
1009
+ };
1010
+ throw new Error("Unknown history type encountered.");
1011
+ }
1012
+
966
1013
  function assertSchemaModel(model) {
967
1014
  if (model === "3.0") throw new Error([ "Error on AutoBeAgent.constructor(): schema version 3.0 is not supported", "due to limitations in the JSON schema specification for function calling.", "Please use a different model that supports modern JSON schema features." ].join(" "));
968
1015
  }
@@ -51692,7 +51739,8 @@ async function compileRealizeFiles(ctx, props) {
51692
51739
  const prisma = ctx.state().prisma?.compiled;
51693
51740
  const payloads = Object.fromEntries(props.authorizations.map(el => [ el.payload.location, el.payload.content ]));
51694
51741
  const compiler = await ctx.compiler();
51695
- const templateFiles = await compiler.realize.getTemplate({
51742
+ const templateFiles = await compiler.getTemplate({
51743
+ phase: "realize",
51696
51744
  dbms: "sqlite"
51697
51745
  });
51698
51746
  const nodeModules = prisma?.type === "success" ? prisma.nodeModules : {};
@@ -53202,7 +53250,8 @@ async function orchestrateRealizeAuthorizationWrite(ctx) {
53202
53250
  total: actors.length,
53203
53251
  completed: 0
53204
53252
  };
53205
- const templates = await (await ctx.compiler()).realize.getTemplate({
53253
+ const templates = await (await ctx.compiler()).getTemplate({
53254
+ phase: "realize",
53206
53255
  dbms: "sqlite"
53207
53256
  });
53208
53257
  const authorizations = await executeCachedBatch(ctx, actors.map(a => promptCacheKey => process$4(ctx, {
@@ -54859,7 +54908,7 @@ function filterDiagnostics(failures, locations) {
54859
54908
  async function getRealizeWriteDto(ctx, operation) {
54860
54909
  const document = filterDocument$1(operation, ctx.state().interface.document);
54861
54910
  const compiler = await ctx.compiler();
54862
- const entries = Object.entries(await compiler.interface.write(document));
54911
+ const entries = Object.entries(await compiler.interface.write(document, []));
54863
54912
  const filter = (prefix, exclude) => {
54864
54913
  const result = entries.filter(([key]) => key.startsWith(prefix) === true);
54865
54914
  return Object.fromEntries(result);
@@ -59411,7 +59460,7 @@ const correct = async (ctx, props, life) => {
59411
59460
  pointer.value.draft = await completeTestCode(ctx, props.function.artifacts, pointer.value.draft);
59412
59461
  ctx.dispatch({
59413
59462
  type: "testCorrect",
59414
- kind: "casting",
59463
+ kind: "overall",
59415
59464
  id: v7(),
59416
59465
  created_at: (new Date).toISOString(),
59417
59466
  file: props.validate.file,
@@ -63865,7 +63914,7 @@ const getTestTemplateCode = (scenario, document) => StringUtil.trim`
63865
63914
  async function getTestScenarioArtifacts(ctx, scenario) {
63866
63915
  const compiler = await ctx.compiler();
63867
63916
  const document = filterDocument(scenario, ctx.state().interface.document);
63868
- const entries = Object.entries(await compiler.interface.write(document));
63917
+ const entries = Object.entries(await compiler.interface.write(document, []));
63869
63918
  const filter = (prefix, exclude) => {
63870
63919
  const result = entries.filter(([key]) => key.startsWith(prefix) === true);
63871
63920
  return Object.fromEntries(exclude ? result.filter(([key]) => key.startsWith(exclude) === false) : result);
@@ -65700,10 +65749,7 @@ function isRetryError(error) {
65700
65749
 
65701
65750
  class AutoBeAgent extends AutoBeAgentBase {
65702
65751
  constructor(props) {
65703
- super({
65704
- compiler: () => this.context_.compiler(),
65705
- state: () => this.state_
65706
- });
65752
+ super();
65707
65753
  this.props_ = props;
65708
65754
  this.histories_ = props.histories?.slice() ?? [];
65709
65755
  this.state_ = createAutoBeState(this.histories_);
@@ -65857,6 +65903,15 @@ class AutoBeAgent extends AutoBeAgentBase {
65857
65903
  getTokenUsage() {
65858
65904
  return this.usage_;
65859
65905
  }
65906
+ async getFiles(options) {
65907
+ return await getAutoBeGenerated({
65908
+ compiler: await this.context_.compiler(),
65909
+ state: this.state_,
65910
+ histories: this.getHistories(),
65911
+ tokenUsage: this.getTokenUsage(),
65912
+ options
65913
+ });
65914
+ }
65860
65915
  getAggregates(latest = false) {
65861
65916
  if (latest === false) return this.aggregates_;
65862
65917
  const state = this.context_.state();
@@ -65887,10 +65942,7 @@ var index = Object.freeze({
65887
65942
 
65888
65943
  class AutoBeMockAgent extends AutoBeAgentBase {
65889
65944
  constructor(props) {
65890
- super({
65891
- compiler: () => this.compiler_.get(),
65892
- state: () => createAutoBeState(this.histories_)
65893
- });
65945
+ super();
65894
65946
  this.props_ = props;
65895
65947
  this.histories_ = [];
65896
65948
  this.compiler_ = new Singleton(async () => props.compiler({
@@ -65959,6 +66011,15 @@ class AutoBeMockAgent extends AutoBeAgentBase {
65959
66011
  getTokenUsage() {
65960
66012
  return this.token_usage_;
65961
66013
  }
66014
+ async getFiles(options) {
66015
+ return await getAutoBeGenerated({
66016
+ compiler: await this.compiler_.get(),
66017
+ state: createAutoBeState(this.histories_),
66018
+ histories: this.getHistories(),
66019
+ tokenUsage: this.getTokenUsage(),
66020
+ options
66021
+ });
66022
+ }
65962
66023
  getPhase() {
65963
66024
  const state = createAutoBeState(this.histories_);
65964
66025
  if (state.analyze === null) return null; else if (state.realize?.step === state.analyze.step) return "realize"; else if (state.test?.step === state.analyze.step) return "test"; else if (state.interface?.step === state.analyze.step) return "interface"; else if (state.prisma?.step === state.analyze.step) return "prisma";