@agentica/core 0.22.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 (36) hide show
  1. package/README.md +10 -11
  2. package/lib/MicroAgentica.d.ts +10 -0
  3. package/lib/MicroAgentica.js +11 -0
  4. package/lib/MicroAgentica.js.map +1 -1
  5. package/lib/functional/assertHttpController.d.ts +75 -0
  6. package/lib/functional/assertHttpController.js +9622 -0
  7. package/lib/functional/assertHttpController.js.map +1 -0
  8. package/lib/functional/assertHttpLlmApplication.d.ts +1 -0
  9. package/lib/functional/assertHttpLlmApplication.js +1 -0
  10. package/lib/functional/assertHttpLlmApplication.js.map +1 -1
  11. package/lib/functional/assertMcpController.d.ts +1 -1
  12. package/lib/functional/assertMcpController.js +1 -1
  13. package/lib/functional/assertMcpController.js.map +1 -1
  14. package/lib/functional/validateHttpController.d.ts +75 -0
  15. package/lib/functional/validateHttpController.js +7952 -0
  16. package/lib/functional/validateHttpController.js.map +1 -0
  17. package/lib/functional/validateHttpLlmApplication.d.ts +1 -0
  18. package/lib/functional/validateHttpLlmApplication.js +1 -0
  19. package/lib/functional/validateHttpLlmApplication.js.map +1 -1
  20. package/lib/functional/validateMcpController.d.ts +24 -0
  21. package/lib/functional/validateMcpController.js +3034 -0
  22. package/lib/functional/validateMcpController.js.map +1 -0
  23. package/lib/index.d.ts +3 -0
  24. package/lib/index.js +3 -0
  25. package/lib/index.js.map +1 -1
  26. package/lib/index.mjs +25721 -5730
  27. package/lib/index.mjs.map +1 -1
  28. package/package.json +1 -1
  29. package/src/MicroAgentica.ts +13 -0
  30. package/src/functional/assertHttpController.ts +112 -0
  31. package/src/functional/assertHttpLlmApplication.ts +1 -0
  32. package/src/functional/assertMcpController.ts +1 -2
  33. package/src/functional/validateHttpController.ts +118 -0
  34. package/src/functional/validateHttpLlmApplication.ts +1 -1
  35. package/src/functional/validateMcpController.ts +56 -0
  36. package/src/index.ts +3 -0
@@ -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
+ }
package/src/index.ts CHANGED
@@ -22,9 +22,12 @@ export * from "./events/MicroAgenticaEvent";
22
22
 
23
23
  export * as factory from "./factory";
24
24
 
25
+ export * from "./functional/assertHttpController";
25
26
  export * from "./functional/assertHttpLlmApplication";
26
27
  export * from "./functional/assertMcpController";
28
+ export * from "./functional/validateHttpController";
27
29
  export * from "./functional/validateHttpLlmApplication";
30
+ export * from "./functional/validateMcpController";
28
31
  // @TODO: implement validateMcpLlmApplication
29
32
 
30
33
  export * from "./histories/AgenticaCancelHistory";