@typia/utils 12.0.0-dev.20260312 → 12.0.0-dev.20260312-3

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.
@@ -1,166 +1,166 @@
1
- import {
2
- IHttpConnection,
3
- IHttpLlmApplication,
4
- IHttpLlmController,
5
- IHttpLlmFunction,
6
- IHttpMigrateApplication,
7
- IHttpResponse,
8
- OpenApi,
9
- OpenApiV3,
10
- OpenApiV3_1,
11
- SwaggerV2,
12
- } from "@typia/interface";
13
-
14
- import { HttpMigration } from "./HttpMigration";
15
- import { HttpLlmApplicationComposer } from "./internal/HttpLlmApplicationComposer";
16
- import { HttpLlmFunctionFetcher } from "./internal/HttpLlmFunctionFetcher";
17
-
18
- /**
19
- * LLM function calling utilities for OpenAPI documents.
20
- *
21
- * `HttpLlm` converts OpenAPI documents into LLM function calling applications
22
- * and executes them. Supports all OpenAPI versions (Swagger 2.0, OpenAPI 3.0,
23
- * 3.1) through automatic conversion to {@link OpenApi} format.
24
- *
25
- * Main functions:
26
- *
27
- * - {@link controller}: Create {@link IHttpLlmController} from OpenAPI document
28
- * - {@link application}: Convert OpenAPI document to {@link IHttpLlmApplication}
29
- * - {@link execute}: Call an LLM function and return the response body
30
- * - {@link propagate}: Call an LLM function and return full HTTP response
31
- * - {@link mergeParameters}: Merge LLM-filled and human-filled parameters
32
- *
33
- * Typical workflow:
34
- *
35
- * 1. Load OpenAPI document (JSON/YAML)
36
- * 2. Call `HttpLlm.application()` to get function schemas
37
- * 3. Send function schemas to LLM for function selection
38
- * 4. Call `HttpLlm.execute()` with LLM's chosen function and arguments
39
- *
40
- * @author Jeongho Nam - https://github.com/samchon
41
- */
42
- export namespace HttpLlm {
43
- /* -----------------------------------------------------------
44
- COMPOSERS
45
- ----------------------------------------------------------- */
46
- /**
47
- * Create HTTP LLM controller from OpenAPI document.
48
- *
49
- * Composes {@link IHttpLlmController} from OpenAPI document with connection
50
- * info. The controller can be used with {@link registerMcpControllers} to
51
- * register all API operations as MCP tools at once.
52
- *
53
- * @param props Controller properties
54
- * @returns HTTP LLM controller
55
- */
56
- export const controller = (props: {
57
- /** Identifier name of the controller. */
58
- name: string;
59
-
60
- /** OpenAPI document to convert. */
61
- document:
62
- | OpenApi.IDocument
63
- | SwaggerV2.IDocument
64
- | OpenApiV3.IDocument
65
- | OpenApiV3_1.IDocument;
66
-
67
- /** Connection to the API server. */
68
- connection: IHttpConnection;
69
-
70
- /** LLM schema conversion configuration. */
71
- config?: Partial<IHttpLlmApplication.IConfig>;
72
-
73
- /**
74
- * Custom executor of the API function.
75
- *
76
- * Default executor is {@link HttpLlm.execute} function.
77
- */
78
- execute?: IHttpLlmController["execute"];
79
- }): IHttpLlmController => ({
80
- protocol: "http",
81
- name: props.name,
82
- application: application({
83
- document: props.document,
84
- config: props.config,
85
- }),
86
- connection: props.connection,
87
- execute: props.execute,
88
- });
89
-
90
- /**
91
- * Convert OpenAPI document to LLM function calling application.
92
- *
93
- * Converts API operations to LLM-callable functions.
94
- *
95
- * @param props Composition properties
96
- * @returns LLM function calling application
97
- */
98
- export const application = (props: {
99
- /** OpenAPI document to convert. */
100
- document:
101
- | OpenApi.IDocument
102
- | SwaggerV2.IDocument
103
- | OpenApiV3.IDocument
104
- | OpenApiV3_1.IDocument;
105
-
106
- /** LLM schema conversion configuration. */
107
- config?: Partial<IHttpLlmApplication.IConfig>;
108
- }): IHttpLlmApplication => {
109
- // MIGRATE
110
- const migrate: IHttpMigrateApplication = HttpMigration.application(
111
- props.document,
112
- );
113
- return HttpLlmApplicationComposer.application({
114
- migrate,
115
- config: {
116
- strict: props.config?.strict ?? false,
117
- maxLength: props.config?.maxLength ?? 64,
118
- equals: props.config?.equals ?? false,
119
- },
120
- });
121
- };
122
-
123
- /* -----------------------------------------------------------
124
- FETCHERS
125
- ----------------------------------------------------------- */
126
- /** Properties for LLM function call. */
127
- export interface IFetchProps {
128
- /** LLM function calling application. */
129
- application: IHttpLlmApplication;
130
-
131
- /** Function to call. */
132
- function: IHttpLlmFunction;
133
-
134
- /** HTTP connection info. */
135
- connection: IHttpConnection;
136
-
137
- /** Function arguments. */
138
- input: object;
139
- }
140
-
141
- /**
142
- * Execute LLM function call.
143
- *
144
- * Calls API endpoint and returns response body. Throws {@link HttpError} on
145
- * non-2xx status.
146
- *
147
- * @param props Function call properties
148
- * @returns Response body
149
- * @throws HttpError on non-2xx status
150
- */
151
- export const execute = (props: IFetchProps): Promise<unknown> =>
152
- HttpLlmFunctionFetcher.execute(props);
153
-
154
- /**
155
- * Propagate LLM function call.
156
- *
157
- * Calls API endpoint and returns full response including non-2xx. Use when
158
- * you need to handle error responses yourself.
159
- *
160
- * @param props Function call properties
161
- * @returns Full HTTP response
162
- * @throws Error only on connection failure
163
- */
164
- export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>
165
- HttpLlmFunctionFetcher.propagate(props);
166
- }
1
+ import {
2
+ IHttpConnection,
3
+ IHttpLlmApplication,
4
+ IHttpLlmController,
5
+ IHttpLlmFunction,
6
+ IHttpMigrateApplication,
7
+ IHttpResponse,
8
+ OpenApi,
9
+ OpenApiV3,
10
+ OpenApiV3_1,
11
+ SwaggerV2,
12
+ } from "@typia/interface";
13
+
14
+ import { HttpMigration } from "./HttpMigration";
15
+ import { HttpLlmApplicationComposer } from "./internal/HttpLlmApplicationComposer";
16
+ import { HttpLlmFunctionFetcher } from "./internal/HttpLlmFunctionFetcher";
17
+
18
+ /**
19
+ * LLM function calling utilities for OpenAPI documents.
20
+ *
21
+ * `HttpLlm` converts OpenAPI documents into LLM function calling applications
22
+ * and executes them. Supports all OpenAPI versions (Swagger 2.0, OpenAPI 3.0,
23
+ * 3.1) through automatic conversion to {@link OpenApi} format.
24
+ *
25
+ * Main functions:
26
+ *
27
+ * - {@link controller}: Create {@link IHttpLlmController} from OpenAPI document
28
+ * - {@link application}: Convert OpenAPI document to {@link IHttpLlmApplication}
29
+ * - {@link execute}: Call an LLM function and return the response body
30
+ * - {@link propagate}: Call an LLM function and return full HTTP response
31
+ * - {@link mergeParameters}: Merge LLM-filled and human-filled parameters
32
+ *
33
+ * Typical workflow:
34
+ *
35
+ * 1. Load OpenAPI document (JSON/YAML)
36
+ * 2. Call `HttpLlm.application()` to get function schemas
37
+ * 3. Send function schemas to LLM for function selection
38
+ * 4. Call `HttpLlm.execute()` with LLM's chosen function and arguments
39
+ *
40
+ * @author Jeongho Nam - https://github.com/samchon
41
+ */
42
+ export namespace HttpLlm {
43
+ /* -----------------------------------------------------------
44
+ COMPOSERS
45
+ ----------------------------------------------------------- */
46
+ /**
47
+ * Create HTTP LLM controller from OpenAPI document.
48
+ *
49
+ * Composes {@link IHttpLlmController} from OpenAPI document with connection
50
+ * info. The controller can be used with {@link registerMcpControllers} to
51
+ * register all API operations as MCP tools at once.
52
+ *
53
+ * @param props Controller properties
54
+ * @returns HTTP LLM controller
55
+ */
56
+ export const controller = (props: {
57
+ /** Identifier name of the controller. */
58
+ name: string;
59
+
60
+ /** OpenAPI document to convert. */
61
+ document:
62
+ | OpenApi.IDocument
63
+ | SwaggerV2.IDocument
64
+ | OpenApiV3.IDocument
65
+ | OpenApiV3_1.IDocument;
66
+
67
+ /** Connection to the API server. */
68
+ connection: IHttpConnection;
69
+
70
+ /** LLM schema conversion configuration. */
71
+ config?: Partial<IHttpLlmApplication.IConfig>;
72
+
73
+ /**
74
+ * Custom executor of the API function.
75
+ *
76
+ * Default executor is {@link HttpLlm.execute} function.
77
+ */
78
+ execute?: IHttpLlmController["execute"];
79
+ }): IHttpLlmController => ({
80
+ protocol: "http",
81
+ name: props.name,
82
+ application: application({
83
+ document: props.document,
84
+ config: props.config,
85
+ }),
86
+ connection: props.connection,
87
+ execute: props.execute,
88
+ });
89
+
90
+ /**
91
+ * Convert OpenAPI document to LLM function calling application.
92
+ *
93
+ * Converts API operations to LLM-callable functions.
94
+ *
95
+ * @param props Composition properties
96
+ * @returns LLM function calling application
97
+ */
98
+ export const application = (props: {
99
+ /** OpenAPI document to convert. */
100
+ document:
101
+ | OpenApi.IDocument
102
+ | SwaggerV2.IDocument
103
+ | OpenApiV3.IDocument
104
+ | OpenApiV3_1.IDocument;
105
+
106
+ /** LLM schema conversion configuration. */
107
+ config?: Partial<IHttpLlmApplication.IConfig>;
108
+ }): IHttpLlmApplication => {
109
+ // MIGRATE
110
+ const migrate: IHttpMigrateApplication = HttpMigration.application(
111
+ props.document,
112
+ );
113
+ return HttpLlmApplicationComposer.application({
114
+ migrate,
115
+ config: {
116
+ strict: props.config?.strict ?? false,
117
+ maxLength: props.config?.maxLength ?? 64,
118
+ equals: props.config?.equals ?? false,
119
+ },
120
+ });
121
+ };
122
+
123
+ /* -----------------------------------------------------------
124
+ FETCHERS
125
+ ----------------------------------------------------------- */
126
+ /** Properties for LLM function call. */
127
+ export interface IFetchProps {
128
+ /** LLM function calling application. */
129
+ application: IHttpLlmApplication;
130
+
131
+ /** Function to call. */
132
+ function: IHttpLlmFunction;
133
+
134
+ /** HTTP connection info. */
135
+ connection: IHttpConnection;
136
+
137
+ /** Function arguments. */
138
+ input: object;
139
+ }
140
+
141
+ /**
142
+ * Execute LLM function call.
143
+ *
144
+ * Calls API endpoint and returns response body. Throws {@link HttpError} on
145
+ * non-2xx status.
146
+ *
147
+ * @param props Function call properties
148
+ * @returns Response body
149
+ * @throws HttpError on non-2xx status
150
+ */
151
+ export const execute = (props: IFetchProps): Promise<unknown> =>
152
+ HttpLlmFunctionFetcher.execute(props);
153
+
154
+ /**
155
+ * Propagate LLM function call.
156
+ *
157
+ * Calls API endpoint and returns full response including non-2xx. Use when
158
+ * you need to handle error responses yourself.
159
+ *
160
+ * @param props Function call properties
161
+ * @returns Full HTTP response
162
+ * @throws Error only on connection failure
163
+ */
164
+ export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>
165
+ HttpLlmFunctionFetcher.propagate(props);
166
+ }