@agentica/core 0.12.21 → 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 (205) hide show
  1. package/README.md +50 -47
  2. package/lib/Agentica.d.ts +9 -9
  3. package/lib/Agentica.js +23 -16
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/chatgpt/ChatGptAgent.d.ts +7 -7
  6. package/lib/chatgpt/ChatGptAgent.js +17 -12
  7. package/lib/chatgpt/ChatGptAgent.js.map +1 -1
  8. package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +7 -6
  9. package/lib/chatgpt/ChatGptCallFunctionAgent.js +121 -81
  10. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
  11. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +9 -7
  12. package/lib/chatgpt/ChatGptCancelFunctionAgent.js +177 -145
  13. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
  14. package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +13 -8
  15. package/lib/chatgpt/ChatGptCompletionMessageUtil.js +499 -489
  16. package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -1
  17. package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +7 -6
  18. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +33 -32
  19. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
  20. package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +7 -6
  21. package/lib/chatgpt/ChatGptHistoryDecoder.js +60 -56
  22. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
  23. package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +7 -6
  24. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +121 -116
  25. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
  26. package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +20 -5
  27. package/lib/chatgpt/ChatGptSelectFunctionAgent.js +183 -150
  28. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
  29. package/lib/chatgpt/ChatGptUsageAggregator.d.ts +9 -6
  30. package/lib/chatgpt/ChatGptUsageAggregator.js +46 -41
  31. package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -1
  32. package/lib/context/AgenticaCancelPrompt.d.ts +3 -3
  33. package/lib/context/AgenticaCancelPrompt.js +1 -1
  34. package/lib/context/AgenticaCancelPrompt.js.map +1 -1
  35. package/lib/context/AgenticaClassOperation.d.ts +1 -1
  36. package/lib/context/AgenticaClassOperation.js.map +1 -1
  37. package/lib/context/AgenticaContext.d.ts +9 -9
  38. package/lib/context/AgenticaHttpOperation.d.ts +1 -1
  39. package/lib/context/AgenticaHttpOperation.js.map +1 -1
  40. package/lib/context/AgenticaOperation.d.ts +4 -4
  41. package/lib/context/AgenticaOperationBase.d.ts +1 -1
  42. package/lib/context/AgenticaOperationCollection.d.ts +2 -2
  43. package/lib/context/AgenticaOperationSelection.d.ts +3 -3
  44. package/lib/context/AgenticaTokenUsage.d.ts +1 -1
  45. package/lib/context/AgenticaTokenUsage.js.map +1 -1
  46. package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +11 -10
  47. package/lib/context/internal/AgenticaTokenUsageAggregator.js +42 -43
  48. package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -1
  49. package/lib/context/internal/__IChatCancelFunctionsApplication.d.ts +2 -2
  50. package/lib/context/internal/__IChatInitialApplication.d.ts +2 -2
  51. package/lib/context/internal/__IChatSelectFunctionsApplication.d.ts +2 -2
  52. package/lib/events/AgenticaCallEvent.d.ts +3 -3
  53. package/lib/events/AgenticaCancelEvent.d.ts +3 -3
  54. package/lib/events/AgenticaDescribeEvent.d.ts +3 -3
  55. package/lib/events/AgenticaDescribeEvent.js +13 -2
  56. package/lib/events/AgenticaDescribeEvent.js.map +1 -1
  57. package/lib/events/AgenticaEvent.d.ts +12 -12
  58. package/lib/events/AgenticaExecuteEvent.d.ts +7 -7
  59. package/lib/events/AgenticaInitializeEvent.d.ts +1 -1
  60. package/lib/events/AgenticaRequestEvent.d.ts +3 -3
  61. package/lib/events/AgenticaRequestEvent.js.map +1 -1
  62. package/lib/events/AgenticaResponseEvent.d.ts +2 -2
  63. package/lib/events/AgenticaResponseEvent.js.map +1 -1
  64. package/lib/events/AgenticaSelectEvent.d.ts +3 -3
  65. package/lib/events/AgenticaSelectEvent.js.map +1 -1
  66. package/lib/events/AgenticaTextEvent.d.ts +1 -1
  67. package/lib/events/AgenticaTextEvent.js +12 -1
  68. package/lib/events/AgenticaTextEvent.js.map +1 -1
  69. package/lib/functional/assertHttpLlmApplication.d.ts +4 -3
  70. package/lib/functional/assertHttpLlmApplication.js +9339 -9338
  71. package/lib/functional/assertHttpLlmApplication.js.map +1 -1
  72. package/lib/functional/validateHttpLlmApplication.d.ts +5 -4
  73. package/lib/functional/validateHttpLlmApplication.js +19 -19
  74. package/lib/functional/validateHttpLlmApplication.js.map +1 -1
  75. package/lib/index.d.ts +19 -19
  76. package/lib/index.js +21 -21
  77. package/lib/index.js.map +1 -1
  78. package/lib/index.mjs +19211 -18997
  79. package/lib/index.mjs.map +1 -1
  80. package/lib/internal/AgenticaDefaultPrompt.d.ts +6 -5
  81. package/lib/internal/AgenticaDefaultPrompt.js +39 -19
  82. package/lib/internal/AgenticaDefaultPrompt.js.map +1 -1
  83. package/lib/internal/AgenticaOperationComposer.d.ts +11 -10
  84. package/lib/internal/AgenticaOperationComposer.js +60 -59
  85. package/lib/internal/AgenticaOperationComposer.js.map +1 -1
  86. package/lib/internal/AgenticaSystemPrompt.d.ts +8 -8
  87. package/lib/internal/AgenticaSystemPrompt.js +9 -9
  88. package/lib/internal/AgenticaSystemPrompt.js.map +1 -1
  89. package/lib/internal/AsyncQueue.d.ts +15 -0
  90. package/lib/internal/AsyncQueue.js +82 -0
  91. package/lib/internal/AsyncQueue.js.map +1 -0
  92. package/lib/internal/ByteArrayUtil.d.ts +1 -1
  93. package/lib/internal/ByteArrayUtil.js +3 -2
  94. package/lib/internal/ByteArrayUtil.js.map +1 -1
  95. package/lib/internal/MPSC.d.ts +10 -0
  96. package/lib/internal/MPSC.js +49 -0
  97. package/lib/internal/MPSC.js.map +1 -0
  98. package/lib/internal/Singleton.js +6 -5
  99. package/lib/internal/Singleton.js.map +1 -1
  100. package/lib/internal/StreamUtil.d.ts +16 -6
  101. package/lib/internal/StreamUtil.js +43 -29
  102. package/lib/internal/StreamUtil.js.map +1 -1
  103. package/lib/internal/__map_take.js +5 -5
  104. package/lib/internal/__map_take.js.map +1 -1
  105. package/lib/json/IAgenticaEventJson.d.ts +7 -7
  106. package/lib/json/IAgenticaOperationSelectionJson.d.ts +1 -1
  107. package/lib/json/IAgenticaPromptJson.d.ts +2 -2
  108. package/lib/prompts/AgenticaCancelPrompt.d.ts +3 -3
  109. package/lib/prompts/AgenticaCancelPrompt.js +1 -1
  110. package/lib/prompts/AgenticaCancelPrompt.js.map +1 -1
  111. package/lib/prompts/AgenticaDescribePrompt.d.ts +3 -3
  112. package/lib/prompts/AgenticaDescribePrompt.js +1 -1
  113. package/lib/prompts/AgenticaDescribePrompt.js.map +1 -1
  114. package/lib/prompts/AgenticaExecutePrompt.d.ts +5 -5
  115. package/lib/prompts/AgenticaExecutePrompt.js.map +1 -1
  116. package/lib/prompts/AgenticaPrompt.d.ts +6 -6
  117. package/lib/prompts/AgenticaSelectPrompt.d.ts +3 -3
  118. package/lib/prompts/AgenticaSelectPrompt.js +1 -1
  119. package/lib/prompts/AgenticaSelectPrompt.js.map +1 -1
  120. package/lib/prompts/AgenticaTextPrompt.d.ts +1 -1
  121. package/lib/structures/IAgenticaConfig.d.ts +5 -5
  122. package/lib/structures/IAgenticaController.d.ts +1 -1
  123. package/lib/structures/IAgenticaExecutor.d.ts +4 -4
  124. package/lib/structures/IAgenticaProps.d.ts +5 -5
  125. package/lib/structures/IAgenticaSystemPrompt.d.ts +4 -4
  126. package/lib/structures/IAgenticaVendor.d.ts +1 -1
  127. package/lib/transformers/AgenticaEventTransformer.d.ts +55 -37
  128. package/lib/transformers/AgenticaEventTransformer.js +105 -58
  129. package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
  130. package/lib/transformers/AgenticaPromptTransformer.d.ts +35 -29
  131. package/lib/transformers/AgenticaPromptTransformer.js +74 -45
  132. package/lib/transformers/AgenticaPromptTransformer.js.map +1 -1
  133. package/package.json +20 -23
  134. package/prompts/cancel.md +1 -1
  135. package/prompts/common.md +1 -1
  136. package/prompts/describe.md +1 -1
  137. package/prompts/execute.md +1 -1
  138. package/prompts/initialize.md +1 -1
  139. package/prompts/select.md +1 -1
  140. package/src/Agentica.ts +41 -31
  141. package/src/chatgpt/ChatGptAgent.ts +63 -57
  142. package/src/chatgpt/ChatGptCallFunctionAgent.ts +363 -337
  143. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +188 -164
  144. package/src/chatgpt/ChatGptCompletionMessageUtil.ts +136 -137
  145. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +105 -101
  146. package/src/chatgpt/ChatGptHistoryDecoder.ts +69 -65
  147. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +128 -123
  148. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +215 -189
  149. package/src/chatgpt/ChatGptUsageAggregator.ts +49 -54
  150. package/src/context/AgenticaCancelPrompt.ts +4 -4
  151. package/src/context/AgenticaClassOperation.ts +5 -5
  152. package/src/context/AgenticaContext.ts +15 -15
  153. package/src/context/AgenticaHttpOperation.ts +5 -5
  154. package/src/context/AgenticaOperation.ts +4 -4
  155. package/src/context/AgenticaOperationBase.ts +1 -1
  156. package/src/context/AgenticaOperationCollection.ts +2 -2
  157. package/src/context/AgenticaOperationSelection.ts +3 -3
  158. package/src/context/AgenticaTokenUsage.ts +4 -3
  159. package/src/context/internal/AgenticaTokenUsageAggregator.ts +59 -59
  160. package/src/context/internal/__IChatCancelFunctionsApplication.ts +2 -2
  161. package/src/context/internal/__IChatInitialApplication.ts +2 -2
  162. package/src/context/internal/__IChatSelectFunctionsApplication.ts +2 -2
  163. package/src/events/AgenticaCallEvent.ts +3 -3
  164. package/src/events/AgenticaCancelEvent.ts +3 -3
  165. package/src/events/AgenticaDescribeEvent.ts +5 -5
  166. package/src/events/AgenticaEvent.ts +12 -12
  167. package/src/events/AgenticaExecuteEvent.ts +7 -7
  168. package/src/events/AgenticaInitializeEvent.ts +1 -1
  169. package/src/events/AgenticaRequestEvent.ts +3 -3
  170. package/src/events/AgenticaResponseEvent.ts +2 -2
  171. package/src/events/AgenticaSelectEvent.ts +4 -4
  172. package/src/events/AgenticaTextEvent.ts +2 -2
  173. package/src/functional/assertHttpLlmApplication.ts +9 -6
  174. package/src/functional/validateHttpLlmApplication.ts +14 -8
  175. package/src/index.ts +24 -24
  176. package/src/internal/AgenticaDefaultPrompt.ts +42 -28
  177. package/src/internal/AgenticaOperationComposer.ts +63 -61
  178. package/src/internal/AgenticaSystemPrompt.ts +15 -14
  179. package/src/internal/AsyncQueue.ts +67 -0
  180. package/src/internal/ByteArrayUtil.ts +2 -2
  181. package/src/internal/MPSC.ts +40 -0
  182. package/src/internal/Singleton.ts +8 -6
  183. package/src/internal/StreamUtil.ts +62 -53
  184. package/src/internal/__map_take.ts +5 -7
  185. package/src/json/IAgenticaEventJson.ts +7 -8
  186. package/src/json/IAgenticaOperationSelectionJson.ts +1 -1
  187. package/src/json/IAgenticaPromptJson.ts +2 -2
  188. package/src/prompts/AgenticaCancelPrompt.ts +4 -4
  189. package/src/prompts/AgenticaDescribePrompt.ts +4 -4
  190. package/src/prompts/AgenticaExecutePrompt.ts +6 -5
  191. package/src/prompts/AgenticaPrompt.ts +6 -6
  192. package/src/prompts/AgenticaSelectPrompt.ts +4 -4
  193. package/src/prompts/AgenticaTextPrompt.ts +1 -1
  194. package/src/structures/IAgenticaConfig.ts +5 -5
  195. package/src/structures/IAgenticaController.ts +14 -14
  196. package/src/structures/IAgenticaExecutor.ts +4 -4
  197. package/src/structures/IAgenticaProps.ts +5 -5
  198. package/src/structures/IAgenticaSystemPrompt.ts +4 -4
  199. package/src/structures/IAgenticaVendor.ts +1 -1
  200. package/src/transformers/AgenticaEventTransformer.ts +169 -136
  201. package/src/transformers/AgenticaPromptTransformer.ts +125 -103
  202. package/lib/internal/MPSCUtil.d.ts +0 -35
  203. package/lib/internal/MPSCUtil.js +0 -105
  204. package/lib/internal/MPSCUtil.js.map +0 -1
  205. package/src/internal/MPSCUtil.ts +0 -111
@@ -1,9 +1,9 @@
1
- import OpenAI from "openai";
1
+ import type OpenAI from "openai";
2
2
 
3
- import { AgenticaEventSource } from "../events/AgenticaEventSource";
4
- import { IAgenticaOperationJson } from "./IAgenticaOperationJson";
5
- import { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
6
- import { IAgenticaPromptJson } from "./IAgenticaPromptJson";
3
+ import type { AgenticaEventSource } from "../events/AgenticaEventSource";
4
+ import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
5
+ import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
6
+ import type { IAgenticaPromptJson } from "./IAgenticaPromptJson";
7
7
 
8
8
  /**
9
9
  * Nestia A.I. chatbot event.
@@ -25,7 +25,7 @@ export type IAgenticaEventJson =
25
25
  | IAgenticaEventJson.IText;
26
26
  export namespace IAgenticaEventJson {
27
27
  export type Type = IAgenticaEventJson["type"];
28
- export type Mapper = {
28
+ export interface Mapper {
29
29
  initialize: IInitialize;
30
30
  select: ISelect;
31
31
  cancel: ICancel;
@@ -34,12 +34,11 @@ export namespace IAgenticaEventJson {
34
34
  describe: IDescribe;
35
35
  text: IText;
36
36
  request: IRequest;
37
- };
37
+ }
38
38
 
39
39
  /**
40
40
  * Event of initializing the chatbot.
41
41
  */
42
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
43
42
  export interface IInitialize extends IBase<"initialize"> {}
44
43
 
45
44
  /**
@@ -1,4 +1,4 @@
1
- import { IAgenticaOperationJson } from "./IAgenticaOperationJson";
1
+ import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
2
2
 
3
3
  /**
4
4
  * Nestia agent operation selection.
@@ -1,5 +1,5 @@
1
- import { IAgenticaOperationJson } from "./IAgenticaOperationJson";
2
- import { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
1
+ import type { IAgenticaOperationJson } from "./IAgenticaOperationJson";
2
+ import type { IAgenticaOperationSelectionJson } from "./IAgenticaOperationSelectionJson";
3
3
 
4
4
  /**
5
5
  * Nestia A.I. chatbot prompt.
@@ -1,7 +1,7 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
4
- import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
3
+ import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
4
+ import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
5
5
  import { AgenticaPromptBase } from "./AgenticaPromptBase";
6
6
 
7
7
  export class AgenticaCancelPrompt<
@@ -20,7 +20,7 @@ export class AgenticaCancelPrompt<
20
20
  return {
21
21
  type: this.type,
22
22
  id: this.id,
23
- selections: this.selections.map((s) => s.toJSON()),
23
+ selections: this.selections.map(s => s.toJSON()),
24
24
  };
25
25
  }
26
26
  }
@@ -1,7 +1,7 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
4
- import { AgenticaExecutePrompt } from "./AgenticaExecutePrompt";
3
+ import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
4
+ import type { AgenticaExecutePrompt } from "./AgenticaExecutePrompt";
5
5
  import { AgenticaPromptBase } from "./AgenticaPromptBase";
6
6
 
7
7
  export class AgenticaDescribePrompt<
@@ -28,7 +28,7 @@ export class AgenticaDescribePrompt<
28
28
  public toJSON(): IAgenticaPromptJson.IDescribe {
29
29
  return {
30
30
  type: this.type,
31
- executes: this.executes.map((e) => e.toJSON()),
31
+ executes: this.executes.map(e => e.toJSON()),
32
32
  text: this.text,
33
33
  };
34
34
  }
@@ -1,7 +1,7 @@
1
- import { IHttpResponse, ILlmSchema } from "@samchon/openapi";
1
+ import type { IHttpResponse, ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaOperation } from "../context/AgenticaOperation";
4
- import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
3
+ import type { AgenticaOperation } from "../context/AgenticaOperation";
4
+ import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
5
5
  import { AgenticaPromptBase } from "./AgenticaPromptBase";
6
6
 
7
7
  export class AgenticaExecutePrompt<
@@ -14,8 +14,9 @@ export class AgenticaExecutePrompt<
14
14
  : Protocol extends "class"
15
15
  ? AgenticaOperation.Class<Model>
16
16
  : AgenticaOperation<Model>;
17
- public readonly arguments: Record<string, any>;
18
- public readonly value: Protocol extends "http" ? IHttpResponse : any;
17
+
18
+ public readonly arguments: Record<string, unknown>;
19
+ public readonly value: Protocol extends "http" ? IHttpResponse : unknown;
19
20
 
20
21
  public constructor(props: AgenticaExecutePrompt.IProps<Model, Protocol>) {
21
22
  super("execute");
@@ -1,10 +1,10 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaCancelPrompt } from "../context/AgenticaCancelPrompt";
4
- import { AgenticaDescribePrompt } from "./AgenticaDescribePrompt";
5
- import { AgenticaExecutePrompt } from "./AgenticaExecutePrompt";
6
- import { AgenticaSelectPrompt } from "./AgenticaSelectPrompt";
7
- import { AgenticaTextPrompt } from "./AgenticaTextPrompt";
3
+ import type { AgenticaCancelPrompt } from "../context/AgenticaCancelPrompt";
4
+ import type { AgenticaDescribePrompt } from "./AgenticaDescribePrompt";
5
+ import type { AgenticaExecutePrompt } from "./AgenticaExecutePrompt";
6
+ import type { AgenticaSelectPrompt } from "./AgenticaSelectPrompt";
7
+ import type { AgenticaTextPrompt } from "./AgenticaTextPrompt";
8
8
 
9
9
  export type AgenticaPrompt<Model extends ILlmSchema.Model> =
10
10
  | AgenticaCancelPrompt<Model>
@@ -1,7 +1,7 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
4
- import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
3
+ import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
4
+ import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
5
5
  import { AgenticaPromptBase } from "./AgenticaPromptBase";
6
6
 
7
7
  export class AgenticaSelectPrompt<
@@ -20,7 +20,7 @@ export class AgenticaSelectPrompt<
20
20
  return {
21
21
  type: this.type,
22
22
  id: this.id,
23
- selections: this.selections.map((s) => s.toJSON()),
23
+ selections: this.selections.map(s => s.toJSON()),
24
24
  };
25
25
  }
26
26
  }
@@ -1,4 +1,4 @@
1
- import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
1
+ import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
2
2
  import { AgenticaPromptBase } from "./AgenticaPromptBase";
3
3
 
4
4
  export class AgenticaTextPrompt<
@@ -1,9 +1,9 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaContext } from "../context/AgenticaContext";
4
- import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
5
- import { IAgenticaExecutor } from "./IAgenticaExecutor";
6
- import { IAgenticaSystemPrompt } from "./IAgenticaSystemPrompt";
3
+ import type { AgenticaContext } from "../context/AgenticaContext";
4
+ import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
5
+ import type { IAgenticaExecutor } from "./IAgenticaExecutor";
6
+ import type { IAgenticaSystemPrompt } from "./IAgenticaSystemPrompt";
7
7
 
8
8
  /**
9
9
  * Configuration for Nestia Agent.
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  IHttpConnection,
3
3
  IHttpLlmApplication,
4
4
  IHttpLlmFunction,
@@ -97,21 +97,21 @@ export namespace IAgenticaController {
97
97
  execute:
98
98
  | object
99
99
  | ((props: {
100
- /**
101
- * Target application schema.
102
- */
103
- application: ILlmApplication<Model>;
100
+ /**
101
+ * Target application schema.
102
+ */
103
+ application: ILlmApplication<Model>;
104
104
 
105
- /**
106
- * Target function schema.
107
- */
108
- function: ILlmFunction<Model>;
105
+ /**
106
+ * Target function schema.
107
+ */
108
+ function: ILlmFunction<Model>;
109
109
 
110
- /**
111
- * Arguments of the function calling.
112
- */
113
- arguments: object;
114
- }) => Promise<unknown>);
110
+ /**
111
+ * Arguments of the function calling.
112
+ */
113
+ arguments: object;
114
+ }) => Promise<unknown>);
115
115
  }
116
116
 
117
117
  interface IBase<Protocol, Application> {
@@ -1,8 +1,8 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaContext } from "../context/AgenticaContext";
4
- import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
5
- import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
3
+ import type { AgenticaContext } from "../context/AgenticaContext";
4
+ import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
5
+ import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
6
6
 
7
7
  /**
8
8
  * Executor of the Agentic AI.
@@ -1,9 +1,9 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
4
- import { IAgenticaConfig } from "./IAgenticaConfig";
5
- import { IAgenticaController } from "./IAgenticaController";
6
- import { IAgenticaVendor } from "./IAgenticaVendor";
3
+ import type { IAgenticaPromptJson } from "../json/IAgenticaPromptJson";
4
+ import type { IAgenticaConfig } from "./IAgenticaConfig";
5
+ import type { IAgenticaController } from "./IAgenticaController";
6
+ import type { IAgenticaVendor } from "./IAgenticaVendor";
7
7
 
8
8
  /**
9
9
  * Properties of the Nestia Agent.
@@ -1,8 +1,8 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
4
- import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
5
- import { IAgenticaConfig } from "./IAgenticaConfig";
3
+ import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
4
+ import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
5
+ import type { IAgenticaConfig } from "./IAgenticaConfig";
6
6
 
7
7
  /**
8
8
  * System prompt collection of the A.I. chatbot.
@@ -1,4 +1,4 @@
1
- import OpenAI from "openai";
1
+ import type OpenAI from "openai";
2
2
 
3
3
  /**
4
4
  * LLM service vendor for Nestia Chat.
@@ -1,165 +1,198 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaOperation } from "../context/AgenticaOperation";
3
+ import type { AgenticaOperation } from "../context/AgenticaOperation";
4
+ import type { AgenticaEvent } from "../events/AgenticaEvent";
5
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
4
6
  import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
5
7
  import { AgenticaCallEvent } from "../events/AgenticaCallEvent";
6
8
  import { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
7
9
  import { AgenticaDescribeEvent } from "../events/AgenticaDescribeEvent";
8
- import { AgenticaEvent } from "../events/AgenticaEvent";
9
10
  import { AgenticaExecuteEvent } from "../events/AgenticaExecuteEvent";
10
11
  import { AgenticaInitializeEvent } from "../events/AgenticaInitializeEvent";
11
12
  import { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
12
13
  import { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
13
14
  import { AgenticaTextEvent } from "../events/AgenticaTextEvent";
14
15
  import { StreamUtil } from "../internal/StreamUtil";
15
- import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
16
16
 
17
- export namespace AgenticaEventTransformer {
18
- export const transform = <Model extends ILlmSchema.Model>(props: {
19
- operations: Map<string, Map<string, AgenticaOperation<Model>>>;
20
- event: IAgenticaEventJson;
21
- }): AgenticaEvent<Model> => {
22
- if (props.event.type === "call")
23
- return transformCall({
24
- operations: props.operations,
25
- event: props.event,
26
- });
27
- else if (props.event.type === "cancel")
28
- return transformCancel({
29
- operations: props.operations,
30
- event: props.event,
31
- });
32
- else if (props.event.type === "describe")
33
- return transformDescribe({
34
- operations: props.operations,
35
- event: props.event,
36
- });
37
- else if (props.event.type === "execute")
38
- return transformExecute({
39
- operations: props.operations,
40
- event: props.event,
41
- });
42
- else if (props.event.type === "initialize") return transformInitialize();
43
- else if (props.event.type === "request")
44
- return transformRequest({
45
- event: props.event,
46
- });
47
- else if (props.event.type === "select")
48
- return transformSelect({
49
- operations: props.operations,
50
- event: props.event,
51
- });
52
- else if (props.event.type === "text")
53
- return transformText({
54
- event: props.event,
55
- });
56
- else throw new Error("Unknown event type");
17
+ function findOperation<Model extends ILlmSchema.Model>(props: {
18
+ operations: Map<string, Map<string, AgenticaOperation<Model>>>;
19
+ input: {
20
+ controller: string;
21
+ function: string;
57
22
  };
23
+ }): AgenticaOperation<Model> {
24
+ const found: AgenticaOperation<Model> | undefined = props.operations
25
+ .get(props.input.controller)
26
+ ?.get(props.input.function);
27
+ if (found === undefined) {
28
+ throw new Error(
29
+ `No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
30
+ );
31
+ }
32
+ return found;
33
+ }
58
34
 
59
- export const transformCall = <Model extends ILlmSchema.Model>(props: {
60
- operations: Map<string, Map<string, AgenticaOperation<Model>>>;
61
- event: IAgenticaEventJson.ICall;
62
- }): AgenticaCallEvent<Model> =>
63
- new AgenticaCallEvent({
64
- id: props.event.id,
65
- operation: findOperation({
66
- operations: props.operations,
67
- input: props.event.operation,
68
- }),
69
- arguments: props.event.arguments,
35
+ export function transform<Model extends ILlmSchema.Model>(props: {
36
+ operations: Map<string, Map<string, AgenticaOperation<Model>>>;
37
+ event: IAgenticaEventJson;
38
+ }): AgenticaEvent<Model> {
39
+ if (props.event.type === "call") {
40
+ return transformCall({
41
+ operations: props.operations,
42
+ event: props.event,
70
43
  });
71
-
72
- export const transformCancel = <Model extends ILlmSchema.Model>(props: {
73
- operations: Map<string, Map<string, AgenticaOperation<Model>>>;
74
- event: IAgenticaEventJson.ICancel;
75
- }): AgenticaCancelEvent<Model> =>
76
- new AgenticaCancelEvent({
77
- selection: new AgenticaOperationSelection({
78
- operation: findOperation({
79
- operations: props.operations,
80
- input: props.event.selection.operation,
81
- }),
82
- reason: props.event.selection.reason,
83
- }),
44
+ }
45
+ else if (props.event.type === "cancel") {
46
+ return transformCancel({
47
+ operations: props.operations,
48
+ event: props.event,
84
49
  });
85
-
86
- export const transformDescribe = <Model extends ILlmSchema.Model>(props: {
87
- operations: Map<string, Map<string, AgenticaOperation<Model>>>;
88
- event: IAgenticaEventJson.IDescribe;
89
- }): AgenticaDescribeEvent<Model> =>
90
- new AgenticaDescribeEvent({
91
- executes: props.event.executes.map((next) =>
92
- transformExecute({
93
- operations: props.operations,
94
- event: next,
95
- }),
96
- ),
97
- stream: StreamUtil.to(props.event.text),
98
- done: () => true,
99
- get: () => props.event.text,
100
- join: async () => props.event.text,
50
+ }
51
+ else if (props.event.type === "describe") {
52
+ return transformDescribe({
53
+ operations: props.operations,
54
+ event: props.event,
101
55
  });
56
+ }
57
+ else if (props.event.type === "execute") {
58
+ return transformExecute({
59
+ operations: props.operations,
60
+ event: props.event,
61
+ });
62
+ }
63
+ else if (props.event.type === "initialize") {
64
+ return transformInitialize();
65
+ }
66
+ else if (props.event.type === "request") {
67
+ return transformRequest({
68
+ event: props.event,
69
+ });
70
+ }
71
+ else if (props.event.type === "select") {
72
+ return transformSelect({
73
+ operations: props.operations,
74
+ event: props.event,
75
+ });
76
+ }
77
+ else if (props.event.type === "text") {
78
+ return transformText({
79
+ event: props.event,
80
+ });
81
+ }
82
+ else { throw new Error("Unknown event type"); }
83
+ }
84
+
85
+ export function transformCall<Model extends ILlmSchema.Model>(props: {
86
+ operations: Map<string, Map<string, AgenticaOperation<Model>>>;
87
+ event: IAgenticaEventJson.ICall;
88
+ }): AgenticaCallEvent<Model> {
89
+ return new AgenticaCallEvent({
90
+ id: props.event.id,
91
+ operation: findOperation({
92
+ operations: props.operations,
93
+ input: props.event.operation,
94
+ }),
95
+ arguments: props.event.arguments,
96
+ });
97
+ }
102
98
 
103
- export const transformExecute = <Model extends ILlmSchema.Model>(props: {
104
- operations: Map<string, Map<string, AgenticaOperation<Model>>>;
105
- event: IAgenticaEventJson.IExecute;
106
- }): AgenticaExecuteEvent<Model> =>
107
- new AgenticaExecuteEvent({
108
- id: props.event.id,
99
+ export function transformCancel<Model extends ILlmSchema.Model>(props: {
100
+ operations: Map<string, Map<string, AgenticaOperation<Model>>>;
101
+ event: IAgenticaEventJson.ICancel;
102
+ }): AgenticaCancelEvent<Model> {
103
+ return new AgenticaCancelEvent({
104
+ selection: new AgenticaOperationSelection({
109
105
  operation: findOperation({
110
106
  operations: props.operations,
111
- input: props.event.operation,
107
+ input: props.event.selection.operation,
112
108
  }),
113
- arguments: props.event.arguments,
114
- value: props.event.value,
115
- });
109
+ reason: props.event.selection.reason,
110
+ }),
111
+ });
112
+ }
116
113
 
117
- export const transformInitialize = (): AgenticaInitializeEvent =>
118
- new AgenticaInitializeEvent();
114
+ export function transformDescribe<Model extends ILlmSchema.Model>(props: {
115
+ operations: Map<string, Map<string, AgenticaOperation<Model>>>;
116
+ event: IAgenticaEventJson.IDescribe;
117
+ }): AgenticaDescribeEvent<Model> {
118
+ return new AgenticaDescribeEvent({
119
+ executes: props.event.executes.map(next =>
120
+ transformExecute({
121
+ operations: props.operations,
122
+ event: next,
123
+ }),
124
+ ),
125
+ stream: StreamUtil.to(props.event.text),
126
+ done: () => true,
127
+ get: () => props.event.text,
128
+ join: async () => props.event.text,
129
+ });
130
+ }
119
131
 
120
- export const transformRequest = (props: {
121
- event: IAgenticaEventJson.IRequest;
122
- }): AgenticaRequestEvent => new AgenticaRequestEvent(props.event);
132
+ export function transformExecute<Model extends ILlmSchema.Model>(props: {
133
+ operations: Map<string, Map<string, AgenticaOperation<Model>>>;
134
+ event: IAgenticaEventJson.IExecute;
135
+ }): AgenticaExecuteEvent<Model> {
136
+ return new AgenticaExecuteEvent({
137
+ id: props.event.id,
138
+ operation: findOperation({
139
+ operations: props.operations,
140
+ input: props.event.operation,
141
+ }),
142
+ /**
143
+ * @TODO remove `as`
144
+ */
145
+ arguments: props.event.arguments as Record<string, any>,
146
+ value: props.event.value,
147
+ });
148
+ }
123
149
 
124
- export const transformSelect = <Model extends ILlmSchema.Model>(props: {
125
- operations: Map<string, Map<string, AgenticaOperation<Model>>>;
126
- event: IAgenticaEventJson.ISelect;
127
- }): AgenticaSelectEvent<Model> =>
128
- new AgenticaSelectEvent({
129
- selection: new AgenticaOperationSelection({
130
- operation: findOperation({
131
- operations: props.operations,
132
- input: props.event.selection.operation,
133
- }),
134
- reason: props.event.selection.reason,
135
- }),
136
- });
150
+ export function transformInitialize(): AgenticaInitializeEvent {
151
+ return new AgenticaInitializeEvent();
152
+ }
137
153
 
138
- export const transformText = (props: {
139
- event: IAgenticaEventJson.IText;
140
- }): AgenticaTextEvent =>
141
- new AgenticaTextEvent({
142
- role: props.event.role,
143
- stream: StreamUtil.to(props.event.text),
144
- done: () => true,
145
- get: () => props.event.text,
146
- join: async () => props.event.text,
147
- });
154
+ export function transformRequest(props: {
155
+ event: IAgenticaEventJson.IRequest;
156
+ }): AgenticaRequestEvent {
157
+ return new AgenticaRequestEvent(props.event);
148
158
  }
149
159
 
150
- const findOperation = <Model extends ILlmSchema.Model>(props: {
160
+ export function transformSelect<Model extends ILlmSchema.Model>(props: {
151
161
  operations: Map<string, Map<string, AgenticaOperation<Model>>>;
152
- input: {
153
- controller: string;
154
- function: string;
155
- };
156
- }): AgenticaOperation<Model> => {
157
- const found: AgenticaOperation<Model> | undefined = props.operations
158
- .get(props.input.controller)
159
- ?.get(props.input.function);
160
- if (found === undefined)
161
- throw new Error(
162
- `No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
163
- );
164
- return found;
162
+ event: IAgenticaEventJson.ISelect;
163
+ }): AgenticaSelectEvent<Model> {
164
+ return new AgenticaSelectEvent({
165
+ selection: new AgenticaOperationSelection({
166
+ operation: findOperation({
167
+ operations: props.operations,
168
+ input: props.event.selection.operation,
169
+ }),
170
+ reason: props.event.selection.reason,
171
+ }),
172
+ });
173
+ }
174
+
175
+ export function transformText(props: {
176
+ event: IAgenticaEventJson.IText;
177
+ }): AgenticaTextEvent {
178
+ return new AgenticaTextEvent({
179
+ role: props.event.role,
180
+ stream: StreamUtil.to(props.event.text),
181
+ done: () => true,
182
+ get: () => props.event.text,
183
+ join: async () => props.event.text,
184
+ });
185
+ }
186
+
187
+ export const AgenticaEventTransformer = {
188
+ transform,
189
+ transformCall,
190
+ transformCancel,
191
+ transformDescribe,
192
+ transformExecute,
193
+ transformInitialize,
194
+ transformRequest,
195
+ transformSelect,
196
+ transformText,
197
+ findOperation,
165
198
  };