@agentica/core 0.21.0 → 0.23.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 (91) hide show
  1. package/README.md +10 -11
  2. package/lib/Agentica.d.ts +2 -1
  3. package/lib/Agentica.js +15 -13
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/MicroAgentica.d.ts +12 -1
  6. package/lib/MicroAgentica.js +23 -10
  7. package/lib/MicroAgentica.js.map +1 -1
  8. package/lib/context/AgenticaContext.d.ts +4 -4
  9. package/lib/context/MicroAgenticaContext.d.ts +2 -2
  10. package/lib/events/AgenticaEvent.d.ts +3 -1
  11. package/lib/events/AgenticaTextEvent.d.ts +2 -2
  12. package/lib/events/AgenticaUserInputEvent.d.ts +10 -0
  13. package/lib/events/AgenticaUserInputEvent.js +3 -0
  14. package/lib/events/AgenticaUserInputEvent.js.map +1 -0
  15. package/lib/events/MicroAgenticaEvent.d.ts +3 -1
  16. package/lib/factory/events.d.ts +7 -3
  17. package/lib/factory/events.js +29 -4
  18. package/lib/factory/events.js.map +1 -1
  19. package/lib/factory/histories.d.ts +6 -3
  20. package/lib/factory/histories.js +59 -32
  21. package/lib/factory/histories.js.map +1 -1
  22. package/lib/functional/assertHttpController.d.ts +75 -0
  23. package/lib/functional/assertHttpController.js +9622 -0
  24. package/lib/functional/assertHttpController.js.map +1 -0
  25. package/lib/functional/assertHttpLlmApplication.d.ts +1 -0
  26. package/lib/functional/assertHttpLlmApplication.js +1 -0
  27. package/lib/functional/assertHttpLlmApplication.js.map +1 -1
  28. package/lib/functional/assertMcpController.d.ts +1 -1
  29. package/lib/functional/assertMcpController.js +1 -1
  30. package/lib/functional/assertMcpController.js.map +1 -1
  31. package/lib/functional/validateHttpController.d.ts +75 -0
  32. package/lib/functional/validateHttpController.js +7952 -0
  33. package/lib/functional/validateHttpController.js.map +1 -0
  34. package/lib/functional/validateHttpLlmApplication.d.ts +1 -0
  35. package/lib/functional/validateHttpLlmApplication.js +1 -0
  36. package/lib/functional/validateHttpLlmApplication.js.map +1 -1
  37. package/lib/functional/validateMcpController.d.ts +24 -0
  38. package/lib/functional/validateMcpController.js +3034 -0
  39. package/lib/functional/validateMcpController.js.map +1 -0
  40. package/lib/histories/AgenticaHistory.d.ts +3 -1
  41. package/lib/histories/AgenticaTextHistory.d.ts +2 -2
  42. package/lib/histories/AgenticaUserInputHistory.d.ts +80 -0
  43. package/lib/histories/AgenticaUserInputHistory.js +3 -0
  44. package/lib/histories/AgenticaUserInputHistory.js.map +1 -0
  45. package/lib/histories/MicroAgenticaHistory.d.ts +2 -1
  46. package/lib/index.d.ts +3 -0
  47. package/lib/index.js +3 -0
  48. package/lib/index.js.map +1 -1
  49. package/lib/index.mjs +25984 -5962
  50. package/lib/index.mjs.map +1 -1
  51. package/lib/json/IAgenticaEventJson.d.ts +8 -1
  52. package/lib/json/IAgenticaHistoryJson.d.ts +15 -3
  53. package/lib/orchestrate/call.js +3 -7
  54. package/lib/orchestrate/call.js.map +1 -1
  55. package/lib/orchestrate/cancel.js +1 -1
  56. package/lib/orchestrate/cancel.js.map +1 -1
  57. package/lib/orchestrate/initialize.js +2 -6
  58. package/lib/orchestrate/initialize.js.map +1 -1
  59. package/lib/orchestrate/select.js +2 -6
  60. package/lib/orchestrate/select.js.map +1 -1
  61. package/lib/transformers/AgenticaEventTransformer.js +0 -1
  62. package/lib/transformers/AgenticaEventTransformer.js.map +1 -1
  63. package/package.json +2 -2
  64. package/src/Agentica.ts +21 -18
  65. package/src/MicroAgentica.ts +30 -15
  66. package/src/context/AgenticaContext.ts +4 -4
  67. package/src/context/MicroAgenticaContext.ts +2 -2
  68. package/src/events/AgenticaEvent.ts +4 -1
  69. package/src/events/AgenticaTextEvent.ts +2 -4
  70. package/src/events/AgenticaUserInputEvent.ts +12 -0
  71. package/src/events/MicroAgenticaEvent.ts +4 -1
  72. package/src/factory/events.ts +26 -8
  73. package/src/factory/histories.ts +76 -43
  74. package/src/functional/assertHttpController.ts +112 -0
  75. package/src/functional/assertHttpLlmApplication.ts +1 -0
  76. package/src/functional/assertMcpController.ts +1 -2
  77. package/src/functional/validateHttpController.ts +118 -0
  78. package/src/functional/validateHttpLlmApplication.ts +1 -1
  79. package/src/functional/validateMcpController.ts +56 -0
  80. package/src/histories/AgenticaHistory.ts +4 -1
  81. package/src/histories/AgenticaTextHistory.ts +2 -4
  82. package/src/histories/AgenticaUserInputHistory.ts +88 -0
  83. package/src/histories/MicroAgenticaHistory.ts +3 -1
  84. package/src/index.ts +3 -0
  85. package/src/json/IAgenticaEventJson.ts +9 -1
  86. package/src/json/IAgenticaHistoryJson.ts +16 -4
  87. package/src/orchestrate/call.ts +5 -7
  88. package/src/orchestrate/cancel.ts +1 -1
  89. package/src/orchestrate/initialize.ts +2 -6
  90. package/src/orchestrate/select.ts +2 -7
  91. package/src/transformers/AgenticaEventTransformer.ts +0 -1
@@ -15,11 +15,13 @@ import type { AgenticaRequestEvent } from "../events/AgenticaRequestEvent";
15
15
  import type { AgenticaResponseEvent } from "../events/AgenticaResponseEvent";
16
16
  import type { AgenticaSelectEvent } from "../events/AgenticaSelectEvent";
17
17
  import type { AgenticaTextEvent } from "../events/AgenticaTextEvent";
18
+ import type { AgenticaUserInputEvent } from "../events/AgenticaUserInputEvent";
18
19
  import type { AgenticaValidateEvent } from "../events/AgenticaValidateEvent";
19
20
  import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory";
21
+ import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
20
22
  import type { IAgenticaEventJson } from "../json/IAgenticaEventJson";
21
23
 
22
- import { createExecuteHistory, createSelectHistory } from "./histories";
24
+ import { createExecuteHistory, createSelectHistory, createUserInputHistory } from "./histories";
23
25
 
24
26
  /* -----------------------------------------------------------
25
27
  FUNCTION SELECTS
@@ -34,6 +36,23 @@ export function createInitializeEvent(): AgenticaInitializeEvent {
34
36
  };
35
37
  }
36
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
+ }
37
56
  export function createSelectEvent<Model extends ILlmSchema.Model>(props: {
38
57
  selection: AgenticaOperationSelection<Model>;
39
58
  }): AgenticaSelectEvent<Model> {
@@ -134,31 +153,30 @@ export function createExecuteEvent<Model extends ILlmSchema.Model>(props: {
134
153
  /* -----------------------------------------------------------
135
154
  TEXT STEAMING
136
155
  ----------------------------------------------------------- */
137
- export function createTextEvent<Role extends "user" | "assistant">(props: {
138
- role: Role;
156
+ export function createTextEvent(props: {
139
157
  stream: AsyncGenerator<string, undefined, undefined>;
140
158
  done: () => boolean;
141
159
  get: () => string;
142
160
  join: () => Promise<string>;
143
- }): AgenticaTextEvent<Role> {
161
+ }): AgenticaTextEvent {
144
162
  return {
145
163
  type: "text",
146
- role: props.role,
164
+ role: "assistant",
147
165
  stream: props.stream,
148
166
  join: props.join,
149
167
  toJSON: () => ({
150
168
  type: "text",
151
- role: props.role,
169
+ role: "assistant",
152
170
  done: props.done(),
153
171
  text: props.get(),
154
172
  }),
155
173
  toHistory: () => ({
156
174
  type: "text",
157
- role: props.role,
175
+ role: "assistant",
158
176
  text: props.get(),
159
177
  toJSON: () => ({
160
178
  type: "text",
161
- role: props.role,
179
+ role: "assistant",
162
180
  text: props.get(),
163
181
  }),
164
182
  }),
@@ -9,6 +9,7 @@ import type { AgenticaExecuteHistory } from "../histories/AgenticaExecuteHistory
9
9
  import type { AgenticaHistory } from "../histories/AgenticaHistory";
10
10
  import type { AgenticaSelectHistory } from "../histories/AgenticaSelectHistory";
11
11
  import type { AgenticaTextHistory } from "../histories/AgenticaTextHistory";
12
+ import type { AgenticaUserInputHistory } from "../histories/AgenticaUserInputHistory";
12
13
  import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
13
14
 
14
15
  export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaHistory<Model>): OpenAI.ChatCompletionMessageParam[] {
@@ -16,7 +17,8 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
16
17
  if (history.type === "describe") {
17
18
  return [];
18
19
  }
19
- else if (history.type === "text") {
20
+
21
+ if (history.type === "text") {
20
22
  return [
21
23
  {
22
24
  role: history.role,
@@ -24,7 +26,8 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
24
26
  },
25
27
  ];
26
28
  }
27
- else if (history.type === "select" || history.type === "cancel") {
29
+
30
+ if (history.type === "select" || history.type === "cancel") {
28
31
  return [
29
32
  {
30
33
  role: "assistant",
@@ -52,59 +55,89 @@ export function decodeHistory<Model extends ILlmSchema.Model>(history: AgenticaH
52
55
  ];
53
56
  }
54
57
 
55
- return [
56
- {
57
- role: "assistant",
58
- tool_calls: [
59
- {
60
- type: "function",
61
- id: history.id,
58
+ if (history.type === "execute") {
59
+ return [
60
+ {
61
+ role: "assistant",
62
+ tool_calls: [
63
+ {
64
+ type: "function",
65
+ id: history.id,
66
+ function: {
67
+ name: history.operation.name,
68
+ arguments: JSON.stringify(history.arguments),
69
+ },
70
+ },
71
+ ],
72
+ },
73
+ {
74
+ role: "tool",
75
+ tool_call_id: history.id,
76
+ content: JSON.stringify({
62
77
  function: {
63
- name: history.operation.name,
64
- arguments: JSON.stringify(history.arguments),
78
+ protocol: history.operation.protocol,
79
+ description: history.operation.function.description,
80
+ parameters: history.operation.function.parameters,
81
+ output: history.operation.function.output,
82
+ ...(history.operation.protocol === "http"
83
+ ? {
84
+ method: history.operation.function.method,
85
+ path: history.operation.function.path,
86
+ }
87
+ : {}),
65
88
  },
66
- },
67
- ],
68
- },
69
- {
70
- role: "tool",
71
- tool_call_id: history.id,
72
- content: JSON.stringify({
73
- function: {
74
- protocol: history.operation.protocol,
75
- description: history.operation.function.description,
76
- parameters: history.operation.function.parameters,
77
- output: history.operation.function.output,
78
89
  ...(history.operation.protocol === "http"
79
90
  ? {
80
- method: history.operation.function.method,
81
- path: history.operation.function.path,
91
+ status: (history.value as IHttpResponse).status,
92
+ data: (history.value as IHttpResponse).body,
82
93
  }
83
- : {}),
84
- },
85
- ...(history.operation.protocol === "http"
86
- ? {
87
- status: (history.value as IHttpResponse).status,
88
- data: (history.value as IHttpResponse).body,
89
- }
90
- : {
91
- value: history.value,
92
- }),
93
- }),
94
- },
95
- ];
94
+ : {
95
+ value: history.value,
96
+ }),
97
+ }),
98
+ },
99
+ ];
100
+ }
101
+
102
+ if (history.type === "user_input") {
103
+ return [
104
+ {
105
+ role: "user",
106
+ content: history.contents,
107
+ },
108
+ ];
109
+ }
110
+
111
+ history satisfies never;
112
+ throw new Error("Invalid history type");
113
+ }
114
+
115
+ /* -----------------------------------------------------------
116
+ USER INPUT PROMPTS
117
+ ----------------------------------------------------------- */
118
+ export function createUserInputHistory(props: {
119
+ contents: Array<AgenticaUserInputHistory.Contents>;
120
+ }): AgenticaUserInputHistory {
121
+ return {
122
+ type: "user_input",
123
+ role: "user",
124
+ contents: props.contents,
125
+ toJSON: () => ({
126
+ type: "user_input",
127
+ contents: props.contents,
128
+ }),
129
+ };
96
130
  }
97
131
 
98
132
  /* -----------------------------------------------------------
99
133
  TEXT PROMPTS
100
134
  ----------------------------------------------------------- */
101
- export function createTextHistory<Role extends "assistant" | "user" = "assistant" | "user">(props: {
102
- role: Role;
135
+ export function createTextHistory(props: {
103
136
  text: string;
104
- }): AgenticaTextHistory<Role> {
105
- const prompt: IAgenticaHistoryJson.IText<Role> = {
137
+ }): AgenticaTextHistory {
138
+ const prompt: IAgenticaHistoryJson.IText = {
106
139
  type: "text",
107
- role: props.role,
140
+ role: "assistant",
108
141
  text: props.text,
109
142
  };
110
143
  return {
@@ -0,0 +1,112 @@
1
+ import type { IHttpConnection, IHttpLlmApplication, IHttpLlmFunction, IHttpResponse, ILlmSchema, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
2
+
3
+ import { HttpLlm, OpenApi } from "@samchon/openapi";
4
+ import typia from "typia";
5
+
6
+ import type { IAgenticaController } from "../structures/IAgenticaController";
7
+
8
+ /**
9
+ * Create an HTTP controller with type assertion.
10
+ *
11
+ * Create an {@link IAgenticaController.IHttp} instance which represents
12
+ * the HTTP controller from the given Swagger/OpenAPI document and the
13
+ * target LLM model with connection information.
14
+ *
15
+ * By the way, even though this `assertHttpController` function
16
+ * supports every version of Swagger/OpenAPI specification, there can
17
+ * be a type error in the given document. In that case, the function
18
+ * will throw an error with detailed type error tracing information.
19
+ *
20
+ * @param props Properties to create the HTTP controller instance
21
+ * @returns HTTP controller instance
22
+ * @throws {@link TypeGuardError} when the given document is invalid
23
+ * @author Samchon
24
+ */
25
+ export function assertHttpController<
26
+ Model extends ILlmSchema.Model,
27
+ >(props: {
28
+ /**
29
+ * Name of the controller.
30
+ */
31
+ name: string;
32
+
33
+ /**
34
+ * Target LLM model.
35
+ */
36
+ model: Model;
37
+
38
+ /**
39
+ * Swagger/OpenAPI document.
40
+ */
41
+ document:
42
+ | SwaggerV2.IDocument
43
+ | OpenApiV3.IDocument
44
+ | OpenApiV3_1.IDocument
45
+ | OpenApi.IDocument
46
+ | unknown;
47
+
48
+ /**
49
+ * Connection to the server.
50
+ *
51
+ * Connection to the API server including the URL and headers.
52
+ */
53
+ connection: IHttpConnection;
54
+
55
+ /**
56
+ * Options for the LLM function calling schema composition.
57
+ */
58
+ options?: Partial<IHttpLlmApplication.IOptions<Model>>;
59
+
60
+ /**
61
+ * Executor of the API function.
62
+ *
63
+ * @param props Properties of the API function call
64
+ * @returns HTTP response of the API function call
65
+ */
66
+ execute?: (props: {
67
+ /**
68
+ * Connection to the server.
69
+ */
70
+ connection: IHttpConnection;
71
+
72
+ /**
73
+ * Application schema.
74
+ */
75
+ application: IHttpLlmApplication<Model>;
76
+
77
+ /**
78
+ * Function schema.
79
+ */
80
+ function: IHttpLlmFunction<Model>;
81
+
82
+ /**
83
+ * Arguments of the function calling.
84
+ *
85
+ * It is an object of key-value pairs of the API function's parameters.
86
+ * The property keys are composed by below rules:
87
+ *
88
+ * - parameter names
89
+ * - query parameter as an object type if exists
90
+ * - body parameter if exists
91
+ */
92
+ arguments: object;
93
+ }) => Promise<IHttpResponse>;
94
+ }): IAgenticaController.IHttp<Model> {
95
+ const document = OpenApi.convert(typia.assert<
96
+ | SwaggerV2.IDocument
97
+ | OpenApiV3.IDocument
98
+ | OpenApiV3_1.IDocument
99
+ | OpenApi.IDocument
100
+ >(props.document));
101
+ return {
102
+ protocol: "http",
103
+ name: props.name,
104
+ application: HttpLlm.application({
105
+ model: props.model,
106
+ document,
107
+ options: props.options,
108
+ }),
109
+ execute: props.execute,
110
+ connection: props.connection,
111
+ };
112
+ }
@@ -28,6 +28,7 @@ import typia from "typia";
28
28
  * @returns HTTP LLM application instance
29
29
  * @throws {@link TypeGuardError} when the given document is invalid
30
30
  * @author Samchon
31
+ * @deprecated Use {@link assertHttpController} instead.
31
32
  */
32
33
  export function assertHttpLlmApplication<
33
34
  Model extends ILlmSchema.Model,
@@ -19,7 +19,7 @@ import type { IAgenticaController } from "../structures/IAgenticaController";
19
19
  * @param props.model Model schema of the LLM function calling.
20
20
  * @param props.options Options to create the MCP controller.
21
21
  * @returns MCP LLM application instance
22
- * @author Samchon
22
+ * @author sunrabbit123
23
23
  */
24
24
  export async function assertMcpController<Model extends ILlmSchema.Model>(props: {
25
25
  name: string;
@@ -42,7 +42,6 @@ export async function assertMcpController<Model extends ILlmSchema.Model>(props:
42
42
  protocol: "mcp",
43
43
  name: props.name,
44
44
  client: props.client,
45
-
46
45
  application,
47
46
  };
48
47
  }
@@ -0,0 +1,118 @@
1
+ import type { IHttpConnection, IHttpLlmApplication, IHttpLlmFunction, IHttpResponse, ILlmSchema, IValidation, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
2
+
3
+ import { HttpLlm, OpenApi } from "@samchon/openapi";
4
+ import typia from "typia";
5
+
6
+ import type { IAgenticaController } from "../structures/IAgenticaController";
7
+
8
+ /**
9
+ * Create an HTTP controller with type validation.
10
+ *
11
+ * Create an {@link IAgenticaController.IHttp} instance which represents
12
+ * the HTTP controller from the given Swagger/OpenAPI document and the
13
+ * target LLM model with connection information.
14
+ *
15
+ * By the way, even though this `validateHttpController` function
16
+ * supports every version of Swagger/OpenAPI specification, there can
17
+ * be a type error in the given document. In that case, the function
18
+ * will return {@link IValidation.IFailure} instance with detailed
19
+ * type error tracing information.
20
+ *
21
+ * @param props Properties to create the HTTP controller instance
22
+ * @returns Validation result of the HTTP controller composition
23
+ * @author Samchon
24
+ */
25
+ export function validateHttpController<
26
+ Model extends ILlmSchema.Model,
27
+ >(props: {
28
+ /**
29
+ * Name of the controller.
30
+ */
31
+ name: string;
32
+
33
+ /**
34
+ * Target LLM model.
35
+ */
36
+ model: Model;
37
+
38
+ /**
39
+ * Swagger/OpenAPI document.
40
+ */
41
+ document:
42
+ | SwaggerV2.IDocument
43
+ | OpenApiV3.IDocument
44
+ | OpenApiV3_1.IDocument
45
+ | OpenApi.IDocument
46
+ | unknown;
47
+
48
+ /**
49
+ * Connection to the server.
50
+ *
51
+ * Connection to the API server including the URL and headers.
52
+ */
53
+ connection: IHttpConnection;
54
+
55
+ /**
56
+ * Options for the LLM function calling schema composition.
57
+ */
58
+ options?: Partial<IHttpLlmApplication.IOptions<Model>>;
59
+
60
+ /**
61
+ * Executor of the API function.
62
+ *
63
+ * @param props Properties of the API function call
64
+ * @returns HTTP response of the API function call
65
+ */
66
+ execute?: (props: {
67
+ /**
68
+ * Connection to the server.
69
+ */
70
+ connection: IHttpConnection;
71
+
72
+ /**
73
+ * Application schema.
74
+ */
75
+ application: IHttpLlmApplication<Model>;
76
+
77
+ /**
78
+ * Function schema.
79
+ */
80
+ function: IHttpLlmFunction<Model>;
81
+
82
+ /**
83
+ * Arguments of the function calling.
84
+ *
85
+ * It is an object of key-value pairs of the API function's parameters.
86
+ * The property keys are composed by below rules:
87
+ *
88
+ * - parameter names
89
+ * - query parameter as an object type if exists
90
+ * - body parameter if exists
91
+ */
92
+ arguments: object;
93
+ }) => Promise<IHttpResponse>;
94
+ }): IValidation<IAgenticaController.IHttp<Model>> {
95
+ const inspect = typia.validate<
96
+ | SwaggerV2.IDocument
97
+ | OpenApiV3.IDocument
98
+ | OpenApiV3_1.IDocument
99
+ | OpenApi.IDocument
100
+ >(props.document);
101
+ if (inspect.success === false) {
102
+ return inspect;
103
+ }
104
+ return {
105
+ success: true,
106
+ data: {
107
+ protocol: "http",
108
+ name: props.name,
109
+ application: HttpLlm.application({
110
+ model: props.model,
111
+ document: OpenApi.convert(inspect.data),
112
+ options: props.options,
113
+ }),
114
+ execute: props.execute,
115
+ connection: props.connection,
116
+ },
117
+ };
118
+ }
@@ -29,6 +29,7 @@ import typia from "typia";
29
29
  * @param props Properties to create the HTTP LLM application instance
30
30
  * @returns Validation result of the HTTP LLM application composition
31
31
  * @author Samchon
32
+ * @deprecated Use {@link validateHttpController} instead.
32
33
  */
33
34
  export function validateHttpLlmApplication<
34
35
  Model extends ILlmSchema.Model,
@@ -67,7 +68,6 @@ export function validateHttpLlmApplication<
67
68
  if (inspect.success === false) {
68
69
  return inspect;
69
70
  }
70
-
71
71
  return {
72
72
  success: true,
73
73
  data: HttpLlm.application({
@@ -0,0 +1,56 @@
1
+ import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
+ import type { ILlmSchema, IMcpLlmApplication, IMcpTool, IValidation } from "@samchon/openapi";
3
+
4
+ import { McpLlm } from "@samchon/openapi";
5
+ import typia from "typia";
6
+
7
+ import type { IAgenticaController } from "../structures/IAgenticaController";
8
+
9
+ /**
10
+ * Create an MCP controller with type validation.
11
+ *
12
+ * Create an {@link IAgenticaController.IMcp} instance which represents
13
+ * an MCP (Model Context Protocol) controller with LLM function calling
14
+ * schemas and client connection.
15
+ *
16
+ * @param props Properties to create the MCP controller
17
+ * @param props.name Name of the MCP implementation.
18
+ * @param props.client Client connection to the MCP implementation.
19
+ * @param props.model Model schema of the LLM function calling.
20
+ * @param props.options Options to create the MCP controller.
21
+ * @returns MCP LLM application instance
22
+ * @author SunRabbit
23
+ */
24
+ export async function validateMcpController<
25
+ Model extends ILlmSchema.Model,
26
+ >(props: {
27
+ name: string;
28
+ client: Client;
29
+ model: Model;
30
+ options?: Partial<IMcpLlmApplication.IOptions<Model>>;
31
+ }): Promise<IValidation<IAgenticaController.IMcp<Model>>> {
32
+ // for peerDependencies
33
+ const { ListToolsResultSchema } = await import("@modelcontextprotocol/sdk/types.js");
34
+
35
+ // get list of tools
36
+ const { tools } = await props.client.request({ method: "tools/list" }, ListToolsResultSchema);
37
+ const inspect = typia.validate<Array<IMcpTool>>(tools);
38
+ if (inspect.success === false) {
39
+ return inspect;
40
+ }
41
+
42
+ const application: IMcpLlmApplication<Model> = McpLlm.application<Model>({
43
+ model: props.model,
44
+ tools: typia.assert<Array<IMcpTool>>(tools),
45
+ });
46
+
47
+ return {
48
+ success: true,
49
+ data: {
50
+ protocol: "mcp",
51
+ name: props.name,
52
+ client: props.client,
53
+ application,
54
+ },
55
+ };
56
+ }
@@ -5,13 +5,15 @@ import type { AgenticaDescribeHistory } from "./AgenticaDescribeHistory";
5
5
  import type { AgenticaExecuteHistory } from "./AgenticaExecuteHistory";
6
6
  import type { AgenticaSelectHistory } from "./AgenticaSelectHistory";
7
7
  import type { AgenticaTextHistory } from "./AgenticaTextHistory";
8
+ import type { AgenticaUserInputHistory } from "./AgenticaUserInputHistory";
8
9
 
9
10
  export type AgenticaHistory<Model extends ILlmSchema.Model> =
10
11
  | AgenticaCancelHistory<Model>
11
12
  | AgenticaDescribeHistory<Model>
12
13
  | AgenticaExecuteHistory<Model>
13
14
  | AgenticaSelectHistory<Model>
14
- | AgenticaTextHistory;
15
+ | AgenticaTextHistory
16
+ | AgenticaUserInputHistory;
15
17
  export namespace AgenticaHistory {
16
18
  export type Type = AgenticaHistory<any>["type"];
17
19
  export interface Mapper<Model extends ILlmSchema.Model> {
@@ -20,5 +22,6 @@ export namespace AgenticaHistory {
20
22
  execute: AgenticaExecuteHistory<Model>;
21
23
  select: AgenticaSelectHistory<Model>;
22
24
  text: AgenticaTextHistory;
25
+ user_input: AgenticaUserInputHistory;
23
26
  }
24
27
  }
@@ -2,9 +2,7 @@ import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
2
2
 
3
3
  import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
4
4
 
5
- export interface AgenticaTextHistory<
6
- Role extends "assistant" | "user" = "assistant" | "user",
7
- > extends AgenticaHistoryBase<"text", IAgenticaHistoryJson.IText> {
8
- role: Role;
5
+ export interface AgenticaTextHistory extends AgenticaHistoryBase<"text", IAgenticaHistoryJson.IText> {
6
+ role: "assistant";
9
7
  text: string;
10
8
  }
@@ -0,0 +1,88 @@
1
+ import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
2
+
3
+ import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
4
+
5
+ export interface AgenticaUserInputHistory extends AgenticaHistoryBase<"user_input", IAgenticaHistoryJson.IUserInput> {
6
+ role: "user";
7
+ contents: Array<AgenticaUserInputHistory.Contents>;
8
+ }
9
+
10
+ export namespace AgenticaUserInputHistory {
11
+ export type Contents = Contents.File | Contents.Image | Contents.InputAudio | Contents.Text;
12
+ export namespace Contents {
13
+ interface ContentsBase<Type extends string> {
14
+ /**
15
+ * The type of the content part.
16
+ */
17
+ type: Type;
18
+ }
19
+ /**
20
+ * Learn about
21
+ * [text inputs](https://platform.openai.com/docs/guides/text-generation).
22
+ */
23
+ export interface Text extends ContentsBase<"text"> {
24
+ /**
25
+ * The text content.
26
+ */
27
+ text: string;
28
+ }
29
+
30
+ /**
31
+ * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
32
+ */
33
+ export interface Image extends ContentsBase<"image_url"> {
34
+ image_url: {
35
+ /**
36
+ * Either a URL of the image or the base64 encoded image data.
37
+ */
38
+ url: string;
39
+ /**
40
+ * Specifies the detail level of the image. Learn more in the
41
+ * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
42
+ */
43
+ detail?: "auto" | "high" | "low";
44
+ };
45
+ }
46
+
47
+ /**
48
+ * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
49
+ */
50
+ export interface InputAudio extends ContentsBase<"input_audio"> {
51
+ input_audio: {
52
+ /**
53
+ * Base64 encoded audio data.
54
+ */
55
+ data: string;
56
+
57
+ /**
58
+ * The format of the encoded audio data. Currently supports "wav" and "mp3".
59
+ */
60
+ format: "wav" | "mp3";
61
+ };
62
+ }
63
+
64
+ /**
65
+ * Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text
66
+ * generation.
67
+ */
68
+ export interface File extends ContentsBase<"file"> {
69
+ file: {
70
+ /**
71
+ * The base64 encoded file data, used when passing the file to the model as a
72
+ * string.
73
+ */
74
+ file_data?: string;
75
+
76
+ /**
77
+ * The ID of an uploaded file to use as input.
78
+ */
79
+ file_id?: string;
80
+
81
+ /**
82
+ * The name of the file, used when passing the file to the model as a string.
83
+ */
84
+ filename?: string;
85
+ };
86
+ }
87
+ }
88
+ }