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