@agentica/core 0.10.4 → 0.11.1

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 (263) hide show
  1. package/lib/Agentica.d.ts +14 -14
  2. package/lib/Agentica.js +54 -31
  3. package/lib/Agentica.js.map +1 -1
  4. package/lib/chatgpt/ChatGptAgent.d.ts +3 -3
  5. package/lib/chatgpt/ChatGptAgent.js +1 -1
  6. package/lib/chatgpt/ChatGptAgent.js.map +1 -1
  7. package/lib/chatgpt/ChatGptCallFunctionAgent.d.ts +3 -3
  8. package/lib/chatgpt/ChatGptCallFunctionAgent.js +61 -63
  9. package/lib/chatgpt/ChatGptCallFunctionAgent.js.map +1 -1
  10. package/lib/chatgpt/ChatGptCancelFunctionAgent.d.ts +6 -6
  11. package/lib/chatgpt/ChatGptCancelFunctionAgent.js +28 -30
  12. package/lib/chatgpt/ChatGptCancelFunctionAgent.js.map +1 -1
  13. package/lib/chatgpt/ChatGptCompletionMessageUtil.d.ts +8 -0
  14. package/lib/chatgpt/ChatGptCompletionMessageUtil.js +536 -0
  15. package/lib/chatgpt/ChatGptCompletionMessageUtil.js.map +1 -0
  16. package/lib/chatgpt/ChatGptDescribeFunctionAgent.d.ts +4 -3
  17. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js +56 -6
  18. package/lib/chatgpt/ChatGptDescribeFunctionAgent.js.map +1 -1
  19. package/lib/chatgpt/ChatGptHistoryDecoder.d.ts +2 -2
  20. package/lib/chatgpt/ChatGptHistoryDecoder.js +8 -8
  21. package/lib/chatgpt/ChatGptHistoryDecoder.js.map +1 -1
  22. package/lib/chatgpt/ChatGptInitializeFunctionAgent.d.ts +3 -3
  23. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js +11 -5
  24. package/lib/chatgpt/ChatGptInitializeFunctionAgent.js.map +1 -1
  25. package/lib/chatgpt/ChatGptSelectFunctionAgent.d.ts +3 -3
  26. package/lib/chatgpt/ChatGptSelectFunctionAgent.js +39 -42
  27. package/lib/chatgpt/ChatGptSelectFunctionAgent.js.map +1 -1
  28. package/lib/chatgpt/ChatGptUsageAggregator.d.ts +6 -0
  29. package/lib/chatgpt/ChatGptUsageAggregator.js +48 -0
  30. package/lib/chatgpt/ChatGptUsageAggregator.js.map +1 -0
  31. package/lib/context/AgenticaCancelPrompt.d.ts +16 -0
  32. package/lib/context/AgenticaCancelPrompt.js +20 -0
  33. package/lib/context/AgenticaCancelPrompt.js.map +1 -0
  34. package/lib/context/AgenticaClassOperation.d.ts +8 -0
  35. package/lib/context/AgenticaClassOperation.js +11 -0
  36. package/lib/context/AgenticaClassOperation.js.map +1 -0
  37. package/lib/{structures/IAgenticaContext.d.ts → context/AgenticaContext.d.ts} +15 -14
  38. package/lib/{structures/IAgenticaPrompt.js → context/AgenticaContext.js} +1 -1
  39. package/lib/context/AgenticaContext.js.map +1 -0
  40. package/lib/context/AgenticaHttpOperation.d.ts +8 -0
  41. package/lib/context/AgenticaHttpOperation.js +11 -0
  42. package/lib/context/AgenticaHttpOperation.js.map +1 -0
  43. package/lib/context/AgenticaOperation.d.ts +46 -0
  44. package/lib/{structures/IAgenticaContext.js → context/AgenticaOperation.js} +1 -1
  45. package/lib/context/AgenticaOperation.js.map +1 -0
  46. package/lib/context/AgenticaOperationBase.d.ts +29 -0
  47. package/lib/context/AgenticaOperationBase.js +21 -0
  48. package/lib/context/AgenticaOperationBase.js.map +1 -0
  49. package/lib/{structures/IAgenticaOperationCollection.d.ts → context/AgenticaOperationCollection.d.ts} +6 -6
  50. package/lib/{structures/IAgenticaOperationSelection.js → context/AgenticaOperationCollection.js} +1 -1
  51. package/lib/context/AgenticaOperationCollection.js.map +1 -0
  52. package/lib/context/AgenticaOperationSelection.d.ts +15 -0
  53. package/lib/context/AgenticaOperationSelection.js +17 -0
  54. package/lib/context/AgenticaOperationSelection.js.map +1 -0
  55. package/lib/context/AgenticaTokenUsage.d.ts +82 -0
  56. package/lib/context/AgenticaTokenUsage.js +97 -0
  57. package/lib/context/AgenticaTokenUsage.js.map +1 -0
  58. package/lib/context/internal/AgenticaTokenUsageAggregator.d.ts +10 -0
  59. package/lib/{internal → context/internal}/AgenticaTokenUsageAggregator.js +0 -46
  60. package/lib/context/internal/AgenticaTokenUsageAggregator.js.map +1 -0
  61. package/lib/context/internal/__IChatCancelFunctionsApplication.js.map +1 -0
  62. package/lib/context/internal/__IChatFunctionReference.js.map +1 -0
  63. package/lib/context/internal/__IChatInitialApplication.js.map +1 -0
  64. package/lib/context/internal/__IChatSelectFunctionsApplication.js.map +1 -0
  65. package/lib/events/AgenticaCallEvent.d.ts +18 -0
  66. package/lib/events/AgenticaCallEvent.js +22 -0
  67. package/lib/events/AgenticaCallEvent.js.map +1 -0
  68. package/lib/events/AgenticaCancelEvent.d.ts +14 -0
  69. package/lib/events/AgenticaCancelEvent.js +18 -0
  70. package/lib/events/AgenticaCancelEvent.js.map +1 -0
  71. package/lib/events/AgenticaDescribeEvent.d.ts +27 -0
  72. package/lib/events/AgenticaDescribeEvent.js +40 -0
  73. package/lib/events/AgenticaDescribeEvent.js.map +1 -0
  74. package/lib/events/AgenticaEvent.d.ts +25 -0
  75. package/lib/{structures/IAgenticaEvent.js → events/AgenticaEvent.js} +1 -1
  76. package/lib/events/AgenticaEvent.js.map +1 -0
  77. package/lib/events/AgenticaEventBase.d.ts +4 -0
  78. package/lib/events/AgenticaEventBase.js +10 -0
  79. package/lib/events/AgenticaEventBase.js.map +1 -0
  80. package/lib/events/AgenticaEventSource.d.ts +1 -0
  81. package/lib/events/AgenticaEventSource.js +3 -0
  82. package/lib/events/AgenticaEventSource.js.map +1 -0
  83. package/lib/events/AgenticaExecuteEvent.d.ts +22 -0
  84. package/lib/events/AgenticaExecuteEvent.js +33 -0
  85. package/lib/events/AgenticaExecuteEvent.js.map +1 -0
  86. package/lib/events/AgenticaInitializeEvent.d.ts +6 -0
  87. package/lib/events/AgenticaInitializeEvent.js +16 -0
  88. package/lib/events/AgenticaInitializeEvent.js.map +1 -0
  89. package/lib/events/AgenticaRequestEvent.d.ts +27 -0
  90. package/lib/events/AgenticaRequestEvent.js +22 -0
  91. package/lib/events/AgenticaRequestEvent.js.map +1 -0
  92. package/lib/events/AgenticaResponseEvent.d.ts +35 -0
  93. package/lib/events/AgenticaResponseEvent.js +16 -0
  94. package/lib/events/AgenticaResponseEvent.js.map +1 -0
  95. package/lib/events/AgenticaSelectEvent.d.ts +16 -0
  96. package/lib/events/AgenticaSelectEvent.js +26 -0
  97. package/lib/events/AgenticaSelectEvent.js.map +1 -0
  98. package/lib/events/AgenticaTextEvent.d.ts +25 -0
  99. package/lib/events/AgenticaTextEvent.js +40 -0
  100. package/lib/events/AgenticaTextEvent.js.map +1 -0
  101. package/lib/index.d.ts +26 -8
  102. package/lib/index.js +29 -9
  103. package/lib/index.js.map +1 -1
  104. package/lib/index.mjs +1391 -306
  105. package/lib/index.mjs.map +1 -1
  106. package/lib/internal/AgenticaOperationComposer.d.ts +2 -2
  107. package/lib/internal/AgenticaOperationComposer.js +12 -0
  108. package/lib/internal/AgenticaOperationComposer.js.map +1 -1
  109. package/lib/internal/ByteArrayUtil.d.ts +3 -0
  110. package/lib/internal/ByteArrayUtil.js +10 -0
  111. package/lib/internal/ByteArrayUtil.js.map +1 -0
  112. package/lib/internal/MPSCUtil.d.ts +21 -0
  113. package/lib/internal/MPSCUtil.js +84 -0
  114. package/lib/internal/MPSCUtil.js.map +1 -0
  115. package/lib/internal/StreamUtil.d.ts +6 -0
  116. package/lib/internal/StreamUtil.js +65 -0
  117. package/lib/internal/StreamUtil.js.map +1 -0
  118. package/lib/json/IAgenticaEventJson.d.ts +149 -0
  119. package/lib/{structures/IAgenticaOperation.js → json/IAgenticaEventJson.js} +1 -1
  120. package/lib/json/IAgenticaEventJson.js.map +1 -0
  121. package/lib/json/IAgenticaOperationJson.d.ts +33 -0
  122. package/lib/json/IAgenticaOperationJson.js +3 -0
  123. package/lib/json/IAgenticaOperationJson.js.map +1 -0
  124. package/lib/json/IAgenticaOperationSelectionJson.d.ts +18 -0
  125. package/lib/{structures/IAgenticaOperationCollection.js → json/IAgenticaOperationSelectionJson.js} +1 -1
  126. package/lib/json/IAgenticaOperationSelectionJson.js.map +1 -0
  127. package/lib/json/IAgenticaPromptJson.d.ts +111 -0
  128. package/lib/json/IAgenticaPromptJson.js +3 -0
  129. package/lib/json/IAgenticaPromptJson.js.map +1 -0
  130. package/lib/{structures/IAgenticaTokenUsage.d.ts → json/IAgenticaTokenUsageJson.d.ts} +10 -10
  131. package/lib/json/IAgenticaTokenUsageJson.js +3 -0
  132. package/lib/json/IAgenticaTokenUsageJson.js.map +1 -0
  133. package/lib/prompts/AgenticaCancelPrompt.d.ts +16 -0
  134. package/lib/prompts/AgenticaCancelPrompt.js +20 -0
  135. package/lib/prompts/AgenticaCancelPrompt.js.map +1 -0
  136. package/lib/prompts/AgenticaDescribePrompt.d.ts +24 -0
  137. package/lib/prompts/AgenticaDescribePrompt.js +20 -0
  138. package/lib/prompts/AgenticaDescribePrompt.js.map +1 -0
  139. package/lib/prompts/AgenticaExecutePrompt.d.ts +20 -0
  140. package/lib/prompts/AgenticaExecutePrompt.js +24 -0
  141. package/lib/prompts/AgenticaExecutePrompt.js.map +1 -0
  142. package/lib/prompts/AgenticaPrompt.d.ts +7 -0
  143. package/lib/{typings/AgenticaSource.js → prompts/AgenticaPrompt.js} +1 -1
  144. package/lib/prompts/AgenticaPrompt.js.map +1 -0
  145. package/lib/prompts/AgenticaPromptBase.d.ts +22 -0
  146. package/lib/prompts/AgenticaPromptBase.js +22 -0
  147. package/lib/prompts/AgenticaPromptBase.js.map +1 -0
  148. package/lib/prompts/AgenticaSelectPrompt.d.ts +16 -0
  149. package/lib/prompts/AgenticaSelectPrompt.js +20 -0
  150. package/lib/prompts/AgenticaSelectPrompt.js.map +1 -0
  151. package/lib/prompts/AgenticaTextPrompt.d.ts +14 -0
  152. package/lib/prompts/AgenticaTextPrompt.js +20 -0
  153. package/lib/prompts/AgenticaTextPrompt.js.map +1 -0
  154. package/lib/structures/IAgenticaConfig.d.ts +3 -3
  155. package/lib/structures/IAgenticaExecutor.d.ts +12 -11
  156. package/lib/structures/IAgenticaProps.d.ts +2 -3
  157. package/lib/structures/IAgenticaSystemPrompt.d.ts +12 -11
  158. package/lib/transformers/AgenticaEventTransformer.d.ts +45 -0
  159. package/lib/transformers/AgenticaEventTransformer.js +127 -0
  160. package/lib/transformers/AgenticaEventTransformer.js.map +1 -0
  161. package/lib/transformers/AgenticaPromptTransformer.d.ts +34 -0
  162. package/lib/transformers/AgenticaPromptTransformer.js +90 -0
  163. package/lib/transformers/AgenticaPromptTransformer.js.map +1 -0
  164. package/package.json +1 -1
  165. package/src/Agentica.ts +93 -63
  166. package/src/chatgpt/ChatGptAgent.ts +8 -7
  167. package/src/chatgpt/ChatGptCallFunctionAgent.ts +90 -88
  168. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +51 -58
  169. package/src/chatgpt/ChatGptCompletionMessageUtil.ts +166 -0
  170. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +81 -12
  171. package/src/chatgpt/ChatGptHistoryDecoder.ts +14 -14
  172. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +21 -13
  173. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +66 -74
  174. package/src/chatgpt/ChatGptUsageAggregator.ts +62 -0
  175. package/src/context/AgenticaCancelPrompt.ts +32 -0
  176. package/src/context/AgenticaClassOperation.ts +23 -0
  177. package/src/{structures/IAgenticaContext.ts → context/AgenticaContext.ts} +17 -16
  178. package/src/context/AgenticaHttpOperation.ts +27 -0
  179. package/src/{structures/IAgenticaOperation.ts → context/AgenticaOperation.ts} +25 -22
  180. package/src/context/AgenticaOperationBase.ts +57 -0
  181. package/src/{structures/IAgenticaOperationCollection.ts → context/AgenticaOperationCollection.ts} +6 -6
  182. package/src/context/AgenticaOperationSelection.ts +27 -0
  183. package/src/context/AgenticaTokenUsage.ts +170 -0
  184. package/src/context/internal/AgenticaTokenUsageAggregator.ts +66 -0
  185. package/src/events/AgenticaCallEvent.ts +36 -0
  186. package/src/events/AgenticaCancelEvent.ts +28 -0
  187. package/src/events/AgenticaDescribeEvent.ts +61 -0
  188. package/src/events/AgenticaEvent.ts +36 -0
  189. package/src/events/AgenticaEventBase.ts +7 -0
  190. package/src/{typings/AgenticaSource.ts → events/AgenticaEventSource.ts} +1 -1
  191. package/src/events/AgenticaExecuteEvent.ts +50 -0
  192. package/src/events/AgenticaInitializeEvent.ts +14 -0
  193. package/src/events/AgenticaRequestEvent.ts +45 -0
  194. package/src/events/AgenticaResponseEvent.ts +48 -0
  195. package/src/events/AgenticaSelectEvent.ts +37 -0
  196. package/src/events/AgenticaTextEvent.ts +57 -0
  197. package/src/index.ts +33 -9
  198. package/src/internal/AgenticaOperationComposer.ts +24 -15
  199. package/src/internal/ByteArrayUtil.ts +5 -0
  200. package/src/internal/MPSCUtil.ts +75 -0
  201. package/src/internal/StreamUtil.ts +64 -0
  202. package/src/json/IAgenticaEventJson.ts +178 -0
  203. package/src/json/IAgenticaOperationJson.ts +36 -0
  204. package/src/json/IAgenticaOperationSelectionJson.ts +19 -0
  205. package/src/json/IAgenticaPromptJson.ts +130 -0
  206. package/src/{structures/IAgenticaTokenUsage.ts → json/IAgenticaTokenUsageJson.ts} +10 -10
  207. package/src/prompts/AgenticaCancelPrompt.ts +32 -0
  208. package/src/prompts/AgenticaDescribePrompt.ts +41 -0
  209. package/src/prompts/AgenticaExecutePrompt.ts +52 -0
  210. package/src/prompts/AgenticaPrompt.ts +14 -0
  211. package/src/prompts/AgenticaPromptBase.ts +27 -0
  212. package/src/prompts/AgenticaSelectPrompt.ts +32 -0
  213. package/src/prompts/AgenticaTextPrompt.ts +31 -0
  214. package/src/structures/IAgenticaConfig.ts +3 -3
  215. package/src/structures/IAgenticaExecutor.ts +14 -13
  216. package/src/structures/IAgenticaProps.ts +2 -3
  217. package/src/structures/IAgenticaSystemPrompt.ts +12 -11
  218. package/src/transformers/AgenticaEventTransformer.ts +165 -0
  219. package/src/transformers/AgenticaPromptTransformer.ts +134 -0
  220. package/lib/internal/AgenticaPromptFactory.d.ts +0 -7
  221. package/lib/internal/AgenticaPromptFactory.js +0 -9
  222. package/lib/internal/AgenticaPromptFactory.js.map +0 -1
  223. package/lib/internal/AgenticaPromptTransformer.d.ts +0 -10
  224. package/lib/internal/AgenticaPromptTransformer.js +0 -58
  225. package/lib/internal/AgenticaPromptTransformer.js.map +0 -1
  226. package/lib/internal/AgenticaTokenUsageAggregator.d.ts +0 -11
  227. package/lib/internal/AgenticaTokenUsageAggregator.js.map +0 -1
  228. package/lib/structures/IAgenticaContext.js.map +0 -1
  229. package/lib/structures/IAgenticaEvent.d.ts +0 -192
  230. package/lib/structures/IAgenticaEvent.js.map +0 -1
  231. package/lib/structures/IAgenticaOperation.d.ts +0 -47
  232. package/lib/structures/IAgenticaOperation.js.map +0 -1
  233. package/lib/structures/IAgenticaOperationCollection.js.map +0 -1
  234. package/lib/structures/IAgenticaOperationSelection.d.ts +0 -50
  235. package/lib/structures/IAgenticaOperationSelection.js.map +0 -1
  236. package/lib/structures/IAgenticaPrompt.d.ts +0 -138
  237. package/lib/structures/IAgenticaPrompt.js.map +0 -1
  238. package/lib/structures/IAgenticaTokenUsage.js +0 -3
  239. package/lib/structures/IAgenticaTokenUsage.js.map +0 -1
  240. package/lib/structures/internal/__IChatCancelFunctionsApplication.js.map +0 -1
  241. package/lib/structures/internal/__IChatFunctionReference.js.map +0 -1
  242. package/lib/structures/internal/__IChatInitialApplication.js.map +0 -1
  243. package/lib/structures/internal/__IChatSelectFunctionsApplication.js.map +0 -1
  244. package/lib/typings/AgenticaSource.d.ts +0 -1
  245. package/lib/typings/AgenticaSource.js.map +0 -1
  246. package/src/internal/AgenticaPromptFactory.ts +0 -32
  247. package/src/internal/AgenticaPromptTransformer.ts +0 -86
  248. package/src/internal/AgenticaTokenUsageAggregator.ts +0 -121
  249. package/src/structures/IAgenticaEvent.ts +0 -229
  250. package/src/structures/IAgenticaOperationSelection.ts +0 -68
  251. package/src/structures/IAgenticaPrompt.ts +0 -182
  252. /package/lib/{structures → context}/internal/__IChatCancelFunctionsApplication.d.ts +0 -0
  253. /package/lib/{structures → context}/internal/__IChatCancelFunctionsApplication.js +0 -0
  254. /package/lib/{structures → context}/internal/__IChatFunctionReference.d.ts +0 -0
  255. /package/lib/{structures → context}/internal/__IChatFunctionReference.js +0 -0
  256. /package/lib/{structures → context}/internal/__IChatInitialApplication.d.ts +0 -0
  257. /package/lib/{structures → context}/internal/__IChatInitialApplication.js +0 -0
  258. /package/lib/{structures → context}/internal/__IChatSelectFunctionsApplication.d.ts +0 -0
  259. /package/lib/{structures → context}/internal/__IChatSelectFunctionsApplication.js +0 -0
  260. /package/src/{structures → context}/internal/__IChatCancelFunctionsApplication.ts +0 -0
  261. /package/src/{structures → context}/internal/__IChatFunctionReference.ts +0 -0
  262. /package/src/{structures → context}/internal/__IChatInitialApplication.ts +0 -0
  263. /package/src/{structures → context}/internal/__IChatSelectFunctionsApplication.ts +0 -0
@@ -1,50 +0,0 @@
1
- import { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
- import { IAgenticaController } from "./IAgenticaController";
3
- /**
4
- * Nestia agent operation selection.
5
- *
6
- * `IAgenticaOperationSelection` is a type represents an operation
7
- * which has been selected by the A.I. chatbot of {@link Agentica}
8
- * class for the LLM (Large Language Model) function calling with
9
- * detailed {@link reason} of the selection (or cancellation).
10
- *
11
- * Also, `IAgenticaOperationSelection` is an union type that can
12
- * specify a subtype by checking the {@link protocol} property.
13
- *
14
- * @author Samchon
15
- */
16
- export type IAgenticaOperationSelection<Model extends ILlmSchema.Model> = IAgenticaOperationSelection.IHttp<Model> | IAgenticaOperationSelection.IClass<Model>;
17
- export declare namespace IAgenticaOperationSelection {
18
- export type IHttp<Model extends ILlmSchema.Model> = IBase<"http", IAgenticaController.IHttp<Model>, IHttpLlmFunction<Model>>;
19
- export type IClass<Model extends ILlmSchema.Model> = IBase<"class", IAgenticaController.IClass<Model>, ILlmFunction<Model>>;
20
- interface IBase<Protocol, Controller, Function> {
21
- /**
22
- * Discriminator protocol.
23
- */
24
- protocol: Protocol;
25
- /**
26
- * Belonged controller of the target function.
27
- */
28
- controller: Controller;
29
- /**
30
- * Target function.
31
- *
32
- * Function that has been selected to prepare LLM function calling,
33
- * or canceled due to no more required.
34
- */
35
- function: Function;
36
- /**
37
- * Identifier name of the target function.
38
- *
39
- * If {@link Agentica} has multiple {@link IAgenticaController}s,
40
- * the `name` can be different from target function's name.
41
- */
42
- name: string;
43
- /**
44
- * The reason of the function selection or cancellation.
45
- */
46
- reason: string;
47
- toJSON(): Omit<IBase<Protocol, string, string>, "toJSON">;
48
- }
49
- export {};
50
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"IAgenticaOperationSelection.js","sourceRoot":"","sources":["../../src/structures/IAgenticaOperationSelection.ts"],"names":[],"mappings":""}
@@ -1,138 +0,0 @@
1
- import { IHttpLlmFunction, IHttpResponse, ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
- import { IAgenticaController } from "./IAgenticaController";
3
- import { IAgenticaOperationSelection } from "./IAgenticaOperationSelection";
4
- /**
5
- * Nestia A.I. chatbot prompt.
6
- *
7
- * `IWrtnChatPrompt` is an union type of all possible prompts that can
8
- * be generated by the A.I. chatbot of the {@link Agentica} class.
9
- *
10
- * In other words, `IWrtnChatPrompt` is a type of chat history that
11
- * is occurred during the conversation between the user and the A.I. chatbot
12
- * in the {@link Agentica} class.
13
- *
14
- * If you want to continue the previous A.I. chatbot session, you can
15
- * accomplish it by assigning the {@link IAgenticaProps.histories}
16
- * property when creating a new {@link Agentica} instance.
17
- *
18
- * @author Samchon
19
- */
20
- export type IAgenticaPrompt<Model extends ILlmSchema.Model> = IAgenticaPrompt.IText | IAgenticaPrompt.ISelect<Model> | IAgenticaPrompt.ICancel<Model> | IAgenticaPrompt.IExecute<Model> | IAgenticaPrompt.IDescribe<Model>;
21
- export declare namespace IAgenticaPrompt {
22
- /**
23
- * Select prompt.
24
- *
25
- * Selection prompt about candidate functions to call.
26
- */
27
- export interface ISelect<Model extends ILlmSchema.Model> extends IBase<"select"> {
28
- /**
29
- * ID of the LLM tool call result.
30
- */
31
- id: string;
32
- /**
33
- * Operations that have been selected.
34
- */
35
- operations: IAgenticaOperationSelection<Model>[];
36
- }
37
- /**
38
- * Cancel prompt.
39
- *
40
- * Cancellation prompt about the candidate functions to be discarded.
41
- */
42
- export interface ICancel<Model extends ILlmSchema.Model> extends IBase<"cancel"> {
43
- /**
44
- * ID of the LLM tool call result.
45
- */
46
- id: string;
47
- /**
48
- * Operations that have been cancelled.
49
- */
50
- operations: IAgenticaOperationSelection<Model>[];
51
- }
52
- /**
53
- * Execute prompt.
54
- *
55
- * Execution prompt about the LLM function calling.
56
- */
57
- export type IExecute<Model extends ILlmSchema.Model> = IExecute.IHttp<Model> | IExecute.IClass<Model>;
58
- export namespace IExecute {
59
- export type IHttp<Model extends ILlmSchema.Model> = IBase<"http", IAgenticaController.IHttp<Model>, IHttpLlmFunction<Model>, IHttpResponse>;
60
- export type IClass<Model extends ILlmSchema.Model> = IBase<"class", IAgenticaController.IClass<Model>, ILlmFunction<Model>, any>;
61
- interface IBase<Protocol, Controller, Function, Value> {
62
- /**
63
- * Discriminator type.
64
- */
65
- type: "execute";
66
- /**
67
- * Protocol discriminator.
68
- */
69
- protocol: Protocol;
70
- /**
71
- * Belonged controller of the target function.
72
- */
73
- controller: Controller;
74
- /**
75
- * Target function to call.
76
- */
77
- function: Function;
78
- /**
79
- * ID of the LLM tool call result.
80
- */
81
- id: string;
82
- /**
83
- * Identifier name of the function.
84
- *
85
- * If {@link Agentica} has multiple {@link IAgenticaController}s,
86
- * the `name` can be different from target function's name.
87
- */
88
- name: string;
89
- /**
90
- * Arguments of the LLM function calling.
91
- */
92
- arguments: object;
93
- /**
94
- * Return value.
95
- */
96
- value: Value;
97
- toJSON(): Omit<IBase<Protocol, string, string, Value>, "toJSON">;
98
- }
99
- export {};
100
- }
101
- /**
102
- * Description prompt.
103
- *
104
- * Description prompt about the return value of the LLM function calling.
105
- */
106
- export interface IDescribe<Model extends ILlmSchema.Model> extends IBase<"describe"> {
107
- /**
108
- * Executions of the LLM function calling.
109
- *
110
- * This prompt describes the return value of them.
111
- */
112
- executions: IExecute<Model>[];
113
- /**
114
- * Description text.
115
- */
116
- text: string;
117
- }
118
- /**
119
- * Text prompt.
120
- */
121
- export interface IText<Role extends "assistant" | "user" = "assistant" | "user"> extends IBase<"text"> {
122
- /**
123
- * Role of the orator.
124
- */
125
- role: Role;
126
- /**
127
- * The text content.
128
- */
129
- text: string;
130
- }
131
- interface IBase<Type extends string> {
132
- /**
133
- * Discriminator type.
134
- */
135
- type: Type;
136
- }
137
- export {};
138
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"IAgenticaPrompt.js","sourceRoot":"","sources":["../../src/structures/IAgenticaPrompt.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=IAgenticaTokenUsage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IAgenticaTokenUsage.js","sourceRoot":"","sources":["../../src/structures/IAgenticaTokenUsage.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"__IChatCancelFunctionsApplication.js","sourceRoot":"","sources":["../../../src/structures/internal/__IChatCancelFunctionsApplication.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"__IChatFunctionReference.js","sourceRoot":"","sources":["../../../src/structures/internal/__IChatFunctionReference.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"__IChatInitialApplication.js","sourceRoot":"","sources":["../../../src/structures/internal/__IChatInitialApplication.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"__IChatSelectFunctionsApplication.js","sourceRoot":"","sources":["../../../src/structures/internal/__IChatSelectFunctionsApplication.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- export type AgenticaSource = "initialize" | "select" | "cancel" | "call" | "describe";
@@ -1 +0,0 @@
1
- {"version":3,"file":"AgenticaSource.js","sourceRoot":"","sources":["../../src/typings/AgenticaSource.ts"],"names":[],"mappings":""}
@@ -1,32 +0,0 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
-
3
- import { IAgenticaOperationSelection } from "../structures/IAgenticaOperationSelection";
4
- import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
5
-
6
- export namespace AgenticaPromptFactory {
7
- export const execute = <Model extends ILlmSchema.Model>(
8
- props: Omit<IAgenticaPrompt.IExecute<Model>, "toJSON">,
9
- ): IAgenticaPrompt.IExecute<Model> =>
10
- ({
11
- ...props,
12
- toJSON: () =>
13
- ({
14
- ...props,
15
- controller: props.controller.name,
16
- function: props.function.name,
17
- }) as any,
18
- }) as IAgenticaPrompt.IExecute<Model>;
19
-
20
- export const selection = <Model extends ILlmSchema.Model>(
21
- props: Omit<IAgenticaOperationSelection<Model>, "toJSON">,
22
- ): IAgenticaOperationSelection<Model> =>
23
- ({
24
- ...props,
25
- toJSON: () =>
26
- ({
27
- ...props,
28
- controller: props.controller.name,
29
- function: props.function.name,
30
- }) as any,
31
- }) as IAgenticaOperationSelection<Model>;
32
- }
@@ -1,86 +0,0 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
- import { Primitive } from "typia";
3
-
4
- import { IAgenticaOperation } from "../structures/IAgenticaOperation";
5
- import { IAgenticaPrompt } from "../structures/IAgenticaPrompt";
6
- import { AgenticaPromptFactory } from "./AgenticaPromptFactory";
7
-
8
- export namespace AgenticaPromptTransformer {
9
- export const transform = <Model extends ILlmSchema.Model>(props: {
10
- operations: Map<string, Map<string, IAgenticaOperation<Model>>>;
11
- input: Primitive<IAgenticaPrompt<Model>>;
12
- }): IAgenticaPrompt<Model> => {
13
- // TEXT
14
- if (props.input.type === "text") return props.input;
15
- // SELECT & CANCEL
16
- else if (props.input.type === "select" || props.input.type === "cancel")
17
- return {
18
- ...props.input,
19
- operations: props.input.operations.map((func) =>
20
- AgenticaPromptFactory.selection({
21
- ...findOperation({
22
- operations: props.operations,
23
- input: func,
24
- }),
25
- reason: func.reason,
26
- }),
27
- ),
28
- } satisfies
29
- | IAgenticaPrompt.ISelect<Model>
30
- | IAgenticaPrompt.ICancel<Model>;
31
- // EXECUTE
32
- else if (props.input.type === "execute")
33
- return transformExecute({
34
- operations: props.operations,
35
- input: props.input,
36
- }) satisfies IAgenticaPrompt.IExecute<Model>;
37
- // DESCRIBE
38
- return {
39
- type: "describe",
40
- text: props.input.text,
41
- executions: props.input.executions.map((next) =>
42
- transformExecute({
43
- operations: props.operations,
44
- input: next,
45
- }),
46
- ),
47
- } satisfies IAgenticaPrompt.IDescribe<Model>;
48
- };
49
-
50
- const transformExecute = <Model extends ILlmSchema.Model>(props: {
51
- operations: Map<string, Map<string, IAgenticaOperation<Model>>>;
52
- input: Primitive<IAgenticaPrompt.IExecute<Model>>;
53
- }): IAgenticaPrompt.IExecute<Model> => {
54
- const operation = findOperation({
55
- operations: props.operations,
56
- input: props.input,
57
- });
58
- return AgenticaPromptFactory.execute({
59
- type: "execute",
60
- protocol: operation.protocol as "http",
61
- controller: operation.controller,
62
- function: operation.function,
63
- id: props.input.id,
64
- name: props.input.name,
65
- arguments: props.input.arguments,
66
- value: props.input.value,
67
- });
68
- };
69
-
70
- const findOperation = <Model extends ILlmSchema.Model>(props: {
71
- operations: Map<string, Map<string, IAgenticaOperation<Model>>>;
72
- input: {
73
- controller: string;
74
- function: string;
75
- };
76
- }): IAgenticaOperation.IHttp<Model> => {
77
- const found: IAgenticaOperation<Model> | undefined = props.operations
78
- .get(props.input.controller)
79
- ?.get(props.input.function);
80
- if (found === undefined)
81
- throw new Error(
82
- `No operation found: (controller: ${props.input.controller}, function: ${props.input.function})`,
83
- );
84
- return found as IAgenticaOperation.IHttp<Model>;
85
- };
86
- }
@@ -1,121 +0,0 @@
1
- import { CompletionUsage } from "openai/resources";
2
-
3
- import { IAgenticaTokenUsage } from "../structures/IAgenticaTokenUsage";
4
-
5
- export namespace AgenticaTokenUsageAggregator {
6
- export const aggregate = (props: {
7
- kind: Exclude<keyof IAgenticaTokenUsage, "aggregate">;
8
- completionUsage: CompletionUsage;
9
- usage: IAgenticaTokenUsage;
10
- }): void => {
11
- if (!props.completionUsage) return;
12
-
13
- //----
14
- // COMPONENT
15
- //----
16
- const component: IAgenticaTokenUsage.IComponent = props.usage[props.kind];
17
-
18
- // TOTAL
19
- component.total += props.completionUsage.total_tokens;
20
-
21
- // PROMPT
22
- component.input.total += props.completionUsage.prompt_tokens;
23
- component.input.total +=
24
- props.completionUsage.prompt_tokens_details?.audio_tokens ?? 0;
25
- component.input.cached +=
26
- props.completionUsage.prompt_tokens_details?.cached_tokens ?? 0;
27
-
28
- // COMPLETION
29
- component.output.total += props.completionUsage.total_tokens;
30
- component.output.accepted_prediction +=
31
- props.completionUsage.completion_tokens_details
32
- ?.accepted_prediction_tokens ?? 0;
33
- component.output.reasoning +=
34
- props.completionUsage.completion_tokens_details?.reasoning_tokens ?? 0;
35
- component.output.rejected_prediction +=
36
- props.completionUsage.completion_tokens_details
37
- ?.rejected_prediction_tokens ?? 0;
38
-
39
- //----
40
- // RE-AGGREGATE
41
- //----
42
- const sum = (getter: (comp: IAgenticaTokenUsage.IComponent) => number) =>
43
- (
44
- Object.entries(props.usage) as [
45
- keyof IAgenticaTokenUsage,
46
- IAgenticaTokenUsage.IComponent,
47
- ][]
48
- )
49
- .filter(([key]) => key !== "aggregate")
50
- .map(([, comp]) => getter(comp))
51
- .reduce((a, b) => a + b, 0);
52
- const aggregate: IAgenticaTokenUsage.IComponent = props.usage.aggregate;
53
- aggregate.total = sum((comp) => comp.total);
54
- aggregate.input.total = sum((comp) => comp.input.total);
55
- aggregate.input.cached = sum((comp) => comp.input.cached);
56
- aggregate.output.total = sum((comp) => comp.output.total);
57
- aggregate.output.reasoning = sum((comp) => comp.output.reasoning);
58
- aggregate.output.accepted_prediction = sum(
59
- (comp) => comp.output.accepted_prediction,
60
- );
61
- aggregate.output.rejected_prediction = sum(
62
- (comp) => comp.output.rejected_prediction,
63
- );
64
- };
65
-
66
- export const plus = (
67
- x: IAgenticaTokenUsage,
68
- y: IAgenticaTokenUsage,
69
- ): IAgenticaTokenUsage => {
70
- const component = (
71
- a: IAgenticaTokenUsage.IComponent,
72
- b: IAgenticaTokenUsage.IComponent,
73
- ): IAgenticaTokenUsage.IComponent => ({
74
- total: a.total + b.total,
75
- input: {
76
- total: a.input.total + b.input.total,
77
- cached: a.input.cached + b.input.cached,
78
- },
79
- output: {
80
- total: a.output.total + b.output.total,
81
- reasoning: a.output.reasoning + b.output.reasoning,
82
- accepted_prediction:
83
- a.output.accepted_prediction + b.output.accepted_prediction,
84
- rejected_prediction:
85
- a.output.rejected_prediction + b.output.rejected_prediction,
86
- },
87
- });
88
- return {
89
- aggregate: component(x.aggregate, y.aggregate),
90
- initialize: component(x.initialize, y.initialize),
91
- select: component(x.select, y.select),
92
- cancel: component(x.cancel, y.cancel),
93
- call: component(x.call, y.call),
94
- describe: component(x.describe, y.describe),
95
- };
96
- };
97
-
98
- export const zero = (): IAgenticaTokenUsage => {
99
- const component = (): IAgenticaTokenUsage.IComponent => ({
100
- total: 0,
101
- input: {
102
- total: 0,
103
- cached: 0,
104
- },
105
- output: {
106
- total: 0,
107
- reasoning: 0,
108
- accepted_prediction: 0,
109
- rejected_prediction: 0,
110
- },
111
- });
112
- return {
113
- aggregate: component(),
114
- initialize: component(),
115
- select: component(),
116
- cancel: component(),
117
- call: component(),
118
- describe: component(),
119
- };
120
- };
121
- }
@@ -1,229 +0,0 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
- import OpenAI from "openai";
3
-
4
- import { AgenticaSource } from "../typings/AgenticaSource";
5
- import { IAgenticaOperation } from "./IAgenticaOperation";
6
- import { IAgenticaPrompt } from "./IAgenticaPrompt";
7
-
8
- /**
9
- * Nestia A.I. chatbot event.
10
- *
11
- * `IAgenticaEvent` is an union type of all possible events that can
12
- * be emitted by the A.I. chatbot of the {@link Agentica} class. You
13
- * can discriminate the subtype by checking the {@link type} property.
14
- *
15
- * @author Samchon
16
- */
17
- export type IAgenticaEvent<Model extends ILlmSchema.Model> =
18
- | IAgenticaEvent.IInitialize
19
- | IAgenticaEvent.ISelect<Model>
20
- | IAgenticaEvent.ICancel<Model>
21
- | IAgenticaEvent.ICall<Model>
22
- | IAgenticaEvent.IExecute<Model>
23
- | IAgenticaEvent.IDescribe<Model>
24
- | IAgenticaEvent.IText
25
- | IAgenticaEvent.IRequest
26
- | IAgenticaEvent.IResponse;
27
- export namespace IAgenticaEvent {
28
- export type Type = IAgenticaEvent<any>["type"];
29
- export type Mapper<Model extends ILlmSchema.Model> = {
30
- initialize: IInitialize;
31
- select: ISelect<Model>;
32
- cancel: ICancel<Model>;
33
- call: ICall<Model>;
34
- execute: IExecute<Model>;
35
- describe: IDescribe<Model>;
36
- text: IText;
37
- request: IRequest;
38
- response: IResponse;
39
- };
40
-
41
- /**
42
- * Event of initializing the chatbot.
43
- */
44
- export interface IInitialize extends IBase<"initialize"> {}
45
-
46
- /**
47
- * Event of selecting a function to call.
48
- */
49
- export interface ISelect<Model extends ILlmSchema.Model>
50
- extends IBase<"select"> {
51
- /**
52
- * Selected operation.
53
- *
54
- * Operation that has been selected to prepare LLM function calling.
55
- */
56
- operation: IAgenticaOperation<Model>;
57
-
58
- /**
59
- * Reason of selecting the function.
60
- *
61
- * The A.I. chatbot will fill this property describing why the function
62
- * has been selected.
63
- */
64
- reason: string;
65
- }
66
-
67
- /**
68
- * Event of canceling a function calling.
69
- */
70
- export interface ICancel<Model extends ILlmSchema.Model>
71
- extends IBase<"cancel"> {
72
- /**
73
- * Selected operation to cancel.
74
- *
75
- * Operation that has been selected to prepare LLM function calling,
76
- * but canceled due to no more required.
77
- */
78
- operation: IAgenticaOperation<Model>;
79
-
80
- /**
81
- * Reason of selecting the function.
82
- *
83
- * The A.I. chatbot will fill this property describing why the function
84
- * has been cancelled.
85
- *
86
- * For reference, if the A.I. chatbot successfully completes the LLM
87
- * function calling, the reason of the function cancellation will be
88
- * "complete".
89
- */
90
- reason: string;
91
- }
92
-
93
- /**
94
- * Event of calling a function.
95
- */
96
- export interface ICall<Model extends ILlmSchema.Model> extends IBase<"call"> {
97
- /**
98
- * ID of the tool calling.
99
- */
100
- id: string;
101
-
102
- /**
103
- * Target operation to call.
104
- */
105
- operation: IAgenticaOperation<Model>;
106
-
107
- /**
108
- * Arguments of the function calling.
109
- *
110
- * If you modify this {@link arguments} property, it actually modifies
111
- * the backend server's request. Therefore, be careful when you're
112
- * trying to modify this property.
113
- */
114
- arguments: object;
115
- }
116
-
117
- /**
118
- * Event of function calling execution.
119
- */
120
- export interface IExecute<Model extends ILlmSchema.Model>
121
- extends IBase<"execute"> {
122
- /**
123
- * ID of the tool calling.
124
- */
125
- id: string;
126
-
127
- /**
128
- * Target operation had called.
129
- */
130
- operation: IAgenticaOperation<Model>;
131
-
132
- /**
133
- * Arguments of the function calling.
134
- */
135
- arguments: object;
136
-
137
- /**
138
- * Return value.
139
- */
140
- value: any;
141
- }
142
-
143
- /**
144
- * Event of description.
145
- *
146
- * Event describing return values of LLM function callings.
147
- */
148
- export interface IDescribe<Model extends ILlmSchema.Model>
149
- extends IBase<"describe"> {
150
- /**
151
- * Executions of the LLM function calling.
152
- *
153
- * This prompt describes the return value of them.
154
- */
155
- executions: IAgenticaPrompt.IExecute<Model>[];
156
-
157
- /**
158
- * Description text.
159
- */
160
- text: string;
161
- }
162
-
163
- /**
164
- * Event of text message.
165
- */
166
- export interface IText extends IBase<"text"> {
167
- /**
168
- * Role of the orator.
169
- */
170
- role: "assistant" | "user";
171
-
172
- /**
173
- * The text content.
174
- */
175
- text: string;
176
- }
177
-
178
- /**
179
- * Request event of LLM vendor API.
180
- */
181
- export interface IRequest extends IBase<"request"> {
182
- /**
183
- * The source agent of the request.
184
- */
185
- source: AgenticaSource;
186
-
187
- /**
188
- * Request body.
189
- */
190
- body: OpenAI.ChatCompletionCreateParamsNonStreaming;
191
-
192
- /**
193
- * Options for the request.
194
- */
195
- options?: OpenAI.RequestOptions | undefined;
196
- }
197
-
198
- /**
199
- * Response event of LLM vendor API.
200
- */
201
- export interface IResponse extends IBase<"response"> {
202
- /**
203
- * The source agent of the response.
204
- */
205
- source: AgenticaSource;
206
-
207
- /**
208
- * Request body.
209
- */
210
- body: OpenAI.ChatCompletionCreateParamsNonStreaming;
211
-
212
- /**
213
- * Options for the request.
214
- */
215
- options?: OpenAI.RequestOptions | undefined;
216
-
217
- /**
218
- * Return value from the LLM vendor API.
219
- */
220
- value: OpenAI.ChatCompletion;
221
- }
222
-
223
- interface IBase<Type extends string> {
224
- /**
225
- * Discriminator type.
226
- */
227
- type: Type;
228
- }
229
- }