@typia/vercel 12.1.0-dev.20260325 → 13.0.0-dev.20260426
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.
- package/LICENSE +21 -21
- package/README.md +111 -111
- package/lib/_virtual/VercelParameterConverter.mjs +4 -0
- package/lib/_virtual/VercelParameterConverter.mjs.map +1 -0
- package/lib/_virtual/VercelToolsRegistrar.mjs +4 -0
- package/lib/_virtual/VercelToolsRegistrar.mjs.map +1 -0
- package/lib/_virtual/_commonjsHelpers.mjs +6 -0
- package/lib/_virtual/_commonjsHelpers.mjs.map +1 -0
- package/lib/_virtual/index.mjs +4 -0
- package/lib/_virtual/index.mjs.map +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +5 -125
- package/lib/index.mjs.map +1 -1
- package/lib/index2.mjs +142 -0
- package/lib/index2.mjs.map +1 -0
- package/lib/internal/VercelParameterConverter.js.map +1 -1
- package/lib/internal/VercelParameterConverter.mjs +5 -6
- package/lib/internal/VercelParameterConverter.mjs.map +1 -1
- package/lib/internal/VercelParameterConverter2.mjs +21 -0
- package/lib/internal/VercelParameterConverter2.mjs.map +1 -0
- package/lib/internal/VercelToolsRegistrar.js.map +1 -1
- package/lib/internal/VercelToolsRegistrar.mjs +5 -123
- package/lib/internal/VercelToolsRegistrar.mjs.map +1 -1
- package/lib/internal/VercelToolsRegistrar2.mjs +151 -0
- package/lib/internal/VercelToolsRegistrar2.mjs.map +1 -0
- package/package.json +8 -9
- package/src/index.ts +155 -155
- package/src/internal/VercelParameterConverter.ts +8 -8
- package/src/internal/VercelToolsRegistrar.ts +166 -166
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Jeongho Nam
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Jeongho Nam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
# `@typia/vercel`
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
[](https://github.com/samchon/typia/blob/master/LICENSE)
|
|
6
|
-
[](https://www.npmjs.com/package/typia)
|
|
7
|
-
[](https://www.npmjs.com/package/typia)
|
|
8
|
-
[](https://github.com/samchon/typia/actions?query=workflow%3Atest)
|
|
9
|
-
[](https://typia.io/docs/)
|
|
10
|
-
[](https://gurubase.io/g/typia)
|
|
11
|
-
[](https://discord.gg/E94XhzrUCZ)
|
|
12
|
-
|
|
13
|
-
[Vercel AI SDK](https://github.com/vercel/ai) integration for [`typia`](https://github.com/samchon/typia).
|
|
14
|
-
|
|
15
|
-
Converts typia controllers to Vercel AI SDK tools compatible with OpenAI, Anthropic, Google, and other LLM providers.
|
|
16
|
-
|
|
17
|
-
## Setup
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install @typia/vercel ai
|
|
21
|
-
npm install typia
|
|
22
|
-
npx typia setup
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Usage
|
|
26
|
-
|
|
27
|
-
### From TypeScript class
|
|
28
|
-
|
|
29
|
-
```typescript
|
|
30
|
-
import { openai } from "@ai-sdk/openai";
|
|
31
|
-
import { toVercelTools } from "@typia/vercel";
|
|
32
|
-
import { generateText, GenerateTextResult, Tool } from "ai";
|
|
33
|
-
import typia from "typia";
|
|
34
|
-
|
|
35
|
-
const tools: Record<string, Tool> = toVercelTools({
|
|
36
|
-
controllers: [
|
|
37
|
-
typia.llm.controller<Calculator>("Calculator", new Calculator()),
|
|
38
|
-
],
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const result: GenerateTextResult = await generateText({
|
|
42
|
-
model: openai("gpt-4o"),
|
|
43
|
-
prompt: "What is 10 + 5?",
|
|
44
|
-
tools,
|
|
45
|
-
});
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### From OpenAPI document
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
import { toVercelTools } from "@typia/vercel";
|
|
52
|
-
import { HttpLlm } from "@typia/utils";
|
|
53
|
-
import { Tool } from "ai";
|
|
54
|
-
|
|
55
|
-
const tools: Record<string, Tool> = toVercelTools({
|
|
56
|
-
controllers: [
|
|
57
|
-
HttpLlm.controller({
|
|
58
|
-
name: "petStore",
|
|
59
|
-
document: yourOpenApiDocument,
|
|
60
|
-
connection: { host: "https://api.example.com" },
|
|
61
|
-
}),
|
|
62
|
-
],
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Structured Output
|
|
67
|
-
|
|
68
|
-
Use `typia.llm.parameters<T>()` with Vercel's `jsonSchema()` to generate structured output with validation:
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
import { openai } from "@ai-sdk/openai";
|
|
72
|
-
import { generateObject, jsonSchema } from "ai";
|
|
73
|
-
import { dedent, LlmJson } from "@typia/utils";
|
|
74
|
-
import typia, { tags } from "typia";
|
|
75
|
-
|
|
76
|
-
interface IMember {
|
|
77
|
-
email: string & tags.Format<"email">;
|
|
78
|
-
name: string;
|
|
79
|
-
age: number & tags.Minimum<0> & tags.Maximum<100>;
|
|
80
|
-
hobbies: string[];
|
|
81
|
-
joined_at: string & tags.Format<"date">;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const { object } = await generateObject({
|
|
85
|
-
model: openai("gpt-4o"),
|
|
86
|
-
schema: jsonSchema<IMember>(typia.llm.parameters<IMember>(), {
|
|
87
|
-
validate: (value) => {
|
|
88
|
-
const result = typia.validate<IMember>(value);
|
|
89
|
-
if (result.success) return { success: true, value: result.data };
|
|
90
|
-
return {
|
|
91
|
-
success: false,
|
|
92
|
-
error: new Error(LlmJson.stringify(result)),
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
96
|
-
prompt: dedent`
|
|
97
|
-
I am a new member of the community.
|
|
98
|
-
|
|
99
|
-
My name is John Doe, and I am 25 years old.
|
|
100
|
-
I like playing basketball and reading books,
|
|
101
|
-
and joined to this community at 2022-01-01.
|
|
102
|
-
`,
|
|
103
|
-
});
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Features
|
|
107
|
-
|
|
108
|
-
- No manual schema definition — generates everything from TypeScript types or OpenAPI
|
|
109
|
-
- Automatic argument validation with LLM-friendly error feedback
|
|
110
|
-
- Supports both class-based (`typia.llm.controller`) and HTTP-based (`HttpLlm.controller`) controllers
|
|
111
|
-
- Works with any LLM provider supported by Vercel AI SDK
|
|
1
|
+
# `@typia/vercel`
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://github.com/samchon/typia/blob/master/LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/typia)
|
|
7
|
+
[](https://www.npmjs.com/package/typia)
|
|
8
|
+
[](https://github.com/samchon/typia/actions?query=workflow%3Atest)
|
|
9
|
+
[](https://typia.io/docs/)
|
|
10
|
+
[](https://gurubase.io/g/typia)
|
|
11
|
+
[](https://discord.gg/E94XhzrUCZ)
|
|
12
|
+
|
|
13
|
+
[Vercel AI SDK](https://github.com/vercel/ai) integration for [`typia`](https://github.com/samchon/typia).
|
|
14
|
+
|
|
15
|
+
Converts typia controllers to Vercel AI SDK tools compatible with OpenAI, Anthropic, Google, and other LLM providers.
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @typia/vercel ai
|
|
21
|
+
npm install typia
|
|
22
|
+
npx typia setup
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### From TypeScript class
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { openai } from "@ai-sdk/openai";
|
|
31
|
+
import { toVercelTools } from "@typia/vercel";
|
|
32
|
+
import { generateText, GenerateTextResult, Tool } from "ai";
|
|
33
|
+
import typia from "typia";
|
|
34
|
+
|
|
35
|
+
const tools: Record<string, Tool> = toVercelTools({
|
|
36
|
+
controllers: [
|
|
37
|
+
typia.llm.controller<Calculator>("Calculator", new Calculator()),
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const result: GenerateTextResult = await generateText({
|
|
42
|
+
model: openai("gpt-4o"),
|
|
43
|
+
prompt: "What is 10 + 5?",
|
|
44
|
+
tools,
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### From OpenAPI document
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { toVercelTools } from "@typia/vercel";
|
|
52
|
+
import { HttpLlm } from "@typia/utils";
|
|
53
|
+
import { Tool } from "ai";
|
|
54
|
+
|
|
55
|
+
const tools: Record<string, Tool> = toVercelTools({
|
|
56
|
+
controllers: [
|
|
57
|
+
HttpLlm.controller({
|
|
58
|
+
name: "petStore",
|
|
59
|
+
document: yourOpenApiDocument,
|
|
60
|
+
connection: { host: "https://api.example.com" },
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Structured Output
|
|
67
|
+
|
|
68
|
+
Use `typia.llm.parameters<T>()` with Vercel's `jsonSchema()` to generate structured output with validation:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { openai } from "@ai-sdk/openai";
|
|
72
|
+
import { generateObject, jsonSchema } from "ai";
|
|
73
|
+
import { dedent, LlmJson } from "@typia/utils";
|
|
74
|
+
import typia, { tags } from "typia";
|
|
75
|
+
|
|
76
|
+
interface IMember {
|
|
77
|
+
email: string & tags.Format<"email">;
|
|
78
|
+
name: string;
|
|
79
|
+
age: number & tags.Minimum<0> & tags.Maximum<100>;
|
|
80
|
+
hobbies: string[];
|
|
81
|
+
joined_at: string & tags.Format<"date">;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const { object } = await generateObject({
|
|
85
|
+
model: openai("gpt-4o"),
|
|
86
|
+
schema: jsonSchema<IMember>(typia.llm.parameters<IMember>(), {
|
|
87
|
+
validate: (value) => {
|
|
88
|
+
const result = typia.validate<IMember>(value);
|
|
89
|
+
if (result.success) return { success: true, value: result.data };
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
error: new Error(LlmJson.stringify(result)),
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
prompt: dedent`
|
|
97
|
+
I am a new member of the community.
|
|
98
|
+
|
|
99
|
+
My name is John Doe, and I am 25 years old.
|
|
100
|
+
I like playing basketball and reading books,
|
|
101
|
+
and joined to this community at 2022-01-01.
|
|
102
|
+
`,
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Features
|
|
107
|
+
|
|
108
|
+
- No manual schema definition — generates everything from TypeScript types or OpenAPI
|
|
109
|
+
- Automatic argument validation with LLM-friendly error feedback
|
|
110
|
+
- Supports both class-based (`typia.llm.controller`) and HTTP-based (`HttpLlm.controller`) controllers
|
|
111
|
+
- Works with any LLM provider supported by Vercel AI SDK
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VercelParameterConverter.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VercelToolsRegistrar.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_commonjsHelpers.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAOA,kFAA+E;AAC/E,0EAAuE;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,uBAA8B,KAoB7B;IACC,OAAO,2CAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBACE,UAAkC;IAElC,OAAO,mDAAwB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACtD,CAAC"}
|
package/lib/index.mjs
CHANGED
|
@@ -1,128 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getDefaultExportFromCjs } from './_virtual/_commonjsHelpers.mjs';
|
|
2
|
+
import { __require as requireLib } from './index2.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* Transforms TypeScript class methods via `typia.llm.controller<Class>()` or
|
|
8
|
-
* OpenAPI operations via `HttpLlm.controller()` into Vercel AI SDK tools that
|
|
9
|
-
* can be used with any LLM provider (OpenAI, Anthropic, Google, etc.).
|
|
10
|
-
*
|
|
11
|
-
* Every tool call is validated by typia. If the LLM provides invalid arguments,
|
|
12
|
-
* returns a validation error formatted by {@link LlmJson.stringify} so the LLM
|
|
13
|
-
* can auto-correct in the next turn.
|
|
14
|
-
*
|
|
15
|
-
* ## Example with OpenAI
|
|
16
|
-
*
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { generateText } from "ai";
|
|
19
|
-
* import { openai } from "@ai-sdk/openai";
|
|
20
|
-
* import typia from "typia";
|
|
21
|
-
* import { toVercelTools } from "@typia/vercel";
|
|
22
|
-
*
|
|
23
|
-
* class Calculator {
|
|
24
|
-
* /** Add two numbers together. */
|
|
25
|
-
* add(props: { a: number; b: number }): { value: number } {
|
|
26
|
-
* return { value: props.a + props.b };
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
*
|
|
30
|
-
* const controller = typia.llm.controller<Calculator>("calc", new Calculator());
|
|
31
|
-
* const tools = toVercelTools({ controllers: [controller] });
|
|
32
|
-
*
|
|
33
|
-
* const result = await generateText({
|
|
34
|
-
* model: openai("gpt-4o"),
|
|
35
|
-
* tools,
|
|
36
|
-
* prompt: "What is 15 + 27?",
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* ## Example with Anthropic
|
|
41
|
-
*
|
|
42
|
-
* ```typescript
|
|
43
|
-
* import { anthropic } from "@ai-sdk/anthropic";
|
|
44
|
-
* import { toVercelTools } from "@typia/vercel";
|
|
45
|
-
* import { generateText } from "ai";
|
|
46
|
-
*
|
|
47
|
-
* const result = await generateText({
|
|
48
|
-
* model: anthropic("claude-sonnet-4-20250514"),
|
|
49
|
-
* tools: toVercelTools({ controllers: [controller] }),
|
|
50
|
-
* prompt: "Calculate 100 * 50",
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* ## Example with HTTP Controller (OpenAPI)
|
|
55
|
-
*
|
|
56
|
-
* ```typescript
|
|
57
|
-
* import { openai } from "@ai-sdk/openai";
|
|
58
|
-
* import { HttpLlm } from "@typia/utils";
|
|
59
|
-
* import { toVercelTools } from "@typia/vercel";
|
|
60
|
-
* import { generateText } from "ai";
|
|
61
|
-
*
|
|
62
|
-
* const controller = HttpLlm.controller({
|
|
63
|
-
* name: "shopping",
|
|
64
|
-
* document: await fetch("https://api.example.com/swagger.json").then(
|
|
65
|
-
* (r) => r.json(),
|
|
66
|
-
* ),
|
|
67
|
-
* connection: { host: "https://api.example.com" },
|
|
68
|
-
* });
|
|
69
|
-
*
|
|
70
|
-
* const result = await generateText({
|
|
71
|
-
* model: openai("gpt-4o"),
|
|
72
|
-
* tools: toVercelTools({ controllers: [controller] }),
|
|
73
|
-
* prompt: "Search for laptops under $1000",
|
|
74
|
-
* });
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
78
|
-
* @param props Conversion properties
|
|
79
|
-
* @returns Record of Vercel AI SDK Tools keyed by tool name
|
|
80
|
-
*/
|
|
81
|
-
function toVercelTools(props) {
|
|
82
|
-
return VercelToolsRegistrar.convert(props);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Convert LLM parameters schema to Vercel AI SDK schema format.
|
|
86
|
-
*
|
|
87
|
-
* Transforms {@link ILlmSchema.IParameters} into Vercel AI SDK's `Schema` type
|
|
88
|
-
* for use with `generateObject()`. Use with `typia.llm.structuredOutput<T>()`
|
|
89
|
-
* or `typia.llm.parameters<T>()`.
|
|
90
|
-
*
|
|
91
|
-
* ## Example
|
|
92
|
-
*
|
|
93
|
-
* ```typescript
|
|
94
|
-
* import { openai } from "@ai-sdk/openai";
|
|
95
|
-
* import { toVercelSchema } from "@typia/vercel";
|
|
96
|
-
* import { generateObject } from "ai";
|
|
97
|
-
* import typia from "typia";
|
|
98
|
-
*
|
|
99
|
-
* interface IMember {
|
|
100
|
-
* name: string;
|
|
101
|
-
* age: number;
|
|
102
|
-
* }
|
|
103
|
-
*
|
|
104
|
-
* const output = typia.llm.structuredOutput<IMember>();
|
|
105
|
-
* const schema = toVercelSchema(output.parameters);
|
|
106
|
-
*
|
|
107
|
-
* const { object } = await generateObject({
|
|
108
|
-
* model: openai("gpt-4o"),
|
|
109
|
-
* schema,
|
|
110
|
-
* prompt: "Generate a member named John who is 30 years old",
|
|
111
|
-
* });
|
|
112
|
-
*
|
|
113
|
-
* const coerced = output.coerce(object);
|
|
114
|
-
* const result = output.validate(coerced);
|
|
115
|
-
* ```
|
|
116
|
-
*
|
|
117
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
118
|
-
* @param parameters LLM parameters schema from
|
|
119
|
-
* `typia.llm.structuredOutput<T>().parameters` or
|
|
120
|
-
* `typia.llm.parameters<T>()`
|
|
121
|
-
* @returns Vercel AI SDK Schema for `generateObject()`
|
|
122
|
-
*/
|
|
123
|
-
function toVercelSchema(parameters) {
|
|
124
|
-
return VercelParameterConverter.convert(parameters);
|
|
125
|
-
}
|
|
4
|
+
var libExports = requireLib();
|
|
5
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(libExports);
|
|
126
6
|
|
|
127
|
-
export {
|
|
7
|
+
export { index as default };
|
|
128
8
|
//# sourceMappingURL=index.mjs.map
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["index.js?commonjs-entry"],"sourcesContent":["import { getDefaultExportFromCjs } from \"\u0000commonjsHelpers.js\";\nimport { __require as requireLib } from \"/home/samchon/github/samchon/typia@next/packages/vercel/lib/index.js\";\nvar libExports = requireLib();\nexport { libExports as __moduleExports };\nexport default /*@__PURE__*/getDefaultExportFromCjs(libExports);"],"names":[],"mappings":";;;AAEA,IAAI,UAAU,GAAG,UAAU,EAAE;AAE7B,YAAe,aAAa,uBAAuB,CAAC,UAAU,CAAC;;;;"}
|
package/lib/index2.mjs
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { __exports as lib } from './_virtual/index.mjs';
|
|
2
|
+
import { __require as requireVercelParameterConverter } from './internal/VercelParameterConverter2.mjs';
|
|
3
|
+
import { __require as requireVercelToolsRegistrar } from './internal/VercelToolsRegistrar2.mjs';
|
|
4
|
+
|
|
5
|
+
var hasRequiredLib;
|
|
6
|
+
|
|
7
|
+
function requireLib () {
|
|
8
|
+
if (hasRequiredLib) return lib;
|
|
9
|
+
hasRequiredLib = 1;
|
|
10
|
+
Object.defineProperty(lib, "__esModule", { value: true });
|
|
11
|
+
lib.toVercelTools = toVercelTools;
|
|
12
|
+
lib.toVercelSchema = toVercelSchema;
|
|
13
|
+
const VercelParameterConverter_1 = requireVercelParameterConverter();
|
|
14
|
+
const VercelToolsRegistrar_1 = requireVercelToolsRegistrar();
|
|
15
|
+
/**
|
|
16
|
+
* Convert typia controllers to Vercel AI SDK tools.
|
|
17
|
+
*
|
|
18
|
+
* Transforms TypeScript class methods via `typia.llm.controller<Class>()` or
|
|
19
|
+
* OpenAPI operations via `HttpLlm.controller()` into Vercel AI SDK tools that
|
|
20
|
+
* can be used with any LLM provider (OpenAI, Anthropic, Google, etc.).
|
|
21
|
+
*
|
|
22
|
+
* Every tool call is validated by typia. If the LLM provides invalid arguments,
|
|
23
|
+
* returns a validation error formatted by {@link LlmJson.stringify} so the LLM
|
|
24
|
+
* can auto-correct in the next turn.
|
|
25
|
+
*
|
|
26
|
+
* ## Example with OpenAI
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { generateText } from "ai";
|
|
30
|
+
* import { openai } from "@ai-sdk/openai";
|
|
31
|
+
* import typia from "typia";
|
|
32
|
+
* import { toVercelTools } from "@typia/vercel";
|
|
33
|
+
*
|
|
34
|
+
* class Calculator {
|
|
35
|
+
* /** Add two numbers together. */
|
|
36
|
+
* add(props: { a: number; b: number }): { value: number } {
|
|
37
|
+
* return { value: props.a + props.b };
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* const controller = typia.llm.controller<Calculator>("calc", new Calculator());
|
|
42
|
+
* const tools = toVercelTools({ controllers: [controller] });
|
|
43
|
+
*
|
|
44
|
+
* const result = await generateText({
|
|
45
|
+
* model: openai("gpt-4o"),
|
|
46
|
+
* tools,
|
|
47
|
+
* prompt: "What is 15 + 27?",
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* ## Example with Anthropic
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { anthropic } from "@ai-sdk/anthropic";
|
|
55
|
+
* import { toVercelTools } from "@typia/vercel";
|
|
56
|
+
* import { generateText } from "ai";
|
|
57
|
+
*
|
|
58
|
+
* const result = await generateText({
|
|
59
|
+
* model: anthropic("claude-sonnet-4-20250514"),
|
|
60
|
+
* tools: toVercelTools({ controllers: [controller] }),
|
|
61
|
+
* prompt: "Calculate 100 * 50",
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* ## Example with HTTP Controller (OpenAPI)
|
|
66
|
+
*
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import { openai } from "@ai-sdk/openai";
|
|
69
|
+
* import { HttpLlm } from "@typia/utils";
|
|
70
|
+
* import { toVercelTools } from "@typia/vercel";
|
|
71
|
+
* import { generateText } from "ai";
|
|
72
|
+
*
|
|
73
|
+
* const controller = HttpLlm.controller({
|
|
74
|
+
* name: "shopping",
|
|
75
|
+
* document: await fetch("https://api.example.com/swagger.json").then(
|
|
76
|
+
* (r) => r.json(),
|
|
77
|
+
* ),
|
|
78
|
+
* connection: { host: "https://api.example.com" },
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* const result = await generateText({
|
|
82
|
+
* model: openai("gpt-4o"),
|
|
83
|
+
* tools: toVercelTools({ controllers: [controller] }),
|
|
84
|
+
* prompt: "Search for laptops under $1000",
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
89
|
+
* @param props Conversion properties
|
|
90
|
+
* @returns Record of Vercel AI SDK Tools keyed by tool name
|
|
91
|
+
*/
|
|
92
|
+
function toVercelTools(props) {
|
|
93
|
+
return VercelToolsRegistrar_1.VercelToolsRegistrar.convert(props);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert LLM parameters schema to Vercel AI SDK schema format.
|
|
97
|
+
*
|
|
98
|
+
* Transforms {@link ILlmSchema.IParameters} into Vercel AI SDK's `Schema` type
|
|
99
|
+
* for use with `generateObject()`. Use with `typia.llm.structuredOutput<T>()`
|
|
100
|
+
* or `typia.llm.parameters<T>()`.
|
|
101
|
+
*
|
|
102
|
+
* ## Example
|
|
103
|
+
*
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { openai } from "@ai-sdk/openai";
|
|
106
|
+
* import { toVercelSchema } from "@typia/vercel";
|
|
107
|
+
* import { generateObject } from "ai";
|
|
108
|
+
* import typia from "typia";
|
|
109
|
+
*
|
|
110
|
+
* interface IMember {
|
|
111
|
+
* name: string;
|
|
112
|
+
* age: number;
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
115
|
+
* const output = typia.llm.structuredOutput<IMember>();
|
|
116
|
+
* const schema = toVercelSchema(output.parameters);
|
|
117
|
+
*
|
|
118
|
+
* const { object } = await generateObject({
|
|
119
|
+
* model: openai("gpt-4o"),
|
|
120
|
+
* schema,
|
|
121
|
+
* prompt: "Generate a member named John who is 30 years old",
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* const coerced = output.coerce(object);
|
|
125
|
+
* const result = output.validate(coerced);
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
129
|
+
* @param parameters LLM parameters schema from
|
|
130
|
+
* `typia.llm.structuredOutput<T>().parameters` or
|
|
131
|
+
* `typia.llm.parameters<T>()`
|
|
132
|
+
* @returns Vercel AI SDK Schema for `generateObject()`
|
|
133
|
+
*/
|
|
134
|
+
function toVercelSchema(parameters) {
|
|
135
|
+
return VercelParameterConverter_1.VercelParameterConverter.convert(parameters);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return lib;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { requireLib as __require };
|
|
142
|
+
//# sourceMappingURL=index2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index2.mjs","sources":["index.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.toVercelTools = toVercelTools;\nexports.toVercelSchema = toVercelSchema;\nconst VercelParameterConverter_1 = require(\"./internal/VercelParameterConverter\");\nconst VercelToolsRegistrar_1 = require(\"./internal/VercelToolsRegistrar\");\n/**\n * Convert typia controllers to Vercel AI SDK tools.\n *\n * Transforms TypeScript class methods via `typia.llm.controller<Class>()` or\n * OpenAPI operations via `HttpLlm.controller()` into Vercel AI SDK tools that\n * can be used with any LLM provider (OpenAI, Anthropic, Google, etc.).\n *\n * Every tool call is validated by typia. If the LLM provides invalid arguments,\n * returns a validation error formatted by {@link LlmJson.stringify} so the LLM\n * can auto-correct in the next turn.\n *\n * ## Example with OpenAI\n *\n * ```typescript\n * import { generateText } from \"ai\";\n * import { openai } from \"@ai-sdk/openai\";\n * import typia from \"typia\";\n * import { toVercelTools } from \"@typia/vercel\";\n *\n * class Calculator {\n * /** Add two numbers together. */\n * add(props: { a: number; b: number }): { value: number } {\n * return { value: props.a + props.b };\n * }\n * }\n *\n * const controller = typia.llm.controller<Calculator>(\"calc\", new Calculator());\n * const tools = toVercelTools({ controllers: [controller] });\n *\n * const result = await generateText({\n * model: openai(\"gpt-4o\"),\n * tools,\n * prompt: \"What is 15 + 27?\",\n * });\n * ```\n *\n * ## Example with Anthropic\n *\n * ```typescript\n * import { anthropic } from \"@ai-sdk/anthropic\";\n * import { toVercelTools } from \"@typia/vercel\";\n * import { generateText } from \"ai\";\n *\n * const result = await generateText({\n * model: anthropic(\"claude-sonnet-4-20250514\"),\n * tools: toVercelTools({ controllers: [controller] }),\n * prompt: \"Calculate 100 * 50\",\n * });\n * ```\n *\n * ## Example with HTTP Controller (OpenAPI)\n *\n * ```typescript\n * import { openai } from \"@ai-sdk/openai\";\n * import { HttpLlm } from \"@typia/utils\";\n * import { toVercelTools } from \"@typia/vercel\";\n * import { generateText } from \"ai\";\n *\n * const controller = HttpLlm.controller({\n * name: \"shopping\",\n * document: await fetch(\"https://api.example.com/swagger.json\").then(\n * (r) => r.json(),\n * ),\n * connection: { host: \"https://api.example.com\" },\n * });\n *\n * const result = await generateText({\n * model: openai(\"gpt-4o\"),\n * tools: toVercelTools({ controllers: [controller] }),\n * prompt: \"Search for laptops under $1000\",\n * });\n * ```\n *\n * @author Jeongho Nam - https://github.com/samchon\n * @param props Conversion properties\n * @returns Record of Vercel AI SDK Tools keyed by tool name\n */\nfunction toVercelTools(props) {\n return VercelToolsRegistrar_1.VercelToolsRegistrar.convert(props);\n}\n/**\n * Convert LLM parameters schema to Vercel AI SDK schema format.\n *\n * Transforms {@link ILlmSchema.IParameters} into Vercel AI SDK's `Schema` type\n * for use with `generateObject()`. Use with `typia.llm.structuredOutput<T>()`\n * or `typia.llm.parameters<T>()`.\n *\n * ## Example\n *\n * ```typescript\n * import { openai } from \"@ai-sdk/openai\";\n * import { toVercelSchema } from \"@typia/vercel\";\n * import { generateObject } from \"ai\";\n * import typia from \"typia\";\n *\n * interface IMember {\n * name: string;\n * age: number;\n * }\n *\n * const output = typia.llm.structuredOutput<IMember>();\n * const schema = toVercelSchema(output.parameters);\n *\n * const { object } = await generateObject({\n * model: openai(\"gpt-4o\"),\n * schema,\n * prompt: \"Generate a member named John who is 30 years old\",\n * });\n *\n * const coerced = output.coerce(object);\n * const result = output.validate(coerced);\n * ```\n *\n * @author Jeongho Nam - https://github.com/samchon\n * @param parameters LLM parameters schema from\n * `typia.llm.structuredOutput<T>().parameters` or\n * `typia.llm.parameters<T>()`\n * @returns Vercel AI SDK Schema for `generateObject()`\n */\nfunction toVercelSchema(parameters) {\n return VercelParameterConverter_1.VercelParameterConverter.convert(parameters);\n}\n//# sourceMappingURL=index.js.map"],"names":["require$$0","require$$1"],"mappings":";;;;;;;;;AACA,CAAA,MAAM,CAAC,cAAc,CAAC,GAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,CAAA,GAAA,CAAA,aAAqB,GAAG,aAAa;AACrC,CAAA,GAAA,CAAA,cAAsB,GAAG,cAAc;CACvC,MAAM,0BAA0B,GAAGA,+BAAA,EAA8C;CACjF,MAAM,sBAAsB,GAAGC,2BAAA,EAA0C;AACzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;CACA,SAAS,aAAa,CAAC,KAAK,EAAE;KAC1B,OAAO,sBAAsB,CAAC,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC;AACrE,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;CACA,SAAS,cAAc,CAAC,UAAU,EAAE;KAChC,OAAO,0BAA0B,CAAC,wBAAwB,CAAC,OAAO,CAAC,UAAU,CAAC;AAClF,CAAA;AACA;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VercelParameterConverter.js","sourceRoot":"","sources":["../../src/internal/VercelParameterConverter.ts"],"names":[],"mappings":";;;AACA,2BAAwC;AAGxC,IAAiB,wBAAwB,CAGxC;AAHD,WAAiB,wBAAwB;IAC1B,gCAAO,GAAG,CAAC,UAAkC,EAAkB,EAAE,CAC5E,IAAA,eAAU,EAAS,UAAyB,CAAC,CAAC;AAClD,CAAC,EAHgB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"VercelParameterConverter.js","sourceRoot":"","sources":["../../src/internal/VercelParameterConverter.ts"],"names":[],"mappings":";;;AACA,2BAAwC;AAGxC,IAAiB,wBAAwB,CAGxC;AAHD,WAAiB,wBAAwB;IAC1B,gCAAO,GAAG,CAAC,UAAkC,EAAkB,EAAE,CAC5E,IAAA,eAAU,EAAS,UAAyB,CAAC,CAAC;AAClD,CAAC,EAHgB,wBAAwB,aAAxB,wBAAwB,GAAxB,wBAAwB,QAGxC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDefaultExportFromCjs } from '../_virtual/_commonjsHelpers.mjs';
|
|
2
|
+
import { __require as requireVercelParameterConverter } from './VercelParameterConverter2.mjs';
|
|
2
3
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
VercelParameterConverter.convert = (parameters) => jsonSchema(parameters);
|
|
6
|
-
})(VercelParameterConverter || (VercelParameterConverter = {}));
|
|
4
|
+
var VercelParameterConverterExports = requireVercelParameterConverter();
|
|
5
|
+
var VercelParameterConverter = /*@__PURE__*/getDefaultExportFromCjs(VercelParameterConverterExports);
|
|
7
6
|
|
|
8
|
-
export { VercelParameterConverter };
|
|
7
|
+
export { VercelParameterConverter as default };
|
|
9
8
|
//# sourceMappingURL=VercelParameterConverter.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VercelParameterConverter.mjs","sources":["
|
|
1
|
+
{"version":3,"file":"VercelParameterConverter.mjs","sources":["VercelParameterConverter.js?commonjs-entry"],"sourcesContent":["import { getDefaultExportFromCjs } from \"\u0000commonjsHelpers.js\";\nimport { __require as requireVercelParameterConverter } from \"/home/samchon/github/samchon/typia@next/packages/vercel/lib/internal/VercelParameterConverter.js\";\nvar VercelParameterConverterExports = requireVercelParameterConverter();\nexport { VercelParameterConverterExports as __moduleExports };\nexport default /*@__PURE__*/getDefaultExportFromCjs(VercelParameterConverterExports);"],"names":[],"mappings":";;;AAEA,IAAI,+BAA+B,GAAG,+BAA+B,EAAE;AAEvE,+BAAe,aAAa,uBAAuB,CAAC,+BAA+B,CAAC;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { __exports as VercelParameterConverter } from '../_virtual/VercelParameterConverter.mjs';
|
|
2
|
+
import require$$0 from 'ai';
|
|
3
|
+
|
|
4
|
+
var hasRequiredVercelParameterConverter;
|
|
5
|
+
|
|
6
|
+
function requireVercelParameterConverter () {
|
|
7
|
+
if (hasRequiredVercelParameterConverter) return VercelParameterConverter;
|
|
8
|
+
hasRequiredVercelParameterConverter = 1;
|
|
9
|
+
Object.defineProperty(VercelParameterConverter, "__esModule", { value: true });
|
|
10
|
+
VercelParameterConverter.VercelParameterConverter = void 0;
|
|
11
|
+
const ai_1 = require$$0;
|
|
12
|
+
var VercelParameterConverter$1;
|
|
13
|
+
(function (VercelParameterConverter) {
|
|
14
|
+
VercelParameterConverter.convert = (parameters) => (0, ai_1.jsonSchema)(parameters);
|
|
15
|
+
})(VercelParameterConverter$1 || (VercelParameterConverter.VercelParameterConverter = VercelParameterConverter$1 = {}));
|
|
16
|
+
|
|
17
|
+
return VercelParameterConverter;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { requireVercelParameterConverter as __require };
|
|
21
|
+
//# sourceMappingURL=VercelParameterConverter2.mjs.map
|