@typia/utils 12.0.0-dev.20260307-2 → 12.0.0-dev.20260310

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 (103) hide show
  1. package/README.md +2 -2
  2. package/lib/http/internal/HttpLlmApplicationComposer.js +1 -0
  3. package/lib/http/internal/HttpLlmApplicationComposer.js.map +1 -1
  4. package/lib/http/internal/HttpLlmApplicationComposer.mjs +1 -0
  5. package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
  6. package/lib/utils/LlmJson.d.ts +3 -3
  7. package/lib/utils/LlmJson.js +2 -2
  8. package/lib/utils/LlmJson.js.map +1 -1
  9. package/lib/utils/LlmJson.mjs +2 -2
  10. package/lib/utils/LlmJson.mjs.map +1 -1
  11. package/lib/utils/internal/coerceLlmArguments.js +17 -1
  12. package/lib/utils/internal/coerceLlmArguments.js.map +1 -1
  13. package/lib/utils/internal/coerceLlmArguments.mjs +17 -1
  14. package/lib/utils/internal/coerceLlmArguments.mjs.map +1 -1
  15. package/lib/utils/internal/parseLenientJson.js +236 -96
  16. package/lib/utils/internal/parseLenientJson.js.map +1 -1
  17. package/lib/utils/internal/parseLenientJson.mjs +236 -96
  18. package/lib/utils/internal/parseLenientJson.mjs.map +1 -1
  19. package/lib/utils/internal/stringifyValidationFailure.js +17 -15
  20. package/lib/utils/internal/stringifyValidationFailure.js.map +1 -1
  21. package/lib/utils/internal/stringifyValidationFailure.mjs +17 -15
  22. package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
  23. package/package.json +2 -2
  24. package/src/converters/LlmSchemaConverter.ts +647 -647
  25. package/src/converters/OpenApiConverter.ts +285 -285
  26. package/src/converters/index.ts +5 -5
  27. package/src/converters/internal/LlmDescriptionInverter.ts +178 -178
  28. package/src/converters/internal/LlmParametersComposer.ts +52 -52
  29. package/src/converters/internal/OpenApiConstraintShifter.ts +154 -154
  30. package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -46
  31. package/src/converters/internal/OpenApiV3Downgrader.ts +355 -355
  32. package/src/converters/internal/OpenApiV3Upgrader.ts +470 -470
  33. package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -685
  34. package/src/converters/internal/SwaggerV2Downgrader.ts +424 -424
  35. package/src/converters/internal/SwaggerV2Upgrader.ts +523 -523
  36. package/src/http/HttpError.ts +107 -107
  37. package/src/http/HttpLlm.ts +167 -167
  38. package/src/http/HttpMigration.ts +92 -92
  39. package/src/http/index.ts +3 -3
  40. package/src/http/internal/HttpLlmApplicationComposer.ts +361 -360
  41. package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -37
  42. package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -56
  43. package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -135
  44. package/src/http/internal/HttpMigrateRouteComposer.ts +505 -505
  45. package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -203
  46. package/src/index.ts +4 -4
  47. package/src/utils/ArrayUtil.ts +42 -42
  48. package/src/utils/LlmJson.ts +141 -141
  49. package/src/utils/MapUtil.ts +15 -15
  50. package/src/utils/NamingConvention.ts +205 -205
  51. package/src/utils/Singleton.ts +17 -17
  52. package/src/utils/StringUtil.ts +14 -14
  53. package/src/utils/dedent.ts +57 -57
  54. package/src/utils/index.ts +8 -8
  55. package/src/utils/internal/EndpointUtil.ts +44 -44
  56. package/src/utils/internal/JsonDescriptor.ts +70 -70
  57. package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -822
  58. package/src/utils/internal/coerceLlmArguments.ts +314 -297
  59. package/src/utils/internal/parseLenientJson.ts +894 -731
  60. package/src/utils/internal/stringifyValidationFailure.ts +415 -411
  61. package/src/validators/LlmTypeChecker.ts +402 -402
  62. package/src/validators/OpenApiTypeChecker.ts +297 -297
  63. package/src/validators/OpenApiV3TypeChecker.ts +70 -70
  64. package/src/validators/OpenApiV3_1TypeChecker.ts +86 -86
  65. package/src/validators/OpenApiValidator.ts +94 -94
  66. package/src/validators/SwaggerV2TypeChecker.ts +71 -71
  67. package/src/validators/functional/_isBigintString.ts +8 -8
  68. package/src/validators/functional/_isFormatByte.ts +7 -7
  69. package/src/validators/functional/_isFormatDate.ts +3 -3
  70. package/src/validators/functional/_isFormatDateTime.ts +4 -4
  71. package/src/validators/functional/_isFormatDuration.ts +4 -4
  72. package/src/validators/functional/_isFormatEmail.ts +4 -4
  73. package/src/validators/functional/_isFormatHostname.ts +4 -4
  74. package/src/validators/functional/_isFormatIdnEmail.ts +4 -4
  75. package/src/validators/functional/_isFormatIdnHostname.ts +4 -4
  76. package/src/validators/functional/_isFormatIpv4.ts +4 -4
  77. package/src/validators/functional/_isFormatIpv6.ts +4 -4
  78. package/src/validators/functional/_isFormatIri.ts +3 -3
  79. package/src/validators/functional/_isFormatIriReference.ts +4 -4
  80. package/src/validators/functional/_isFormatJsonPointer.ts +3 -3
  81. package/src/validators/functional/_isFormatPassword.ts +1 -1
  82. package/src/validators/functional/_isFormatRegex.ts +8 -8
  83. package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -4
  84. package/src/validators/functional/_isFormatTime.ts +4 -4
  85. package/src/validators/functional/_isFormatUri.ts +6 -6
  86. package/src/validators/functional/_isFormatUriReference.ts +5 -5
  87. package/src/validators/functional/_isFormatUriTemplate.ts +4 -4
  88. package/src/validators/functional/_isFormatUrl.ts +4 -4
  89. package/src/validators/functional/_isFormatUuid.ts +3 -3
  90. package/src/validators/functional/_isUniqueItems.ts +159 -159
  91. package/src/validators/index.ts +14 -14
  92. package/src/validators/internal/IOpenApiValidatorContext.ts +17 -17
  93. package/src/validators/internal/OpenApiArrayValidator.ts +49 -49
  94. package/src/validators/internal/OpenApiBooleanValidator.ts +11 -11
  95. package/src/validators/internal/OpenApiConstantValidator.ts +11 -11
  96. package/src/validators/internal/OpenApiIntegerValidator.ts +49 -49
  97. package/src/validators/internal/OpenApiNumberValidator.ts +48 -48
  98. package/src/validators/internal/OpenApiObjectValidator.ts +83 -83
  99. package/src/validators/internal/OpenApiOneOfValidator.ts +309 -309
  100. package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -124
  101. package/src/validators/internal/OpenApiStationValidator.ts +115 -115
  102. package/src/validators/internal/OpenApiStringValidator.ts +88 -88
  103. package/src/validators/internal/OpenApiTupleValidator.ts +55 -55
@@ -1,107 +1,107 @@
1
- /**
2
- * Error thrown when HTTP request fails with non-2xx status.
3
- *
4
- * `HttpError` is thrown by {@link HttpLlm.execute} and
5
- * {@link HttpMigration.execute} when the server returns a non-2xx status code.
6
- * Contains the full HTTP context: method, path, status, headers, and response
7
- * body.
8
- *
9
- * The response body is available via {@link message} (raw string) or
10
- * {@link toJSON} (parsed JSON). For non-throwing behavior, use
11
- * {@link HttpLlm.propagate} or {@link HttpMigration.propagate} instead.
12
- *
13
- * @author Jeongho Nam - https://github.com/samchon
14
- */
15
- export class HttpError extends Error {
16
- /** HTTP method used for the request. */
17
- public readonly method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD";
18
-
19
- /** Request path or URL. */
20
- public readonly path: string;
21
-
22
- /** HTTP status code from server. */
23
- public readonly status: number;
24
-
25
- /** Response headers from server. */
26
- public readonly headers: Record<string, string | string[]>;
27
-
28
- /** @internal */
29
- private body_: any = NOT_YET;
30
-
31
- /**
32
- * @param method HTTP method
33
- * @param path Request path or URL
34
- * @param status HTTP status code
35
- * @param headers Response headers
36
- * @param message Error message (response body)
37
- */
38
- public constructor(
39
- method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD",
40
- path: string,
41
- status: number,
42
- headers: Record<string, string | string[]>,
43
- message: string,
44
- ) {
45
- super(message);
46
- this.method = method;
47
- this.path = path;
48
- this.status = status;
49
- this.headers = headers;
50
-
51
- // INHERITANCE POLYFILL
52
- const proto: HttpError = new.target.prototype;
53
- if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
54
- else (this as any).__proto__ = proto;
55
- }
56
-
57
- /**
58
- * Serialize to JSON-compatible object.
59
- *
60
- * Lazily parses JSON message body on first call. If parsing fails, returns
61
- * the original string.
62
- *
63
- * @template T Expected response body type
64
- * @returns Structured HTTP error information
65
- */
66
- public toJSON<T>(): HttpError.IProps<T> {
67
- if (this.body_ === NOT_YET)
68
- try {
69
- this.body_ = JSON.parse(this.message);
70
- } catch {
71
- this.body_ = this.message;
72
- }
73
- return {
74
- method: this.method,
75
- path: this.path,
76
- status: this.status,
77
- headers: this.headers,
78
- message: this.body_,
79
- };
80
- }
81
- }
82
- export namespace HttpError {
83
- /**
84
- * JSON representation of HttpError.
85
- *
86
- * @template T Response body type
87
- */
88
- export interface IProps<T> {
89
- /** HTTP method. */
90
- method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD";
91
-
92
- /** Request path or URL. */
93
- path: string;
94
-
95
- /** HTTP status code. */
96
- status: number;
97
-
98
- /** Response headers. */
99
- headers: Record<string, string | string[]>;
100
-
101
- /** Response body (parsed JSON or original string). */
102
- message: T;
103
- }
104
- }
105
-
106
- /** @internal */
107
- const NOT_YET = {} as any;
1
+ /**
2
+ * Error thrown when HTTP request fails with non-2xx status.
3
+ *
4
+ * `HttpError` is thrown by {@link HttpLlm.execute} and
5
+ * {@link HttpMigration.execute} when the server returns a non-2xx status code.
6
+ * Contains the full HTTP context: method, path, status, headers, and response
7
+ * body.
8
+ *
9
+ * The response body is available via {@link message} (raw string) or
10
+ * {@link toJSON} (parsed JSON). For non-throwing behavior, use
11
+ * {@link HttpLlm.propagate} or {@link HttpMigration.propagate} instead.
12
+ *
13
+ * @author Jeongho Nam - https://github.com/samchon
14
+ */
15
+ export class HttpError extends Error {
16
+ /** HTTP method used for the request. */
17
+ public readonly method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD";
18
+
19
+ /** Request path or URL. */
20
+ public readonly path: string;
21
+
22
+ /** HTTP status code from server. */
23
+ public readonly status: number;
24
+
25
+ /** Response headers from server. */
26
+ public readonly headers: Record<string, string | string[]>;
27
+
28
+ /** @internal */
29
+ private body_: any = NOT_YET;
30
+
31
+ /**
32
+ * @param method HTTP method
33
+ * @param path Request path or URL
34
+ * @param status HTTP status code
35
+ * @param headers Response headers
36
+ * @param message Error message (response body)
37
+ */
38
+ public constructor(
39
+ method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD",
40
+ path: string,
41
+ status: number,
42
+ headers: Record<string, string | string[]>,
43
+ message: string,
44
+ ) {
45
+ super(message);
46
+ this.method = method;
47
+ this.path = path;
48
+ this.status = status;
49
+ this.headers = headers;
50
+
51
+ // INHERITANCE POLYFILL
52
+ const proto: HttpError = new.target.prototype;
53
+ if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
54
+ else (this as any).__proto__ = proto;
55
+ }
56
+
57
+ /**
58
+ * Serialize to JSON-compatible object.
59
+ *
60
+ * Lazily parses JSON message body on first call. If parsing fails, returns
61
+ * the original string.
62
+ *
63
+ * @template T Expected response body type
64
+ * @returns Structured HTTP error information
65
+ */
66
+ public toJSON<T>(): HttpError.IProps<T> {
67
+ if (this.body_ === NOT_YET)
68
+ try {
69
+ this.body_ = JSON.parse(this.message);
70
+ } catch {
71
+ this.body_ = this.message;
72
+ }
73
+ return {
74
+ method: this.method,
75
+ path: this.path,
76
+ status: this.status,
77
+ headers: this.headers,
78
+ message: this.body_,
79
+ };
80
+ }
81
+ }
82
+ export namespace HttpError {
83
+ /**
84
+ * JSON representation of HttpError.
85
+ *
86
+ * @template T Response body type
87
+ */
88
+ export interface IProps<T> {
89
+ /** HTTP method. */
90
+ method: "GET" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD";
91
+
92
+ /** Request path or URL. */
93
+ path: string;
94
+
95
+ /** HTTP status code. */
96
+ status: number;
97
+
98
+ /** Response headers. */
99
+ headers: Record<string, string | string[]>;
100
+
101
+ /** Response body (parsed JSON or original string). */
102
+ message: T;
103
+ }
104
+ }
105
+
106
+ /** @internal */
107
+ const NOT_YET = {} as any;
@@ -1,167 +1,167 @@
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
- reference: props.config?.reference ?? true,
117
- strict: props.config?.strict ?? false,
118
- maxLength: props.config?.maxLength ?? 64,
119
- equals: props.config?.equals ?? false,
120
- },
121
- });
122
- };
123
-
124
- /* -----------------------------------------------------------
125
- FETCHERS
126
- ----------------------------------------------------------- */
127
- /** Properties for LLM function call. */
128
- export interface IFetchProps {
129
- /** LLM function calling application. */
130
- application: IHttpLlmApplication;
131
-
132
- /** Function to call. */
133
- function: IHttpLlmFunction;
134
-
135
- /** HTTP connection info. */
136
- connection: IHttpConnection;
137
-
138
- /** Function arguments. */
139
- input: object;
140
- }
141
-
142
- /**
143
- * Execute LLM function call.
144
- *
145
- * Calls API endpoint and returns response body. Throws {@link HttpError} on
146
- * non-2xx status.
147
- *
148
- * @param props Function call properties
149
- * @returns Response body
150
- * @throws HttpError on non-2xx status
151
- */
152
- export const execute = (props: IFetchProps): Promise<unknown> =>
153
- HttpLlmFunctionFetcher.execute(props);
154
-
155
- /**
156
- * Propagate LLM function call.
157
- *
158
- * Calls API endpoint and returns full response including non-2xx. Use when
159
- * you need to handle error responses yourself.
160
- *
161
- * @param props Function call properties
162
- * @returns Full HTTP response
163
- * @throws Error only on connection failure
164
- */
165
- export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>
166
- HttpLlmFunctionFetcher.propagate(props);
167
- }
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
+ reference: props.config?.reference ?? true,
117
+ strict: props.config?.strict ?? false,
118
+ maxLength: props.config?.maxLength ?? 64,
119
+ equals: props.config?.equals ?? false,
120
+ },
121
+ });
122
+ };
123
+
124
+ /* -----------------------------------------------------------
125
+ FETCHERS
126
+ ----------------------------------------------------------- */
127
+ /** Properties for LLM function call. */
128
+ export interface IFetchProps {
129
+ /** LLM function calling application. */
130
+ application: IHttpLlmApplication;
131
+
132
+ /** Function to call. */
133
+ function: IHttpLlmFunction;
134
+
135
+ /** HTTP connection info. */
136
+ connection: IHttpConnection;
137
+
138
+ /** Function arguments. */
139
+ input: object;
140
+ }
141
+
142
+ /**
143
+ * Execute LLM function call.
144
+ *
145
+ * Calls API endpoint and returns response body. Throws {@link HttpError} on
146
+ * non-2xx status.
147
+ *
148
+ * @param props Function call properties
149
+ * @returns Response body
150
+ * @throws HttpError on non-2xx status
151
+ */
152
+ export const execute = (props: IFetchProps): Promise<unknown> =>
153
+ HttpLlmFunctionFetcher.execute(props);
154
+
155
+ /**
156
+ * Propagate LLM function call.
157
+ *
158
+ * Calls API endpoint and returns full response including non-2xx. Use when
159
+ * you need to handle error responses yourself.
160
+ *
161
+ * @param props Function call properties
162
+ * @returns Full HTTP response
163
+ * @throws Error only on connection failure
164
+ */
165
+ export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>
166
+ HttpLlmFunctionFetcher.propagate(props);
167
+ }