@agentica/core 0.22.0 → 0.24.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 (67) hide show
  1. package/README.md +11 -12
  2. package/lib/Agentica.d.ts +6 -1
  3. package/lib/Agentica.js +8 -3
  4. package/lib/Agentica.js.map +1 -1
  5. package/lib/MicroAgentica.d.ts +10 -0
  6. package/lib/MicroAgentica.js +11 -0
  7. package/lib/MicroAgentica.js.map +1 -1
  8. package/lib/context/AgenticaContext.d.ts +4 -0
  9. package/lib/functional/assertHttpController.d.ts +75 -0
  10. package/lib/functional/assertHttpController.js +9622 -0
  11. package/lib/functional/assertHttpController.js.map +1 -0
  12. package/lib/functional/assertHttpLlmApplication.d.ts +1 -0
  13. package/lib/functional/assertHttpLlmApplication.js +1 -0
  14. package/lib/functional/assertHttpLlmApplication.js.map +1 -1
  15. package/lib/functional/assertMcpController.d.ts +1 -1
  16. package/lib/functional/assertMcpController.js +1 -1
  17. package/lib/functional/assertMcpController.js.map +1 -1
  18. package/lib/functional/validateHttpController.d.ts +75 -0
  19. package/lib/functional/validateHttpController.js +7952 -0
  20. package/lib/functional/validateHttpController.js.map +1 -0
  21. package/lib/functional/validateHttpLlmApplication.d.ts +1 -0
  22. package/lib/functional/validateHttpLlmApplication.js +1 -0
  23. package/lib/functional/validateHttpLlmApplication.js.map +1 -1
  24. package/lib/functional/validateMcpController.d.ts +24 -0
  25. package/lib/functional/validateMcpController.js +3034 -0
  26. package/lib/functional/validateMcpController.js.map +1 -0
  27. package/lib/histories/AgenticaUserInputHistory.d.ts +13 -7
  28. package/lib/index.d.ts +3 -0
  29. package/lib/index.js +3 -0
  30. package/lib/index.js.map +1 -1
  31. package/lib/index.mjs +25981 -5985
  32. package/lib/index.mjs.map +1 -1
  33. package/lib/utils/ChatGptCompletionMessageUtil.spec.d.ts +1 -0
  34. package/lib/utils/ChatGptCompletionMessageUtil.spec.js +288 -0
  35. package/lib/utils/ChatGptCompletionMessageUtil.spec.js.map +1 -0
  36. package/lib/utils/ChatGptTokenUsageAggregator.spec.d.ts +1 -0
  37. package/lib/utils/ChatGptTokenUsageAggregator.spec.js +199 -0
  38. package/lib/utils/ChatGptTokenUsageAggregator.spec.js.map +1 -0
  39. package/lib/utils/Singleton.js +18 -0
  40. package/lib/utils/Singleton.js.map +1 -1
  41. package/lib/utils/Singleton.spec.d.ts +1 -0
  42. package/lib/utils/Singleton.spec.js +106 -0
  43. package/lib/utils/Singleton.spec.js.map +1 -0
  44. package/lib/utils/__map_take.spec.d.ts +1 -0
  45. package/lib/utils/__map_take.spec.js +108 -0
  46. package/lib/utils/__map_take.spec.js.map +1 -0
  47. package/package.json +1 -1
  48. package/src/Agentica.ts +16 -2
  49. package/src/MicroAgentica.ts +13 -0
  50. package/src/context/AgenticaContext.ts +5 -0
  51. package/src/functional/assertHttpController.ts +112 -0
  52. package/src/functional/assertHttpLlmApplication.ts +1 -0
  53. package/src/functional/assertMcpController.ts +1 -2
  54. package/src/functional/validateHttpController.ts +118 -0
  55. package/src/functional/validateHttpLlmApplication.ts +1 -1
  56. package/src/functional/validateMcpController.ts +56 -0
  57. package/src/histories/AgenticaUserInputHistory.ts +14 -8
  58. package/src/index.ts +3 -0
  59. package/src/utils/ChatGptCompletionMessageUtil.spec.ts +320 -0
  60. package/src/utils/ChatGptTokenUsageAggregator.spec.ts +226 -0
  61. package/src/utils/Singleton.spec.ts +138 -0
  62. package/src/utils/Singleton.ts +18 -0
  63. package/src/utils/__map_take.spec.ts +140 -0
  64. package/lib/utils/MathUtil.d.ts +0 -3
  65. package/lib/utils/MathUtil.js +0 -8
  66. package/lib/utils/MathUtil.js.map +0 -1
  67. package/src/utils/MathUtil.ts +0 -3
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const __map_take_1 = require("./__map_take");
4
+ describe("__map_take", () => {
5
+ describe("basic functionality", () => {
6
+ it("should generate value for new key", () => {
7
+ const map = new Map();
8
+ const generator = () => 42;
9
+ const result = (0, __map_take_1.__map_take)(map, "test", generator);
10
+ expect(result).toBe(42);
11
+ expect(map.get("test")).toBe(42);
12
+ });
13
+ it("should return existing value for existing key", () => {
14
+ const map = new Map();
15
+ map.set("test", 100);
16
+ const generator = () => 42;
17
+ const result = (0, __map_take_1.__map_take)(map, "test", generator);
18
+ expect(result).toBe(100);
19
+ expect(map.get("test")).toBe(100);
20
+ });
21
+ });
22
+ describe("various type tests", () => {
23
+ it("should handle object type", () => {
24
+ const map = new Map();
25
+ const generator = () => ({ value: 42 });
26
+ const result = (0, __map_take_1.__map_take)(map, "test", generator);
27
+ expect(result).toEqual({ value: 42 });
28
+ expect(map.get("test")).toEqual({ value: 42 });
29
+ });
30
+ it("should handle array type", () => {
31
+ const map = new Map();
32
+ const generator = () => [1, 2, 3];
33
+ const result = (0, __map_take_1.__map_take)(map, "test", generator);
34
+ expect(result).toEqual([1, 2, 3]);
35
+ expect(map.get("test")).toEqual([1, 2, 3]);
36
+ });
37
+ it("should handle function type", () => {
38
+ var _a;
39
+ const map = new Map();
40
+ const generator = () => () => 42;
41
+ const result = (0, __map_take_1.__map_take)(map, "test", generator);
42
+ expect(result()).toBe(42);
43
+ expect((_a = map.get("test")) === null || _a === void 0 ? void 0 : _a()).toBe(42);
44
+ });
45
+ });
46
+ describe("edge cases", () => {
47
+ it("should handle null key", () => {
48
+ const map = new Map();
49
+ const generator = () => "test";
50
+ const result = (0, __map_take_1.__map_take)(map, null, generator);
51
+ expect(result).toBe("test");
52
+ expect(map.get(null)).toBe("test");
53
+ });
54
+ it("should handle undefined key", () => {
55
+ const map = new Map();
56
+ const generator = () => "test";
57
+ const result = (0, __map_take_1.__map_take)(map, undefined, generator);
58
+ expect(result).toBe("test");
59
+ expect(map.get(undefined)).toBe("test");
60
+ });
61
+ it("should handle empty string key", () => {
62
+ const map = new Map();
63
+ const generator = () => "test";
64
+ const result = (0, __map_take_1.__map_take)(map, "", generator);
65
+ expect(result).toBe("test");
66
+ expect(map.get("")).toBe("test");
67
+ });
68
+ });
69
+ describe("generator function tests", () => {
70
+ it("should not call generator multiple times", () => {
71
+ const map = new Map();
72
+ let callCount = 0;
73
+ const generator = () => {
74
+ callCount++;
75
+ return 42;
76
+ };
77
+ (0, __map_take_1.__map_take)(map, "test", generator);
78
+ (0, __map_take_1.__map_take)(map, "test", generator);
79
+ expect(callCount).toBe(1);
80
+ });
81
+ it("should handle generator throwing error", () => {
82
+ const map = new Map();
83
+ const generator = () => {
84
+ throw new Error("Generator error");
85
+ };
86
+ expect(() => (0, __map_take_1.__map_take)(map, "test", generator)).toThrow("Generator error");
87
+ });
88
+ it("should handle generator returning undefined", () => {
89
+ const map = new Map();
90
+ const generator = () => undefined;
91
+ const result = (0, __map_take_1.__map_take)(map, "test", generator);
92
+ expect(result).toBeUndefined();
93
+ expect(map.get("test")).toBeUndefined();
94
+ });
95
+ });
96
+ describe("concurrency tests", () => {
97
+ it("should handle concurrent access to same key", () => {
98
+ const map = new Map();
99
+ const generator = () => 42;
100
+ const result1 = (0, __map_take_1.__map_take)(map, "test", generator);
101
+ const result2 = (0, __map_take_1.__map_take)(map, "test", generator);
102
+ expect(result1).toBe(42);
103
+ expect(result2).toBe(42);
104
+ expect(map.get("test")).toBe(42);
105
+ });
106
+ });
107
+ });
108
+ //# sourceMappingURL=__map_take.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"__map_take.spec.js","sourceRoot":"","sources":["../../src/utils/__map_take.spec.ts"],"names":[],"mappings":";;AAAA,6CAA0C;AAE1C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACnC,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;YAC3C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;YACtC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC;YAE3B,M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AC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;YACrD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;YACtC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC;YAE3B,MAAM,OAAO,GAAG,IAAA,uBAAU,EAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;YACnD,MAAM,OAAO,GAAG,IAAA,uBAAU,EAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;YAEnD,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACzB,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACzB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentica/core",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Agentic AI Library specialized in LLM Function Calling",
5
5
  "author": "Wrtn Technologies",
6
6
  "license": "MIT",
package/src/Agentica.ts CHANGED
@@ -124,9 +124,17 @@ export class Agentica<Model extends ILlmSchema.Model> {
124
124
  * function calling information like {@link AgenticaExecuteHistory}.
125
125
  *
126
126
  * @param content The content to talk
127
+ * @param options Options
128
+ * @param options.abortSignal Abort signal
129
+ * @throws AbortError
127
130
  * @returns List of newly created chat prompts
128
131
  */
129
- public async conversate(content: string | AgenticaUserInputHistory.Contents | Array<AgenticaUserInputHistory.Contents>): Promise<AgenticaHistory<Model>[]> {
132
+ public async conversate(
133
+ content: string | AgenticaUserInputHistory.Contents | Array<AgenticaUserInputHistory.Contents>,
134
+ options: {
135
+ abortSignal?: AbortSignal;
136
+ } = {},
137
+ ): Promise<AgenticaHistory<Model>[]> {
130
138
  const prompt: AgenticaUserInputHistory = createUserInputHistory({
131
139
  contents: Array.isArray(content)
132
140
  ? content
@@ -147,6 +155,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
147
155
  const newbie: AgenticaHistory<Model>[] = await this.executor_(
148
156
  this.getContext({
149
157
  prompt,
158
+ abortSignal: options.abortSignal,
150
159
  usage: this.token_usage_,
151
160
  }),
152
161
  );
@@ -219,6 +228,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
219
228
  public getContext(props: {
220
229
  prompt: AgenticaUserInputHistory;
221
230
  usage: AgenticaTokenUsage;
231
+ abortSignal?: AbortSignal;
222
232
  }): AgenticaContext<Model> {
223
233
  const dispatch = async (event: AgenticaEvent<Model>) => this.dispatch(event);
224
234
  return {
@@ -231,6 +241,7 @@ export class Agentica<Model extends ILlmSchema.Model> {
231
241
  stack: this.stack_,
232
242
  ready: () => this.ready_,
233
243
  prompt: props.prompt,
244
+ abortSignal: props.abortSignal,
234
245
 
235
246
  // HANDLERS
236
247
  dispatch: async event => this.dispatch(event),
@@ -246,7 +257,10 @@ export class Agentica<Model extends ILlmSchema.Model> {
246
257
  include_usage: true,
247
258
  },
248
259
  },
249
- options: this.props.vendor.options,
260
+ options: {
261
+ ...this.props.vendor.options,
262
+ signal: props.abortSignal,
263
+ },
250
264
  });
251
265
  await dispatch(event);
252
266
 
@@ -1,5 +1,6 @@
1
1
  import type { ILlmSchema } from "@samchon/openapi";
2
2
 
3
+ import type { AgenticaOperation } from "./context/AgenticaOperation";
3
4
  import type { AgenticaOperationCollection } from "./context/AgenticaOperationCollection";
4
5
  import type { MicroAgenticaContext } from "./context/MicroAgenticaContext";
5
6
  import type { AgenticaRequestEvent } from "./events/AgenticaRequestEvent";
@@ -157,6 +158,18 @@ export class MicroAgentica<Model extends ILlmSchema.Model> {
157
158
  return this.props.vendor;
158
159
  }
159
160
 
161
+ /**
162
+ * Get operations.
163
+ *
164
+ * Get list of operations, which has capsuled the pair of controller
165
+ * and function from the {@link getControllers controllers}.
166
+ *
167
+ * @returns List of operations
168
+ */
169
+ public getOperations(): ReadonlyArray<AgenticaOperation<Model>> {
170
+ return this.operations_.array;
171
+ }
172
+
160
173
  /**
161
174
  * Get controllers.
162
175
  *
@@ -87,6 +87,11 @@ export interface AgenticaContext<Model extends ILlmSchema.Model> {
87
87
  */
88
88
  prompt: AgenticaUserInputHistory;
89
89
 
90
+ /**
91
+ * Abort signal.
92
+ */
93
+ abortSignal?: AbortSignal;
94
+
90
95
  /**
91
96
  * Whether the agent is ready.
92
97
  *
@@ -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
+ }
@@ -1,3 +1,5 @@
1
+ import type typia from "typia";
2
+
1
3
  import type { IAgenticaHistoryJson } from "../json/IAgenticaHistoryJson";
2
4
 
3
5
  import type { AgenticaHistoryBase } from "./AgenticaHistoryBase";
@@ -35,7 +37,7 @@ export namespace AgenticaUserInputHistory {
35
37
  /**
36
38
  * Either a URL of the image or the base64 encoded image data.
37
39
  */
38
- url: string;
40
+ url: string & typia.tags.Format<"url">;
39
41
  /**
40
42
  * Specifies the detail level of the image. Learn more in the
41
43
  * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
@@ -46,6 +48,8 @@ export namespace AgenticaUserInputHistory {
46
48
 
47
49
  /**
48
50
  * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
51
+ *
52
+ * Note: we not recommend it because audio input data only support base64 so it's too big data.
49
53
  */
50
54
  export interface InputAudio extends ContentsBase<"input_audio"> {
51
55
  input_audio: {
@@ -64,24 +68,26 @@ export namespace AgenticaUserInputHistory {
64
68
  /**
65
69
  * Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text
66
70
  * generation.
71
+ *
72
+ * Note: we recommend use `file_id` instead of `file_data` because it's too big data.
67
73
  */
68
74
  export interface File extends ContentsBase<"file"> {
69
75
  file: {
70
76
  /**
71
- * The base64 encoded file data, used when passing the file to the model as a
72
- * string.
77
+ * The ID of an uploaded file to use as input.
73
78
  */
74
- file_data?: string;
75
-
79
+ file_id: string;
80
+ } | {
76
81
  /**
77
- * The ID of an uploaded file to use as input.
82
+ * The base64 encoded file data, used when passing the file to the model as a
83
+ * string.
78
84
  */
79
- file_id?: string;
85
+ file_data: string;
80
86
 
81
87
  /**
82
88
  * The name of the file, used when passing the file to the model as a string.
83
89
  */
84
- filename?: string;
90
+ filename: string;
85
91
  };
86
92
  }
87
93
  }
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";