@autobe/agent 0.25.3 → 0.25.4

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.
@@ -62,7 +62,7 @@ function orchestratePrismaCorrect(ctx, application) {
62
62
  return true;
63
63
  });
64
64
  application.files = application.files.filter((f) => f.models.length !== 0);
65
- return iterate(ctx, application, Math.max(ctx.retry, 5));
65
+ return iterate(ctx, application, Math.max(ctx.retry, 8));
66
66
  }
67
67
  function iterate(ctx, application, life) {
68
68
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobe/agent",
3
- "version": "0.25.3",
3
+ "version": "0.25.4",
4
4
  "description": "AI backend server code generator",
5
5
  "main": "lib/index.js",
6
6
  "author": "Wrtn Technologies",
@@ -27,8 +27,8 @@
27
27
  "tstl": "^3.0.0",
28
28
  "typia": "^9.7.2",
29
29
  "uuid": "^11.1.0",
30
- "@autobe/utils": "^0.25.3",
31
- "@autobe/interface": "^0.25.3"
30
+ "@autobe/interface": "^0.25.4",
31
+ "@autobe/utils": "^0.25.4"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@rollup/plugin-json": "^6.1.0",
@@ -40,8 +40,8 @@
40
40
  "ts-node": "^10.9.2",
41
41
  "ts-patch": "^3.3.0",
42
42
  "typescript": "~5.9.2",
43
- "@autobe/compiler": "^0.25.3",
44
- "@autobe/filesystem": "^0.25.3"
43
+ "@autobe/compiler": "^0.25.4",
44
+ "@autobe/filesystem": "^0.25.4"
45
45
  },
46
46
  "keywords": [
47
47
  "ai",
@@ -27,6 +27,7 @@ import { createAgenticaHistory } from "./factory/createAgenticaHistory";
27
27
  import { createAutoBeController } from "./factory/createAutoBeApplication";
28
28
  import { createAutoBeContext } from "./factory/createAutoBeContext";
29
29
  import { createAutoBeState } from "./factory/createAutoBeState";
30
+ import { supportMistral } from "./factory/supportMistral";
30
31
  import { transformFacadeStateMessage } from "./orchestrate/facade/transformFacadeStateMessage";
31
32
  import { IAutoBeProps } from "./structures/IAutoBeProps";
32
33
  import { randomBackoffStrategy } from "./utils/backoffRetry";
@@ -162,6 +163,7 @@ export class AutoBeAgent<Model extends ILlmSchema.Model>
162
163
  }),
163
164
  ],
164
165
  });
166
+ supportMistral(this.agentica_, props.vendor);
165
167
 
166
168
  // HISTORIES MANIPULATION
167
169
  this.agentica_.getHistories().push(
@@ -16,6 +16,7 @@ import { AutoBeConfigConstant } from "../constants/AutoBeConfigConstant";
16
16
  import { AutoBeSystemPromptConstant } from "../constants/AutoBeSystemPromptConstant";
17
17
  import { IAutoBeConfig } from "../structures/IAutoBeConfig";
18
18
  import { IAutoBeVendor } from "../structures/IAutoBeVendor";
19
+ import { supportMistral } from "./supportMistral";
19
20
 
20
21
  export const consentFunctionCall = async (props: {
21
22
  dispatch: (event: AutoBeEvent) => void;
@@ -67,6 +68,8 @@ export const consentFunctionCall = async (props: {
67
68
  } satisfies IConsentApplication),
68
69
  ],
69
70
  });
71
+ supportMistral(agent, props.vendor);
72
+
70
73
  const histories: MicroAgenticaHistory<"chatgpt">[] = await agent.conversate(
71
74
  "Analyze and judge this assistant message please.",
72
75
  );
@@ -41,6 +41,7 @@ import { AutoBeTimeoutError } from "../utils/AutoBeTimeoutError";
41
41
  import { TimedConversation } from "../utils/TimedConversation";
42
42
  import { consentFunctionCall } from "./consentFunctionCall";
43
43
  import { getCriticalCompiler } from "./getCriticalCompiler";
44
+ import { supportMistral } from "./supportMistral";
44
45
 
45
46
  export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
46
47
  model: Model;
@@ -104,6 +105,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
104
105
  histories: next.histories,
105
106
  controllers: [next.controller],
106
107
  });
108
+ supportMistral(agent, props.vendor);
107
109
 
108
110
  // ADD EVENT LISTENERS
109
111
  agent.on("request", async (event) => {
@@ -0,0 +1,122 @@
1
+ import { MicroAgentica } from "@agentica/core";
2
+ import { ILlmSchema } from "@samchon/openapi";
3
+ import OpenAI from "openai";
4
+
5
+ import { IAutoBeVendor } from "../structures/IAutoBeVendor";
6
+
7
+ export const supportMistral = <Model extends ILlmSchema.Model>(
8
+ agent: MicroAgentica<Model>,
9
+ vendor: IAutoBeVendor,
10
+ ): void => {
11
+ if (
12
+ vendor.model.includes("mistral") ||
13
+ vendor.model.includes("devstral") ||
14
+ vendor.model.includes("codestral")
15
+ ) {
16
+ agent.on("request", async (e) => {
17
+ const newMessages: OpenAI.ChatCompletionMessageParam[] = [];
18
+ for (const m of e.body.messages) {
19
+ newMessages.push(m);
20
+ if (m.role === "tool") {
21
+ m.tool_call_id = uuidToShortId(m.tool_call_id);
22
+ newMessages.push({
23
+ role: "assistant",
24
+ content: "A tool has been called.",
25
+ });
26
+ } else if (m.role === "assistant") {
27
+ for (const call of m.tool_calls ?? [])
28
+ call.id = uuidToShortId(call.id);
29
+ }
30
+ }
31
+ e.body.messages = newMessages;
32
+ });
33
+
34
+ // agent.on("request", (e) => {
35
+ // const toolCalls: OpenAI.ChatCompletionMessageFunctionToolCall[] =
36
+ // e.body.messages
37
+ // .filter((m) => m.role === "assistant")
38
+ // .filter((m) => !!m.tool_calls?.length)
39
+ // .map((m) => m.tool_calls ?? [])
40
+ // .flat()
41
+ // .filter((c) => c.type === "function");
42
+ // e.body.messages.forEach((m, i, array) => {
43
+ // if (m.role !== "tool") return;
44
+ // const call: OpenAI.ChatCompletionMessageFunctionToolCall | undefined =
45
+ // toolCalls.find((c) => c.id === m.tool_call_id);
46
+ // const content: string = getFunctionCallMessage(m, call);
47
+ // array[i] = {
48
+ // role: "assistant",
49
+ // content,
50
+ // };
51
+ // });
52
+ // e.body.messages = e.body.messages.filter(
53
+ // (m) => m.role !== "assistant" || !m.tool_calls?.length,
54
+ // );
55
+ // });
56
+ }
57
+ };
58
+
59
+ // const getFunctionCallMessage = (
60
+ // param: OpenAI.ChatCompletionToolMessageParam,
61
+ // call: OpenAI.ChatCompletionMessageFunctionToolCall | undefined,
62
+ // ): string => {
63
+ // if (call === undefined) {
64
+ // // unreachable
65
+ // return StringUtil.trim`
66
+ // ## Function Call
67
+
68
+ // A function has been called, but could not find its arguments.
69
+
70
+ // - id: ${param.tool_call_id}
71
+ // - content: ${param.content}
72
+ // `;
73
+ // }
74
+ // return StringUtil.trim`
75
+ // ## Function Call
76
+
77
+ // - id: ${call.id}
78
+ // - function name: ${call.function.name}
79
+ // - arguments: ${JSON.stringify(call.function.arguments)}
80
+ // - content: ${param.content}
81
+ // `;
82
+ // };
83
+
84
+ const BASE62_CHARS =
85
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
86
+
87
+ function simpleHash(str: string): number {
88
+ let h1 = 0xdeadbeef;
89
+ let h2 = 0x41c6ce57;
90
+
91
+ for (let i = 0; i < str.length; i++) {
92
+ const ch = str.charCodeAt(i);
93
+ h1 = Math.imul(h1 ^ ch, 2654435761);
94
+ h2 = Math.imul(h2 ^ ch, 1597334677);
95
+ }
96
+
97
+ h1 =
98
+ Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
99
+ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
100
+ h2 =
101
+ Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
102
+ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
103
+
104
+ return 4294967296 * (2097151 & h2) + (h1 >>> 0);
105
+ }
106
+
107
+ function toBase62(num: number, length: number): string {
108
+ let result = "";
109
+ let n = num;
110
+
111
+ while (n > 0 && result.length < length) {
112
+ result = BASE62_CHARS[n % 62] + result;
113
+ n = Math.floor(n / 62);
114
+ }
115
+
116
+ return result.padStart(length, "0");
117
+ }
118
+
119
+ function uuidToShortId(uuid: string): string {
120
+ const hash = simpleHash(uuid);
121
+ return toBase62(hash, 9);
122
+ }
@@ -27,7 +27,7 @@ export function orchestratePrismaCorrect<Model extends ILlmSchema.Model>(
27
27
  return true;
28
28
  });
29
29
  application.files = application.files.filter((f) => f.models.length !== 0);
30
- return iterate(ctx, application, Math.max(ctx.retry, 5));
30
+ return iterate(ctx, application, Math.max(ctx.retry, 8));
31
31
  }
32
32
 
33
33
  async function iterate<Model extends ILlmSchema.Model>(