@agentica/core 0.24.0 → 0.26.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 (189) hide show
  1. package/README.md +56 -17
  2. package/lib/Agentica.d.ts +2 -2
  3. package/lib/Agentica.js +4 -4
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/MicroAgentica.d.ts +2 -2
  6. package/lib/MicroAgentica.js +4 -4
  7. package/lib/MicroAgentica.js.map +1 -1
  8. package/lib/context/AgenticaContext.d.ts +2 -2
  9. package/lib/context/MicroAgenticaContext.d.ts +2 -2
  10. package/lib/context/index.d.ts +5 -0
  11. package/lib/{structures/mcp → context}/index.js +5 -1
  12. package/lib/context/index.js.map +1 -0
  13. package/lib/context/internal/AgenticaOperationComposer.spec.js +13 -5
  14. package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
  15. package/lib/events/AgenticaAssistantMessageEvent.d.ts +9 -0
  16. package/lib/events/AgenticaAssistantMessageEvent.js +3 -0
  17. package/lib/events/AgenticaAssistantMessageEvent.js.map +1 -0
  18. package/lib/events/AgenticaEvent.d.ts +9 -9
  19. package/lib/events/AgenticaEvent.type.d.ts +1 -0
  20. package/lib/events/AgenticaEvent.type.js +8 -0
  21. package/lib/events/AgenticaEvent.type.js.map +1 -0
  22. package/lib/events/AgenticaUserMessageEvent.d.ts +9 -0
  23. package/lib/events/{AgenticaUserInputEvent.js → AgenticaUserMessageEvent.js} +1 -1
  24. package/lib/events/AgenticaUserMessageEvent.js.map +1 -0
  25. package/lib/events/MicroAgenticaEvent.d.ts +6 -6
  26. package/lib/events/index.d.ts +14 -0
  27. package/lib/events/index.js +31 -0
  28. package/lib/events/index.js.map +1 -0
  29. package/lib/factory/events.d.ts +8 -8
  30. package/lib/factory/events.js +23 -38
  31. package/lib/factory/events.js.map +1 -1
  32. package/lib/factory/histories.d.ts +1 -36
  33. package/lib/factory/histories.js +103 -22
  34. package/lib/factory/histories.js.map +1 -1
  35. package/lib/functional/assertHttpController.js +6 -6
  36. package/lib/functional/assertHttpLlmApplication.js +6 -6
  37. package/lib/functional/assertMcpController.d.ts +1 -2
  38. package/lib/functional/assertMcpController.js +6 -6
  39. package/lib/functional/assertMcpController.js.map +1 -1
  40. package/lib/functional/index.d.ts +6 -0
  41. package/lib/functional/index.js +23 -0
  42. package/lib/functional/index.js.map +1 -0
  43. package/lib/functional/validateHttpController.js +5 -5
  44. package/lib/functional/validateHttpLlmApplication.js +5 -5
  45. package/lib/functional/validateMcpController.d.ts +1 -2
  46. package/lib/functional/validateMcpController.js +11 -11
  47. package/lib/functional/validateMcpController.js.map +1 -1
  48. package/lib/histories/AgenticaAssistantMessageHistory.d.ts +5 -0
  49. package/lib/histories/AgenticaAssistantMessageHistory.js +3 -0
  50. package/lib/histories/AgenticaAssistantMessageHistory.js.map +1 -0
  51. package/lib/histories/AgenticaHistory.d.ts +9 -7
  52. package/lib/histories/{AgenticaTextHistory.d.ts → AgenticaSystemMessageHistory.d.ts} +1 -2
  53. package/lib/histories/{AgenticaUserInputHistory.js → AgenticaSystemMessageHistory.js} +1 -1
  54. package/lib/histories/AgenticaSystemMessageHistory.js.map +1 -0
  55. package/lib/histories/AgenticaUserMessageHistory.d.ts +6 -0
  56. package/lib/{events/AgenticaTextEvent.js → histories/AgenticaUserMessageHistory.js} +1 -1
  57. package/lib/histories/AgenticaUserMessageHistory.js.map +1 -0
  58. package/lib/histories/MicroAgenticaHistory.d.ts +5 -4
  59. package/lib/histories/contents/AgenticaUserMessageAudioContent.d.ts +19 -0
  60. package/lib/histories/contents/AgenticaUserMessageAudioContent.js +3 -0
  61. package/lib/histories/contents/AgenticaUserMessageAudioContent.js.map +1 -0
  62. package/lib/histories/contents/AgenticaUserMessageContent.d.ts +14 -0
  63. package/lib/histories/{AgenticaTextHistory.js → contents/AgenticaUserMessageContent.js} +1 -1
  64. package/lib/histories/contents/AgenticaUserMessageContent.js.map +1 -0
  65. package/lib/histories/contents/AgenticaUserMessageContentBase.d.ts +6 -0
  66. package/lib/histories/contents/AgenticaUserMessageContentBase.js +3 -0
  67. package/lib/histories/contents/AgenticaUserMessageContentBase.js.map +1 -0
  68. package/lib/histories/contents/AgenticaUserMessageFileContent.d.ts +26 -0
  69. package/lib/histories/contents/AgenticaUserMessageFileContent.js +3 -0
  70. package/lib/histories/contents/AgenticaUserMessageFileContent.js.map +1 -0
  71. package/lib/histories/contents/AgenticaUserMessageImageContent.d.ts +20 -0
  72. package/lib/histories/contents/AgenticaUserMessageImageContent.js +3 -0
  73. package/lib/histories/contents/AgenticaUserMessageImageContent.js.map +1 -0
  74. package/lib/histories/contents/AgenticaUserMessageTextContent.d.ts +14 -0
  75. package/lib/histories/contents/AgenticaUserMessageTextContent.js +3 -0
  76. package/lib/histories/contents/AgenticaUserMessageTextContent.js.map +1 -0
  77. package/lib/histories/contents/index.d.ts +5 -0
  78. package/lib/histories/contents/index.js +22 -0
  79. package/lib/histories/contents/index.js.map +1 -0
  80. package/lib/histories/index.d.ts +10 -0
  81. package/lib/histories/index.js +27 -0
  82. package/lib/histories/index.js.map +1 -0
  83. package/lib/index.d.ts +6 -45
  84. package/lib/index.js +6 -46
  85. package/lib/index.js.map +1 -1
  86. package/lib/index.mjs +182 -131
  87. package/lib/index.mjs.map +1 -1
  88. package/lib/json/IAgenticaEventJson.d.ts +44 -19
  89. package/lib/json/IAgenticaEventJson.type.d.ts +1 -0
  90. package/lib/json/IAgenticaEventJson.type.js +8 -0
  91. package/lib/json/IAgenticaEventJson.type.js.map +1 -0
  92. package/lib/json/IAgenticaHistoryJson.d.ts +34 -19
  93. package/lib/json/IAgenticaHistoryJson.type.d.ts +1 -0
  94. package/lib/json/IAgenticaHistoryJson.type.js +8 -0
  95. package/lib/json/IAgenticaHistoryJson.type.js.map +1 -0
  96. package/lib/json/IMicroAgenticaEventJson.d.ts +1 -1
  97. package/lib/json/IMicroAgenticaHistoryJson.d.ts +1 -1
  98. package/lib/json/index.d.ts +7 -0
  99. package/lib/json/index.js +24 -0
  100. package/lib/json/index.js.map +1 -0
  101. package/lib/orchestrate/call.js +4 -4
  102. package/lib/orchestrate/call.js.map +1 -1
  103. package/lib/orchestrate/cancel.js +1 -1
  104. package/lib/orchestrate/cancel.js.map +1 -1
  105. package/lib/orchestrate/initialize.js +4 -4
  106. package/lib/orchestrate/initialize.js.map +1 -1
  107. package/lib/orchestrate/select.js +3 -3
  108. package/lib/orchestrate/select.js.map +1 -1
  109. package/lib/structures/IAgenticaController.d.ts +1 -2
  110. package/lib/structures/index.d.ts +10 -0
  111. package/lib/structures/index.js +27 -0
  112. package/lib/structures/index.js.map +1 -0
  113. package/lib/transformers/transformHistory.d.ts +1 -0
  114. package/lib/transformers/{AgenticaHistoryTransformer.js → transformHistory.js} +33 -23
  115. package/lib/transformers/transformHistory.js.map +1 -0
  116. package/lib/utils/ChatGptCompletionMessageUtil.js +2 -2
  117. package/lib/utils/types.d.ts +33 -0
  118. package/lib/utils/types.js +29 -0
  119. package/lib/utils/types.js.map +1 -0
  120. package/package.json +7 -7
  121. package/src/Agentica.ts +10 -9
  122. package/src/MicroAgentica.ts +12 -9
  123. package/src/context/AgenticaContext.ts +2 -2
  124. package/src/context/MicroAgenticaContext.ts +2 -2
  125. package/src/context/index.ts +5 -0
  126. package/src/context/internal/AgenticaOperationComposer.spec.ts +15 -5
  127. package/src/events/AgenticaAssistantMessageEvent.ts +12 -0
  128. package/src/events/AgenticaEvent.ts +15 -15
  129. package/src/events/AgenticaEvent.type.ts +19 -0
  130. package/src/events/AgenticaUserMessageEvent.ts +12 -0
  131. package/src/events/MicroAgenticaEvent.ts +9 -9
  132. package/src/events/index.ts +14 -0
  133. package/src/factory/events.ts +29 -34
  134. package/src/factory/histories.ts +120 -29
  135. package/src/functional/assertMcpController.ts +4 -2
  136. package/src/functional/index.ts +7 -0
  137. package/src/functional/validateMcpController.ts +4 -2
  138. package/src/histories/AgenticaAssistantMessageHistory.ts +10 -0
  139. package/src/histories/AgenticaHistory.ts +11 -8
  140. package/src/histories/{AgenticaTextHistory.ts → AgenticaSystemMessageHistory.ts} +4 -2
  141. package/src/histories/AgenticaUserMessageHistory.ts +11 -0
  142. package/src/histories/MicroAgenticaHistory.ts +6 -5
  143. package/src/histories/contents/AgenticaUserMessageAudioContent.ts +21 -0
  144. package/src/histories/contents/AgenticaUserMessageContent.ts +19 -0
  145. package/src/histories/contents/AgenticaUserMessageContentBase.ts +6 -0
  146. package/src/histories/contents/AgenticaUserMessageFileContent.ts +27 -0
  147. package/src/histories/contents/AgenticaUserMessageImageContent.ts +23 -0
  148. package/src/histories/contents/AgenticaUserMessageTextContent.ts +15 -0
  149. package/src/histories/contents/index.ts +5 -0
  150. package/src/histories/index.ts +10 -0
  151. package/src/index.ts +6 -54
  152. package/src/json/IAgenticaEventJson.ts +53 -21
  153. package/src/json/IAgenticaEventJson.type.ts +19 -0
  154. package/src/json/IAgenticaHistoryJson.ts +41 -23
  155. package/src/json/IAgenticaHistoryJson.type.ts +19 -0
  156. package/src/json/IMicroAgenticaEventJson.ts +2 -1
  157. package/src/json/IMicroAgenticaHistoryJson.ts +2 -1
  158. package/src/json/index.ts +7 -0
  159. package/src/orchestrate/call.ts +8 -8
  160. package/src/orchestrate/cancel.ts +2 -2
  161. package/src/orchestrate/initialize.ts +5 -5
  162. package/src/orchestrate/select.ts +5 -5
  163. package/src/structures/IAgenticaController.ts +4 -2
  164. package/src/structures/index.ts +10 -0
  165. package/src/transformers/{AgenticaHistoryTransformer.ts → transformHistory.ts} +43 -26
  166. package/src/utils/types.ts +50 -0
  167. package/lib/events/AgenticaTextEvent.d.ts +0 -10
  168. package/lib/events/AgenticaTextEvent.js.map +0 -1
  169. package/lib/events/AgenticaUserInputEvent.d.ts +0 -10
  170. package/lib/events/AgenticaUserInputEvent.js.map +0 -1
  171. package/lib/histories/AgenticaTextHistory.js.map +0 -1
  172. package/lib/histories/AgenticaUserInputHistory.d.ts +0 -86
  173. package/lib/histories/AgenticaUserInputHistory.js.map +0 -1
  174. package/lib/structures/mcp/IMcpLlmTransportProps.d.ts +0 -11
  175. package/lib/structures/mcp/IMcpLlmTransportProps.js +0 -3
  176. package/lib/structures/mcp/IMcpLlmTransportProps.js.map +0 -1
  177. package/lib/structures/mcp/index.d.ts +0 -1
  178. package/lib/structures/mcp/index.js.map +0 -1
  179. package/lib/transformers/AgenticaEventTransformer.d.ts +0 -63
  180. package/lib/transformers/AgenticaEventTransformer.js +0 -155
  181. package/lib/transformers/AgenticaEventTransformer.js.map +0 -1
  182. package/lib/transformers/AgenticaHistoryTransformer.d.ts +0 -41
  183. package/lib/transformers/AgenticaHistoryTransformer.js.map +0 -1
  184. package/src/events/AgenticaTextEvent.ts +0 -12
  185. package/src/events/AgenticaUserInputEvent.ts +0 -12
  186. package/src/histories/AgenticaUserInputHistory.ts +0 -94
  187. package/src/structures/mcp/IMcpLlmTransportProps.ts +0 -13
  188. package/src/structures/mcp/index.ts +0 -1
  189. package/src/transformers/AgenticaEventTransformer.ts +0 -196
@@ -5,6 +5,7 @@ import { v4 } from "uuid";
5
5
 
6
6
  import type { AgenticaOperation } from "../context/AgenticaOperation";
7
7
  import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
8
+ import type { AgenticaAssistantMessageEvent } from "../events/AgenticaAssistantMessageEvent";
8
9
  import type { AgenticaCallEvent } from "../events/AgenticaCallEvent";
9
10
  import type { AgenticaCancelEvent } from "../events/AgenticaCancelEvent";
10
11
  import type { AgenticaDescribeEvent } from "../events/AgenticaDescribeEvent";
@@ -14,14 +15,13 @@ import type { AgenticaInitializeEvent } from "../events/AgenticaInitializeEvent"
14
15
  import type { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
15
16
  import type { AgenticaResponseEvent } from "../events/AgenticaResponseEvent";
16
17
  import type { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
17
- import type { AgenticaTextEvent } from "../events/AgenticaTextEvent";
18
- import type { AgenticaUserInputEvent } from "../events/AgenticaUserInputEvent";
18
+ import type { AgenticaUserMessageEvent } from "../events/AgenticaUserMessageEvent";
19
19
  import type { AgenticaValidateEvent } from "../events/AgenticaValidateEvent";
20
+ import type { AgenticaUserMessageContent } from "../histories";
20
21
  import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
21
- import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
22
22
  import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
23
23
 
24
- import { createExecuteHistory, createSelectHistory, createUserInputHistory } from "./histories";
24
+ import { createExecuteHistory, createSelectHistory, createUserMessageHistory } from "./histories";
25
25
 
26
26
  /* -----------------------------------------------------------
27
27
  FUNCTION SELECTS
@@ -36,23 +36,6 @@ export function createInitializeEvent(): AgenticaInitializeEvent {
36
36
  };
37
37
  }
38
38
 
39
- export function createUserInputEvent(props: {
40
- contents: Array<AgenticaUserInputHistory.Contents>;
41
- }): AgenticaUserInputEvent {
42
- return {
43
- type: "user_input",
44
- role: "user",
45
- contents: props.contents,
46
- join: async () => props.contents,
47
- toJSON: () => ({
48
- type: "user_input",
49
- contents: props.contents,
50
- }),
51
- toHistory: () => createUserInputHistory({
52
- contents: props.contents,
53
- }),
54
- };
55
- }
56
39
  export function createSelectEvent<Model extends ILlmSchema.Model>(props: {
57
40
  selection: AgenticaOperationSelection<Model>;
58
41
  }): AgenticaSelectEvent<Model> {
@@ -151,32 +134,44 @@ export function createExecuteEvent<Model extends ILlmSchema.Model>(props: {
151
134
  }
152
135
 
153
136
  /* -----------------------------------------------------------
154
- TEXT STEAMING
137
+ CONTENTS
155
138
  ----------------------------------------------------------- */
156
- export function createTextEvent(props: {
139
+ export function createUserMessageEvent(props: {
140
+ contents: Array<AgenticaUserMessageContent>;
141
+ }): AgenticaUserMessageEvent {
142
+ return {
143
+ type: "userMessage",
144
+ contents: props.contents,
145
+ toJSON: () => ({
146
+ type: "userMessage",
147
+ contents: props.contents,
148
+ }),
149
+ toHistory: () => createUserMessageHistory({
150
+ contents: props.contents,
151
+ }),
152
+ };
153
+ }
154
+
155
+ export function creatAssistantEvent(props: {
157
156
  stream: AsyncGenerator<string, undefined, undefined>;
158
157
  done: () => boolean;
159
158
  get: () => string;
160
159
  join: () => Promise<string>;
161
- }): AgenticaTextEvent {
160
+ }): AgenticaAssistantMessageEvent {
162
161
  return {
163
- type: "text",
164
- role: "assistant",
162
+ type: "assistantMessage",
165
163
  stream: props.stream,
166
164
  join: props.join,
167
165
  toJSON: () => ({
168
- type: "text",
169
- role: "assistant",
166
+ type: "assistantMessage",
170
167
  done: props.done(),
171
168
  text: props.get(),
172
169
  }),
173
170
  toHistory: () => ({
174
- type: "text",
175
- role: "assistant",
171
+ type: "assistantMessage",
176
172
  text: props.get(),
177
173
  toJSON: () => ({
178
- type: "text",
179
- role: "assistant",
174
+ type: "assistantMessage",
180
175
  text: props.get(),
181
176
  }),
182
177
  }),
@@ -215,8 +210,8 @@ export function createDescribeEvent<Model extends ILlmSchema.Model>(props: {
215
210
  }
216
211
 
217
212
  /* -----------------------------------------------------------
218
- API REQUESTS
219
- ----------------------------------------------------------- */
213
+ API REQUESTS
214
+ ----------------------------------------------------------- */
220
215
  export function createRequestEvent(props: {
221
216
  source: AgenticaEventSource;
222
217
  body: OpenAI.ChatCompletionCreateParamsStreaming;
@@ -3,31 +3,26 @@ import type OpenAI from "openai";
3
3
 
4
4
  import type { AgenticaOperation } from "../context/AgenticaOperation";
5
5
  import type { AgenticaOperationSelection } from "../context/AgenticaOperationSelection";
6
+ import type { AgenticaUserMessageContent } from "../histories";
7
+ import type { AgenticaAssistantMessageHistory } from "../histories/AgenticaAssistantMessageHistory";
6
8
  import type { AgenticaCancelHistory } from "../histories/AgenticaCancelHistory";
7
9
  import type { AgenticaDescribeHistory } from "../histories/AgenticaDescribeHistory";
8
10
  import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
9
11
  import type { AgenticaHistory } from "../histories/AgenticaHistory";
10
12
  import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
11
- import type { AgenticaTextHistory } from "../histories/AgenticaTextHistory";
12
- import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
13
+ import type { AgenticaSystemMessageHistory } from "../histories/AgenticaSystemMessageHistory";
14
+ import type { AgenticaUserMessageHistory } from "../histories/AgenticaUserMessageHistory";
13
15
  import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
14
16
 
17
+ /**
18
+ * @internal
19
+ */
15
20
  export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaHistory<Model>): OpenAI.ChatCompletionMessageParam[] {
16
21
  // NO NEED TO DECODE DESCRIBE
17
22
  if (history.type === "describe") {
18
23
  return [];
19
24
  }
20
-
21
- if (history.type === "text") {
22
- return [
23
- {
24
- role: history.role,
25
- content: history.text,
26
- },
27
- ];
28
- }
29
-
30
- if (history.type === "select" || history.type === "cancel") {
25
+ else if (history.type === "select" || history.type === "cancel") {
31
26
  return [
32
27
  {
33
28
  role: "assistant",
@@ -54,8 +49,7 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
54
49
  },
55
50
  ];
56
51
  }
57
-
58
- if (history.type === "execute") {
52
+ else if (history.type === "execute") {
59
53
  return [
60
54
  {
61
55
  role: "assistant",
@@ -99,31 +93,98 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
99
93
  ];
100
94
  }
101
95
 
102
- if (history.type === "user_input") {
96
+ if (history.type === "assistantMessage") {
97
+ return [
98
+ {
99
+ role: "assistant",
100
+ content: history.text,
101
+ },
102
+ ];
103
+ }
104
+
105
+ if (history.type === "systemMessage") {
106
+ return [
107
+ {
108
+ role: "system",
109
+ content: history.text,
110
+ },
111
+ ];
112
+ }
113
+
114
+ if (history.type === "userMessage") {
115
+ const contents = history.contents;
103
116
  return [
104
117
  {
105
118
  role: "user",
106
- content: history.contents,
119
+ content: contents.map(decodeUserMessageContent),
107
120
  },
108
121
  ];
109
122
  }
110
123
 
111
124
  history satisfies never;
112
- throw new Error("Invalid history type");
125
+ throw new Error(`Unsupported history type, value: ${JSON.stringify(history)}`);
126
+ }
127
+
128
+ /**
129
+ * @internal
130
+ */
131
+ export function decodeUserMessageContent(content: AgenticaUserMessageContent): OpenAI.ChatCompletionContentPart {
132
+ if (content.type === "text") {
133
+ return content;
134
+ }
135
+
136
+ if (content.type === "audio") {
137
+ return {
138
+ type: "input_audio",
139
+ input_audio: {
140
+ data: content.data,
141
+ format: content.format,
142
+ },
143
+ };
144
+ }
145
+
146
+ if (content.type === "file") {
147
+ return {
148
+ type: "file",
149
+ file: content.file.type === "data"
150
+ ? {
151
+ file_data: content.file.data,
152
+ filename: content.file.name,
153
+ }
154
+ : {
155
+ file_id: content.file.id,
156
+ },
157
+ };
158
+ }
159
+
160
+ if (content.type === "image") {
161
+ return {
162
+ type: "image_url",
163
+ image_url: {
164
+ url: content.url,
165
+ detail: content.detail,
166
+ },
167
+ };
168
+ }
169
+
170
+ content satisfies never;
171
+ throw new Error(`Unsupported user message content type, value: ${JSON.stringify(content)}`);
113
172
  }
114
173
 
115
174
  /* -----------------------------------------------------------
116
175
  USER INPUT PROMPTS
117
176
  ----------------------------------------------------------- */
118
- export function createUserInputHistory(props: {
119
- contents: Array<AgenticaUserInputHistory.Contents>;
120
- }): AgenticaUserInputHistory {
177
+ /**
178
+ * @internal
179
+ */
180
+ export function createUserMessageHistory(props: {
181
+ contents: Array<AgenticaUserMessageContent>;
182
+ }): AgenticaUserMessageHistory {
121
183
  return {
122
- type: "user_input",
123
- role: "user",
184
+ type: "userMessage",
124
185
  contents: props.contents,
125
186
  toJSON: () => ({
126
- type: "user_input",
187
+ type: "userMessage",
127
188
  contents: props.contents,
128
189
  }),
129
190
  };
@@ -132,12 +193,30 @@ export function createUserInputHistory(props: {
132
193
  /* -----------------------------------------------------------
133
194
  TEXT PROMPTS
134
195
  ----------------------------------------------------------- */
135
- export function createTextHistory(props: {
196
+ /**
197
+ * @internal
198
+ */
199
+ export function createAssistantMessageHistory(props: {
200
+ text: string;
201
+ }): AgenticaAssistantMessageHistory {
202
+ const prompt: IAgenticaHistoryJson.IAssistantMessage = {
203
+ type: "assistantMessage",
204
+ text: props.text,
205
+ };
206
+ return {
207
+ ...prompt,
208
+ toJSON: () => prompt,
209
+ };
210
+ }
211
+
212
+ /**
213
+ * @internal
214
+ */
215
+ export function createSystemMessageHistory(props: {
136
216
  text: string;
137
- }): AgenticaTextHistory {
138
- const prompt: IAgenticaHistoryJson.IText = {
139
- type: "text",
140
- role: "assistant",
217
+ }): AgenticaSystemMessageHistory {
218
+ const prompt: IAgenticaHistoryJson.ISystemMessage = {
219
+ type: "systemMessage",
141
220
  text: props.text,
142
221
  };
143
222
  return {
@@ -146,6 +225,9 @@ export function createTextHistory(props: {
146
225
  };
147
226
  }
148
227
 
228
+ /**
229
+ * @internal
230
+ */
149
231
  export function createDescribeHistory<Model extends ILlmSchema.Model>(props: {
150
232
  executes: AgenticaExecuteHistory<Model>[];
151
233
  text: string;
@@ -165,6 +247,9 @@ export function createDescribeHistory<Model extends ILlmSchema.Model>(props: {
165
247
  /* -----------------------------------------------------------
166
248
  FUNCTION CALLING PROMPTS
167
249
  ----------------------------------------------------------- */
250
+ /**
251
+ * @internal
252
+ */
168
253
  export function createSelectHistory<Model extends ILlmSchema.Model>(props: {
169
254
  id: string;
170
255
  selections: AgenticaOperationSelection<Model>[];
@@ -181,6 +266,9 @@ export function createSelectHistory<Model extends ILlmSchema.Model>(props: {
181
266
  };
182
267
  }
183
268
 
269
+ /**
270
+ * @internal
271
+ */
184
272
  export function createCancelHistory<Model extends ILlmSchema.Model>(props: {
185
273
  id: string;
186
274
  selections: AgenticaOperationSelection<Model>[];
@@ -197,6 +285,9 @@ export function createCancelHistory<Model extends ILlmSchema.Model>(props: {
197
285
  };
198
286
  }
199
287
 
288
+ /**
289
+ * @internal
290
+ */
200
291
  export function createExecuteHistory<
201
292
  Model extends ILlmSchema.Model,
202
293
  >(props: {
@@ -1,4 +1,3 @@
1
- import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
1
  import type { ILlmSchema, IMcpLlmApplication, IMcpTool } from "@samchon/openapi";
3
2
 
4
3
  import { McpLlm } from "@samchon/openapi";
@@ -23,8 +22,11 @@ import type { IAgenticaController } from "../structures/IAgenticaController";
23
22
  */
24
23
  export async function assertMcpController<Model extends ILlmSchema.Model>(props: {
25
24
  name: string;
26
- client: Client;
27
25
  model: Model;
26
+ // @ts-ignore Type checking only when `@modelcontextprotocol/sdk` is installed.
27
+ // This strategy is useful for someone who does not need MCP,
28
+ // for someone who has not installed `@modelcontextprotocol/sdk`.
29
+ client: import("@modelcontextprotocol/sdk/client/index.d.ts").Client;
28
30
  options?: Partial<IMcpLlmApplication.IOptions<Model>>;
29
31
  }): Promise<IAgenticaController.IMcp<Model>> {
30
32
  // for peerDependencies
@@ -0,0 +1,7 @@
1
+ export * from "./assertHttpController";
2
+ export * from "./assertHttpLlmApplication"; // deprecated
3
+ export * from "./assertMcpController";
4
+ export * from "./validateHttpController"; // deprecated
5
+
6
+ export * from "./validateHttpLlmApplication";
7
+ export * from "./validateMcpController";
@@ -1,4 +1,3 @@
1
- import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
1
  import type { ILlmSchema, IMcpLlmApplication, IMcpTool, IValidation } from "@samchon/openapi";
3
2
 
4
3
  import { McpLlm } from "@samchon/openapi";
@@ -25,7 +24,10 @@ export async function validateMcpController<
25
24
  Model extends ILlmSchema.Model,
26
25
  >(props: {
27
26
  name: string;
28
- client: Client;
27
+ // @ts-ignore Type checking only when `@modelcontextprotocol/sdk` is installed.
28
+ // This strategy is useful for someone who does not need MCP,
29
+ // for someone who has not installed `@modelcontextprotocol/sdk`.
30
+ client: import("@modelcontextprotocol/sdk/client/index.d.ts").Client;
29
31
  model: Model;
30
32
  options?: Partial<IMcpLlmApplication.IOptions<Model>>;
31
33
  }): Promise<IValidation<IAgenticaController.IMcp<Model>>> {
@@ -0,0 +1,10 @@
1
+ import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
2
+
3
+ import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
4
+
5
+ export interface AgenticaAssistantMessageHistory extends AgenticaHistoryBase<
6
+ "assistantMessage",
7
+ IAgenticaHistoryJson.IAssistantMessage
8
+ > {
9
+ text: string;
10
+ }
@@ -1,27 +1,30 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
+ import type { AgenticaAssistantMessageHistory } from "./AgenticaAssistantMessageHistory";
3
4
  import type { AgenticaCancelHistory } from "./AgenticaCancelHistory";
4
5
  import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
5
6
  import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
6
7
  import type { AgenticaSelectHistory } from "./AgenticaSelectHistory";
7
- import type { AgenticaTextHistory } from "./AgenticaTextHistory";
8
- import type { AgenticaUserInputHistory } from "./AgenticaUserInputHistory";
8
+ import type { AgenticaSystemMessageHistory } from "./AgenticaSystemMessageHistory";
9
+ import type { AgenticaUserMessageHistory } from "./AgenticaUserMessageHistory";
9
10
 
10
11
  export type AgenticaHistory<Model extends ILlmSchema.Model> =
11
12
  | AgenticaCancelHistory<Model>
12
13
  | AgenticaDescribeHistory<Model>
13
14
  | AgenticaExecuteHistory<Model>
14
15
  | AgenticaSelectHistory<Model>
15
- | AgenticaTextHistory
16
- | AgenticaUserInputHistory;
16
+ | AgenticaAssistantMessageHistory
17
+ | AgenticaUserMessageHistory
18
+ | AgenticaSystemMessageHistory;
17
19
  export namespace AgenticaHistory {
18
20
  export type Type = AgenticaHistory<any>["type"];
19
21
  export interface Mapper<Model extends ILlmSchema.Model> {
22
+ select: AgenticaSelectHistory<Model>;
20
23
  cancel: AgenticaCancelHistory<Model>;
21
- describe: AgenticaDescribeHistory<Model>;
22
24
  execute: AgenticaExecuteHistory<Model>;
23
- select: AgenticaSelectHistory<Model>;
24
- text: AgenticaTextHistory;
25
- user_input: AgenticaUserInputHistory;
25
+ describe: AgenticaDescribeHistory<Model>;
26
+ assistantMessage: AgenticaAssistantMessageHistory;
27
+ systemMessage: AgenticaSystemMessageHistory;
28
+ userMessage: AgenticaUserMessageHistory;
26
29
  }
27
30
  }
@@ -2,7 +2,9 @@ import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
2
2
 
3
3
  import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
4
4
 
5
- export interface AgenticaTextHistory extends AgenticaHistoryBase<"text", IAgenticaHistoryJson.IText> {
6
- role: "assistant";
5
+ export interface AgenticaSystemMessageHistory extends AgenticaHistoryBase<
6
+ "systemMessage",
7
+ IAgenticaHistoryJson.ISystemMessage
8
+ > {
7
9
  text: string;
8
10
  }
@@ -0,0 +1,11 @@
1
+ import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
2
+
3
+ import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
4
+ import type { AgenticaUserMessageContent } from "./contents/AgenticaUserMessageContent";
5
+
6
+ export interface AgenticaUserMessageHistory extends AgenticaHistoryBase<
7
+ "userMessage",
8
+ IAgenticaHistoryJson.IUserMessage
9
+ > {
10
+ contents: AgenticaUserMessageContent[];
11
+ }
@@ -1,20 +1,21 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
+ import type { AgenticaAssistantMessageHistory } from "./AgenticaAssistantMessageHistory";
3
4
  import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
4
5
  import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
5
- import type { AgenticaTextHistory } from "./AgenticaTextHistory";
6
- import type { AgenticaUserInputHistory } from "./AgenticaUserInputHistory";
6
+ import type { AgenticaUserMessageHistory } from "./AgenticaUserMessageHistory";
7
7
 
8
8
  export type MicroAgenticaHistory<Model extends ILlmSchema.Model> =
9
9
  | AgenticaDescribeHistory<Model>
10
10
  | AgenticaExecuteHistory<Model>
11
- | AgenticaTextHistory
12
- | AgenticaUserInputHistory;
11
+ | AgenticaAssistantMessageHistory
12
+ | AgenticaUserMessageHistory;
13
13
  export namespace MicroAgenticaHistory {
14
14
  export type Type = MicroAgenticaHistory<any>["type"];
15
15
  export interface Mapper<Model extends ILlmSchema.Model> {
16
16
  describe: AgenticaDescribeHistory<Model>;
17
17
  execute: AgenticaExecuteHistory<Model>;
18
- text: AgenticaTextHistory;
18
+ userMessage: AgenticaUserMessageHistory;
19
+ assistantMessage: AgenticaAssistantMessageHistory;
19
20
  }
20
21
  }
@@ -0,0 +1,21 @@
1
+ import type { AgenticaUserMessageContentBase } from "./AgenticaUserMessageContentBase";
2
+
3
+ /**
4
+ * Audio content by user.
5
+ *
6
+ * @reference https://platform.openai.com/docs/guides/audio
7
+ * @warning We not recommend it because audio data only support base64
8
+ * so it's too big data
9
+ * @author SunRabbit
10
+ */
11
+ export interface AgenticaUserMessageAudioContent extends AgenticaUserMessageContentBase<"audio"> {
12
+ /**
13
+ * Base64 encoded audio data.
14
+ */
15
+ data: string;
16
+
17
+ /**
18
+ * The format of the encoded audio data. Currently supports "wav" and "mp3".
19
+ */
20
+ format: "wav" | "mp3";
21
+ }
@@ -0,0 +1,19 @@
1
+ import type { AgenticaUserMessageAudioContent } from "./AgenticaUserMessageAudioContent";
2
+ import type { AgenticaUserMessageFileContent } from "./AgenticaUserMessageFileContent";
3
+ import type { AgenticaUserMessageImageContent } from "./AgenticaUserMessageImageContent";
4
+ import type { AgenticaUserMessageTextContent } from "./AgenticaUserMessageTextContent";
5
+
6
+ export type AgenticaUserMessageContent =
7
+ | AgenticaUserMessageAudioContent
8
+ | AgenticaUserMessageFileContent
9
+ | AgenticaUserMessageImageContent
10
+ | AgenticaUserMessageTextContent;
11
+ export namespace AgenticaUserMessageContent {
12
+ export type Type = AgenticaUserMessageContent["type"];
13
+ export interface Mapper {
14
+ audio: AgenticaUserMessageAudioContent;
15
+ file: AgenticaUserMessageFileContent;
16
+ image: AgenticaUserMessageImageContent;
17
+ text: AgenticaUserMessageTextContent;
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ export interface AgenticaUserMessageContentBase<Type extends string> {
2
+ /**
3
+ * Discriminator for the type of content.
4
+ */
5
+ type: Type;
6
+ }
@@ -0,0 +1,27 @@
1
+ import type { AgenticaUserMessageContentBase } from "./AgenticaUserMessageContentBase";
2
+
3
+ /**
4
+ * File content by user.
5
+ *
6
+ * @reference https://platform.openai.com/docs/api-reference/uploads/create
7
+ * @author SunRabbit
8
+ */
9
+ export interface AgenticaUserMessageFileContent extends AgenticaUserMessageContentBase<"file"> {
10
+ /**
11
+ * Reference to the pre-uploaded file or the data itself.
12
+ *
13
+ * @todo Properly define independent interface
14
+ */
15
+ file: AgenticaUserMessageFileContent.IReference | AgenticaUserMessageFileContent.IData;
16
+ }
17
+ export namespace AgenticaUserMessageFileContent {
18
+ export interface IReference {
19
+ type: "reference";
20
+ id: string;
21
+ }
22
+ export interface IData {
23
+ type: "data";
24
+ name: string;
25
+ data: string;
26
+ }
27
+ }
@@ -0,0 +1,23 @@
1
+ import type { tags } from "typia";
2
+
3
+ import type { AgenticaUserMessageContentBase } from "./AgenticaUserMessageContentBase";
4
+
5
+ /**
6
+ * Image content by user.
7
+ *
8
+ * @reference https://platform.openai.com/docs/guides/vision
9
+ * @author SunRabbit
10
+ */
11
+ export interface AgenticaUserMessageImageContent extends AgenticaUserMessageContentBase<"image"> {
12
+ /**
13
+ * Image URL.
14
+ */
15
+ url: string & tags.Format<"url">;
16
+
17
+ /**
18
+ * Specifies the detail level of the image.
19
+ *
20
+ * @reference https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding
21
+ */
22
+ detail?: "auto" | "high" | "low" | undefined;
23
+ }
@@ -0,0 +1,15 @@
1
+ import type { AgenticaUserMessageContentBase } from "./AgenticaUserMessageContentBase";
2
+
3
+ /**
4
+ * Text content by user.
5
+ *
6
+ * @reference https://platform.openai.com/docs/guides/text-generation
7
+ * @author Samchon
8
+ * @author SunRabbit
9
+ */
10
+ export interface AgenticaUserMessageTextContent extends AgenticaUserMessageContentBase<"text"> {
11
+ /**
12
+ * The text content.
13
+ */
14
+ text: string;
15
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./AgenticaUserMessageAudioContent";
2
+ export * from "./AgenticaUserMessageContent";
3
+ export * from "./AgenticaUserMessageFileContent";
4
+ export * from "./AgenticaUserMessageImageContent";
5
+ export * from "./AgenticaUserMessageTextContent";
@@ -0,0 +1,10 @@
1
+ export * from "./AgenticaAssistantMessageHistory";
2
+ export * from "./AgenticaCancelHistory";
3
+ export * from "./AgenticaDescribeHistory";
4
+ export * from "./AgenticaExecuteHistory";
5
+ export * from "./AgenticaHistory";
6
+ export * from "./AgenticaSelectHistory";
7
+ export * from "./AgenticaSystemMessageHistory";
8
+ export * from "./AgenticaUserMessageHistory";
9
+ export * from "./contents";
10
+ export * from "./MicroAgenticaHistory";