@agentica/core 0.12.20 → 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,13 +1,13 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
- import OpenAI from "openai";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
+ import type OpenAI from "openai";
3
3
 
4
- import { AgenticaEvent } from "../events/AgenticaEvent";
5
- import { AgenticaEventSource } from "../events/AgenticaEventSource";
6
- import { AgenticaPrompt } from "../prompts/AgenticaPrompt";
7
- import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
8
- import { IAgenticaConfig } from "../structures/IAgenticaConfig";
9
- import { AgenticaOperationCollection } from "./AgenticaOperationCollection";
10
- import { AgenticaOperationSelection } from "./AgenticaOperationSelection";
4
+ import type { AgenticaEvent } from "../events/AgenticaEvent";
5
+ import type { AgenticaEventSource } from "../events/AgenticaEventSource";
6
+ import type { AgenticaPrompt } from "../prompts/AgenticaPrompt";
7
+ import type { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
8
+ import type { IAgenticaConfig } from "../structures/IAgenticaConfig";
9
+ import type { AgenticaOperationCollection } from "./AgenticaOperationCollection";
10
+ import type { AgenticaOperationSelection } from "./AgenticaOperationSelection";
11
11
 
12
12
  /**
13
13
  * Context of the Nestia A.I. agent.
@@ -41,9 +41,9 @@ import { AgenticaOperationSelection } from "./AgenticaOperationSelection";
41
41
  * @author Samchon
42
42
  */
43
43
  export interface AgenticaContext<Model extends ILlmSchema.Model> {
44
- //----
44
+ // ----
45
45
  // APPLICATION
46
- //----
46
+ // ----
47
47
  /**
48
48
  * Collection of operations.
49
49
  *
@@ -63,9 +63,9 @@ export interface AgenticaContext<Model extends ILlmSchema.Model> {
63
63
  */
64
64
  config: IAgenticaConfig<Model> | undefined;
65
65
 
66
- //----
66
+ // ----
67
67
  // STATES
68
- //----
68
+ // ----
69
69
  /**
70
70
  * Prompt histories.
71
71
  */
@@ -98,9 +98,9 @@ export interface AgenticaContext<Model extends ILlmSchema.Model> {
98
98
  */
99
99
  ready: () => boolean;
100
100
 
101
- //----
101
+ // ----
102
102
  // HANDLERS
103
- //----
103
+ // ----
104
104
  /**
105
105
  * Dispatch event.
106
106
  *
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  IHttpLlmApplication,
3
3
  IHttpLlmFunction,
4
4
  ILlmSchema,
@@ -9,10 +9,10 @@ import { AgenticaOperationBase } from "./AgenticaOperationBase";
9
9
  export class AgenticaHttpOperation<
10
10
  Model extends ILlmSchema.Model,
11
11
  > extends AgenticaOperationBase<
12
- "http",
13
- IHttpLlmApplication<Model>,
14
- IHttpLlmFunction<Model>
15
- > {
12
+ "http",
13
+ IHttpLlmApplication<Model>,
14
+ IHttpLlmFunction<Model>
15
+ > {
16
16
  public constructor(props: AgenticaHttpOperation.IProps<Model>) {
17
17
  super(props);
18
18
  }
@@ -1,7 +1,7 @@
1
- import { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
1
+ import type { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
4
- import { IAgenticaController } from "../structures/IAgenticaController";
3
+ import type { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
4
+ import type { IAgenticaController } from "../structures/IAgenticaController";
5
5
 
6
6
  /**
7
7
  * Operation information in the Agentica Agent.
@@ -61,6 +61,6 @@ export namespace AgenticaOperation {
61
61
  /**
62
62
  * Convert to primitive JSON object.
63
63
  */
64
- toJSON(): IAgenticaOperationJson;
64
+ toJSON: () => IAgenticaOperationJson;
65
65
  }
66
66
  }
@@ -1,4 +1,4 @@
1
- import { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
1
+ import type { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
2
2
 
3
3
  export abstract class AgenticaOperationBase<
4
4
  Protocol extends "http" | "class",
@@ -1,6 +1,6 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaOperation } from "./AgenticaOperation";
3
+ import type { AgenticaOperation } from "./AgenticaOperation";
4
4
 
5
5
  /**
6
6
  * Collection of operations used in the Nestia Agent.
@@ -1,7 +1,7 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
4
- import { AgenticaOperation } from "./AgenticaOperation";
3
+ import type { IAgenticaOperationSelectionJson } from "../json/IAgenticaOperationSelectionJson";
4
+ import type { AgenticaOperation } from "./AgenticaOperation";
5
5
 
6
6
  export class AgenticaOperationSelection<Model extends ILlmSchema.Model> {
7
7
  public readonly operation: AgenticaOperation<Model>;
@@ -1,6 +1,6 @@
1
- import typia from "typia";
1
+ import type { IAgenticaTokenUsageJson } from "../json/IAgenticaTokenUsageJson";
2
2
 
3
- import { IAgenticaTokenUsageJson } from "../json/IAgenticaTokenUsageJson";
3
+ import typia from "typia";
4
4
 
5
5
  export class AgenticaTokenUsage implements IAgenticaTokenUsageJson {
6
6
  /**
@@ -42,7 +42,8 @@ export class AgenticaTokenUsage implements IAgenticaTokenUsageJson {
42
42
  this.cancel = zero.cancel;
43
43
  this.call = zero.call;
44
44
  this.describe = zero.describe;
45
- } else {
45
+ }
46
+ else {
46
47
  this.aggregate = props.aggregate;
47
48
  this.initialize = props.initialize;
48
49
  this.select = props.select;
@@ -1,66 +1,66 @@
1
- import { CompletionUsage } from "openai/resources";
1
+ import type { CompletionUsage } from "openai/resources";
2
2
 
3
- import { IAgenticaTokenUsageJson } from "../../json/IAgenticaTokenUsageJson";
4
- import { AgenticaTokenUsage } from "../AgenticaTokenUsage";
3
+ import type { IAgenticaTokenUsageJson } from "../../json/IAgenticaTokenUsageJson";
4
+ import type { AgenticaTokenUsage } from "../AgenticaTokenUsage";
5
5
 
6
- export namespace AgenticaTokenUsageAggregator {
7
- export const aggregate = (props: {
8
- kind: Exclude<keyof IAgenticaTokenUsageJson, "aggregate">;
9
- completionUsage: CompletionUsage;
10
- usage: AgenticaTokenUsage;
11
- }): void => {
12
- if (!props.completionUsage) return;
6
+ export function aggregate(props: {
7
+ kind: Exclude<keyof IAgenticaTokenUsageJson, "aggregate">;
8
+ completionUsage: CompletionUsage;
9
+ usage: AgenticaTokenUsage;
10
+ }): void {
11
+ // ----
12
+ // COMPONENT
13
+ // ----
14
+ const component: AgenticaTokenUsage.IComponent = props.usage[props.kind];
13
15
 
14
- //----
15
- // COMPONENT
16
- //----
17
- const component: AgenticaTokenUsage.IComponent = props.usage[props.kind];
16
+ // TOTAL
17
+ component.total += props.completionUsage.total_tokens;
18
18
 
19
- // TOTAL
20
- component.total += props.completionUsage.total_tokens;
19
+ // PROMPT
20
+ component.input.total += props.completionUsage.prompt_tokens;
21
+ component.input.total
22
+ += props.completionUsage.prompt_tokens_details?.audio_tokens ?? 0;
23
+ component.input.cached
24
+ += props.completionUsage.prompt_tokens_details?.cached_tokens ?? 0;
21
25
 
22
- // PROMPT
23
- component.input.total += props.completionUsage.prompt_tokens;
24
- component.input.total +=
25
- props.completionUsage.prompt_tokens_details?.audio_tokens ?? 0;
26
- component.input.cached +=
27
- props.completionUsage.prompt_tokens_details?.cached_tokens ?? 0;
26
+ // COMPLETION
27
+ component.output.total += props.completionUsage.completion_tokens;
28
+ component.output.accepted_prediction
29
+ += props.completionUsage.completion_tokens_details
30
+ ?.accepted_prediction_tokens ?? 0;
31
+ component.output.reasoning
32
+ += props.completionUsage.completion_tokens_details?.reasoning_tokens ?? 0;
33
+ component.output.rejected_prediction
34
+ += props.completionUsage.completion_tokens_details
35
+ ?.rejected_prediction_tokens ?? 0;
28
36
 
29
- // COMPLETION
30
- component.output.total += props.completionUsage.completion_tokens;
31
- component.output.accepted_prediction +=
32
- props.completionUsage.completion_tokens_details
33
- ?.accepted_prediction_tokens ?? 0;
34
- component.output.reasoning +=
35
- props.completionUsage.completion_tokens_details?.reasoning_tokens ?? 0;
36
- component.output.rejected_prediction +=
37
- props.completionUsage.completion_tokens_details
38
- ?.rejected_prediction_tokens ?? 0;
39
-
40
- //----
41
- // RE-AGGREGATE
42
- //----
43
- const sum = (getter: (comp: AgenticaTokenUsage.IComponent) => number) =>
44
- (
45
- Object.entries(props.usage) as [
46
- keyof AgenticaTokenUsage,
47
- AgenticaTokenUsage.IComponent,
48
- ][]
49
- )
50
- .filter(([key]) => key !== "aggregate")
51
- .map(([, comp]) => getter(comp))
52
- .reduce((a, b) => a + b, 0);
53
- const aggregate: AgenticaTokenUsage.IComponent = props.usage.aggregate;
54
- aggregate.total = sum((comp) => comp.total);
55
- aggregate.input.total = sum((comp) => comp.input.total);
56
- aggregate.input.cached = sum((comp) => comp.input.cached);
57
- aggregate.output.total = sum((comp) => comp.output.total);
58
- aggregate.output.reasoning = sum((comp) => comp.output.reasoning);
59
- aggregate.output.accepted_prediction = sum(
60
- (comp) => comp.output.accepted_prediction,
61
- );
62
- aggregate.output.rejected_prediction = sum(
63
- (comp) => comp.output.rejected_prediction,
64
- );
65
- };
37
+ // ----
38
+ // RE-AGGREGATE
39
+ // ----
40
+ const sum = (getter: (comp: AgenticaTokenUsage.IComponent) => number) =>
41
+ (
42
+ Object.entries(props.usage) as [
43
+ keyof AgenticaTokenUsage,
44
+ AgenticaTokenUsage.IComponent,
45
+ ][]
46
+ )
47
+ .filter(([key]) => key !== "aggregate")
48
+ .map(([, comp]) => getter(comp))
49
+ .reduce((a, b) => a + b, 0);
50
+ const aggregate: AgenticaTokenUsage.IComponent = props.usage.aggregate;
51
+ aggregate.total = sum(comp => comp.total);
52
+ aggregate.input.total = sum(comp => comp.input.total);
53
+ aggregate.input.cached = sum(comp => comp.input.cached);
54
+ aggregate.output.total = sum(comp => comp.output.total);
55
+ aggregate.output.reasoning = sum(comp => comp.output.reasoning);
56
+ aggregate.output.accepted_prediction = sum(
57
+ comp => comp.output.accepted_prediction,
58
+ );
59
+ aggregate.output.rejected_prediction = sum(
60
+ comp => comp.output.rejected_prediction,
61
+ );
66
62
  }
63
+
64
+ export const AgenticaTokenUsageAggregator = {
65
+ aggregate,
66
+ };
@@ -1,4 +1,4 @@
1
- import { __IChatFunctionReference } from "./__IChatFunctionReference";
1
+ import type { __IChatFunctionReference } from "./__IChatFunctionReference";
2
2
 
3
3
  export interface __IChatCancelFunctionsApplication {
4
4
  /**
@@ -19,5 +19,5 @@ export interface __IChatCancelFunctionsApplication {
19
19
  *
20
20
  * @param props Properties of the function
21
21
  */
22
- cancelFunctions(props: __IChatFunctionReference.IProps): Promise<void>;
22
+ cancelFunctions: (props: __IChatFunctionReference.IProps) => Promise<void>;
23
23
  }
@@ -1,4 +1,4 @@
1
- import { IHttpLlmFunction } from "@samchon/openapi";
1
+ import type { IHttpLlmFunction } from "@samchon/openapi";
2
2
 
3
3
  export interface __IChatInitialApplication {
4
4
  /**
@@ -11,5 +11,5 @@ export interface __IChatInitialApplication {
11
11
  * Also, user just wants to list up every remote API functions that can be
12
12
  * called from the backend server, utilize this function too.
13
13
  */
14
- getApiFunctions({}): Promise<Array<IHttpLlmFunction<"chatgpt">>>;
14
+ getApiFunctions: (props: object) => Promise<Array<IHttpLlmFunction<"chatgpt">>>;
15
15
  }
@@ -1,4 +1,4 @@
1
- import { __IChatFunctionReference } from "./__IChatFunctionReference";
1
+ import type { __IChatFunctionReference } from "./__IChatFunctionReference";
2
2
 
3
3
  export interface __IChatSelectFunctionsApplication {
4
4
  /**
@@ -20,5 +20,5 @@ export interface __IChatSelectFunctionsApplication {
20
20
  *
21
21
  * @param props Properties of the function
22
22
  */
23
- selectFunctions(props: __IChatFunctionReference.IProps): Promise<void>;
23
+ selectFunctions: (props: __IChatFunctionReference.IProps) => Promise<void>;
24
24
  }
@@ -1,7 +1,7 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaOperation } from "../context/AgenticaOperation";
4
- import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
3
+ import type { AgenticaOperation } from "../context/AgenticaOperation";
4
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
5
5
  import { AgenticaEventBase } from "./AgenticaEventBase";
6
6
 
7
7
  export class AgenticaCallEvent<
@@ -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 { IAgenticaEventJson } from "../json/IAgenticaEventJson";
3
+ import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
4
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
5
5
  import { AgenticaEventBase } from "./AgenticaEventBase";
6
6
 
7
7
  export class AgenticaCancelEvent<
@@ -1,8 +1,8 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
3
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
4
+ import type { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
4
5
  import { AgenticaDescribePrompt } from "../prompts/AgenticaDescribePrompt";
5
- import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
6
6
  import { AgenticaEventBase } from "./AgenticaEventBase";
7
7
 
8
8
  export class AgenticaDescribeEvent<
@@ -31,14 +31,14 @@ export class AgenticaDescribeEvent<
31
31
  this.join_ = props.join;
32
32
  }
33
33
 
34
- public join(): Promise<string> {
34
+ public async join(): Promise<string> {
35
35
  return this.join_();
36
36
  }
37
37
 
38
38
  public toJSON(): IAgenticaEventJson.IDescribe {
39
39
  return {
40
40
  type: "describe",
41
- executes: this.executes.map((e) => e.toJSON()),
41
+ executes: this.executes.map(e => e.toJSON()),
42
42
  text: this.text,
43
43
  done: this.done,
44
44
  };
@@ -1,14 +1,14 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaCallEvent } from "./AgenticaCallEvent";
4
- import { AgenticaCancelEvent } from "./AgenticaCancelEvent";
5
- import { AgenticaDescribeEvent } from "./AgenticaDescribeEvent";
6
- import { AgenticaExecuteEvent } from "./AgenticaExecuteEvent";
7
- import { AgenticaInitializeEvent } from "./AgenticaInitializeEvent";
8
- import { AgenticaRequestEvent } from "./AgenticaRequestEvent";
9
- import { AgenticaResponseEvent } from "./AgenticaResponseEvent";
10
- import { AgenticaSelectEvent } from "./AgenticaSelectEvent";
11
- import { AgenticaTextEvent } from "./AgenticaTextEvent";
3
+ import type { AgenticaCallEvent } from "./AgenticaCallEvent";
4
+ import type { AgenticaCancelEvent } from "./AgenticaCancelEvent";
5
+ import type { AgenticaDescribeEvent } from "./AgenticaDescribeEvent";
6
+ import type { AgenticaExecuteEvent } from "./AgenticaExecuteEvent";
7
+ import type { AgenticaInitializeEvent } from "./AgenticaInitializeEvent";
8
+ import type { AgenticaRequestEvent } from "./AgenticaRequestEvent";
9
+ import type { AgenticaResponseEvent } from "./AgenticaResponseEvent";
10
+ import type { AgenticaSelectEvent } from "./AgenticaSelectEvent";
11
+ import type { AgenticaTextEvent } from "./AgenticaTextEvent";
12
12
 
13
13
  export type AgenticaEvent<Model extends ILlmSchema.Model> =
14
14
  | AgenticaCallEvent<Model>
@@ -22,7 +22,7 @@ export type AgenticaEvent<Model extends ILlmSchema.Model> =
22
22
  | AgenticaTextEvent;
23
23
  export namespace AgenticaEvent {
24
24
  export type Type = AgenticaEvent<any>["type"];
25
- export type Mapper<Model extends ILlmSchema.Model> = {
25
+ export interface Mapper<Model extends ILlmSchema.Model> {
26
26
  call: AgenticaCallEvent<Model>;
27
27
  cancel: AgenticaCancelEvent<Model>;
28
28
  describe: AgenticaDescribeEvent<Model>;
@@ -32,5 +32,5 @@ export namespace AgenticaEvent {
32
32
  response: AgenticaResponseEvent;
33
33
  select: AgenticaSelectEvent<Model>;
34
34
  text: AgenticaTextEvent;
35
- };
35
+ }
36
36
  }
@@ -1,7 +1,7 @@
1
- import { ILlmSchema } from "@samchon/openapi";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
- import { AgenticaOperation } from "../context/AgenticaOperation";
4
- import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
3
+ import type { AgenticaOperation } from "../context/AgenticaOperation";
4
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
5
5
  import { AgenticaExecutePrompt } from "../prompts/AgenticaExecutePrompt";
6
6
  import { AgenticaEventBase } from "./AgenticaEventBase";
7
7
 
@@ -10,8 +10,8 @@ export class AgenticaExecuteEvent<
10
10
  > extends AgenticaEventBase<"execute"> {
11
11
  public readonly id: string;
12
12
  public readonly operation: AgenticaOperation<Model>;
13
- public readonly arguments: Record<string, any>;
14
- public readonly value: any;
13
+ public readonly arguments: Record<string, unknown>;
14
+ public readonly value: unknown;
15
15
 
16
16
  public constructor(props: AgenticaExecuteEvent.IProps<Model>) {
17
17
  super("execute");
@@ -44,7 +44,7 @@ export namespace AgenticaExecuteEvent {
44
44
  export interface IProps<Model extends ILlmSchema.Model> {
45
45
  id: string;
46
46
  operation: AgenticaOperation<Model>;
47
- arguments: Record<string, any>;
48
- value: any;
47
+ arguments: Record<string, unknown>;
48
+ value: unknown;
49
49
  }
50
50
  }
@@ -1,4 +1,4 @@
1
- import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
1
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
2
2
  import { AgenticaEventBase } from "./AgenticaEventBase";
3
3
 
4
4
  export class AgenticaInitializeEvent extends AgenticaEventBase<"initialize"> {
@@ -1,8 +1,8 @@
1
- import OpenAI from "openai";
1
+ import type OpenAI from "openai";
2
2
 
3
- import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
3
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
4
+ import type { AgenticaEventSource } from "./AgenticaEventSource";
4
5
  import { AgenticaEventBase } from "./AgenticaEventBase";
5
- import { AgenticaEventSource } from "./AgenticaEventSource";
6
6
 
7
7
  export class AgenticaRequestEvent extends AgenticaEventBase<"request"> {
8
8
  public readonly source: AgenticaEventSource;
@@ -1,7 +1,7 @@
1
- import OpenAI from "openai";
1
+ import type OpenAI from "openai";
2
2
 
3
+ import type { AgenticaEventSource } from "./AgenticaEventSource";
3
4
  import { AgenticaEventBase } from "./AgenticaEventBase";
4
- import { AgenticaEventSource } from "./AgenticaEventSource";
5
5
 
6
6
  export class AgenticaResponseEvent extends AgenticaEventBase<"response"> {
7
7
  public readonly source: AgenticaEventSource;
@@ -1,8 +1,8 @@
1
- import { ILlmSchema } from "@samchon/openapi";
2
- import { v4 } from "uuid";
1
+ import type { ILlmSchema } from "@samchon/openapi";
2
+ import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
3
3
 
4
- import { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
5
- import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
4
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
5
+ import { v4 } from "uuid";
6
6
  import { AgenticaSelectPrompt } from "../prompts/AgenticaSelectPrompt";
7
7
  import { AgenticaEventBase } from "./AgenticaEventBase";
8
8
 
@@ -1,4 +1,4 @@
1
- import { IAgenticaEventJson } from "../json/IAgenticaEventJson";
1
+ import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
2
2
  import { AgenticaTextPrompt } from "../prompts/AgenticaTextPrompt";
3
3
  import { AgenticaEventBase } from "./AgenticaEventBase";
4
4
 
@@ -27,7 +27,7 @@ export class AgenticaTextEvent extends AgenticaEventBase<"text"> {
27
27
  this.join_ = props.join;
28
28
  }
29
29
 
30
- public join(): Promise<string> {
30
+ public async join(): Promise<string> {
31
31
  return this.join_();
32
32
  }
33
33
 
@@ -1,12 +1,14 @@
1
- import {
2
- HttpLlm,
1
+ import type {
3
2
  IHttpLlmApplication,
4
3
  ILlmSchema,
5
- OpenApi,
6
4
  OpenApiV3,
7
5
  OpenApiV3_1,
8
6
  SwaggerV2,
9
7
  } from "@samchon/openapi";
8
+ import {
9
+ HttpLlm,
10
+ OpenApi,
11
+ } from "@samchon/openapi";
10
12
  import typia from "typia";
11
13
 
12
14
  /**
@@ -26,7 +28,7 @@ import typia from "typia";
26
28
  * @throws {@link TypeGuardError} when the given document is invalid
27
29
  * @author Samchon
28
30
  */
29
- export const assertHttpLlmApplication = <
31
+ export function assertHttpLlmApplication<
30
32
  Model extends ILlmSchema.Model,
31
33
  >(props: {
32
34
  /**
@@ -47,9 +49,10 @@ export const assertHttpLlmApplication = <
47
49
  * Options for the LLM function calling schema composition.
48
50
  */
49
51
  options?: Partial<IHttpLlmApplication.IOptions<Model>>;
50
- }): IHttpLlmApplication<Model> =>
51
- HttpLlm.application({
52
+ }): IHttpLlmApplication<Model> {
53
+ return HttpLlm.application({
52
54
  model: props.model,
53
55
  document: OpenApi.convert(typia.assert(props.document)),
54
56
  options: props.options,
55
57
  });
58
+ }
@@ -1,13 +1,16 @@
1
- import {
2
- HttpLlm,
1
+ import type {
3
2
  IHttpLlmApplication,
4
3
  ILlmSchema,
5
- OpenApi,
6
4
  OpenApiV3,
7
5
  OpenApiV3_1,
8
6
  SwaggerV2,
9
7
  } from "@samchon/openapi";
10
- import typia, { IValidation } from "typia";
8
+ import type { IValidation } from "typia";
9
+ import {
10
+ HttpLlm,
11
+ OpenApi,
12
+ } from "@samchon/openapi";
13
+ import typia from "typia";
11
14
 
12
15
  /**
13
16
  * Create an HTTP LLM application instance with type validation.
@@ -26,7 +29,7 @@ import typia, { IValidation } from "typia";
26
29
  * @returns Validation result of the HTTP LLM application composition
27
30
  * @author Samchon
28
31
  */
29
- export const validateHttpLlmApplication = <
32
+ export function validateHttpLlmApplication<
30
33
  Model extends ILlmSchema.Model,
31
34
  >(props: {
32
35
  /**
@@ -47,14 +50,17 @@ export const validateHttpLlmApplication = <
47
50
  * Options for the LLM function calling schema composition.
48
51
  */
49
52
  options?: Partial<IHttpLlmApplication.IOptions<Model>>;
50
- }): IValidation<IHttpLlmApplication<Model>> => {
53
+ }): IValidation<IHttpLlmApplication<Model>> {
51
54
  const inspect: IValidation<
52
55
  | SwaggerV2.IDocument
53
56
  | OpenApiV3.IDocument
54
57
  | OpenApiV3_1.IDocument
55
58
  | OpenApi.IDocument
56
59
  > = typia.validate(props.document);
57
- if (inspect.success === false) return inspect;
60
+ if (inspect.success === false) {
61
+ return inspect;
62
+ }
63
+
58
64
  return {
59
65
  success: true,
60
66
  data: HttpLlm.application({
@@ -63,4 +69,4 @@ export const validateHttpLlmApplication = <
63
69
  options: props.options,
64
70
  }),
65
71
  };
66
- };
72
+ }