@reminix/vercel-ai 0.0.1

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # @reminix/vercel-ai
2
+
3
+ Reminix Runtime adapter for the [Vercel AI SDK](https://sdk.vercel.ai/). Supports both:
4
+
5
+ - **ToolLoopAgent** - Full agents with tools and automatic tool loop handling
6
+ - **Model** - Simple completions via `generateText`/`streamText` without tools
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @reminix/runtime @reminix/vercel-ai ai @ai-sdk/openai
12
+ ```
13
+
14
+ ## Quick Start with ToolLoopAgent
15
+
16
+ For agents with tools, use `ToolLoopAgent`:
17
+
18
+ ```typescript
19
+ import { ToolLoopAgent, tool } from 'ai';
20
+ import { openai } from '@ai-sdk/openai';
21
+ import { z } from 'zod';
22
+
23
+ import { wrap } from '@reminix/vercel-ai';
24
+ import { serve } from '@reminix/runtime';
25
+
26
+ const weatherTool = tool({
27
+ description: 'Get the current weather for a city',
28
+ inputSchema: z.object({
29
+ city: z.string()
30
+ }),
31
+ execute: async ({ city }) => {
32
+ return { city, temp: 72, condition: 'sunny' };
33
+ }
34
+ });
35
+
36
+ const agent = new ToolLoopAgent({
37
+ model: openai('gpt-4o'),
38
+ instructions: 'You help users check the weather.',
39
+ tools: { getWeather: weatherTool }
40
+ });
41
+
42
+ const reminixAgent = wrap(agent, { name: 'weather-agent' });
43
+
44
+ serve([reminixAgent], { port: 8080 });
45
+ ```
46
+
47
+ ## Quick Start with Model
48
+
49
+ For simple completions without tools, pass the model directly:
50
+
51
+ ```typescript
52
+ import { openai } from '@ai-sdk/openai';
53
+
54
+ import { wrap } from '@reminix/vercel-ai';
55
+ import { serve } from '@reminix/runtime';
56
+
57
+ const model = openai('gpt-4o');
58
+
59
+ const reminixAgent = wrap(model, { name: 'chat-agent' });
60
+
61
+ serve([reminixAgent], { port: 8080 });
62
+ ```
63
+
64
+ Your agent is now available at:
65
+ - `POST /agents/<name>/invoke` - Stateless invocation
66
+ - `POST /agents/<name>/chat` - Conversational chat
67
+
68
+ ## API Reference
69
+
70
+ ### `wrap(modelOrAgent, options)`
71
+
72
+ Wrap a Vercel AI SDK ToolLoopAgent or Model for use with Reminix Runtime.
73
+
74
+ | Parameter | Type | Default | Description |
75
+ |-----------|------|---------|-------------|
76
+ | `modelOrAgent` | `ToolLoopAgent \| LanguageModel` | required | A ToolLoopAgent or language model |
77
+ | `options.name` | `string` | `"vercel-ai-agent"` | Name for the agent (used in URL path) |
78
+
79
+ **Returns:** `VercelAIAdapter` - A Reminix adapter instance
80
+
81
+ ## Using Different Providers
82
+
83
+ The Vercel AI SDK supports multiple providers:
84
+
85
+ ```typescript
86
+ import { openai } from '@ai-sdk/openai';
87
+ import { anthropic } from '@ai-sdk/anthropic';
88
+ import { google } from '@ai-sdk/google';
89
+ import { wrap } from '@reminix/vercel-ai';
90
+ import { serve } from '@reminix/runtime';
91
+
92
+ const gpt = wrap(openai('gpt-4o'), { name: 'gpt' });
93
+ const claude = wrap(anthropic('claude-sonnet-4-20250514'), { name: 'claude' });
94
+ const gemini = wrap(google('gemini-pro'), { name: 'gemini' });
95
+
96
+ serve([gpt, claude, gemini], { port: 8080 });
97
+ ```
98
+
99
+ ## When to Use Each Option
100
+
101
+ | Option | Use Case |
102
+ |--------|----------|
103
+ | **ToolLoopAgent** | Agents that need tools, multi-step reasoning, automatic tool loop |
104
+ | **Model** | Simple completions, providers without dedicated adapters (Google, Mistral, etc.) |
105
+
106
+ ## Endpoint Input/Output Formats
107
+
108
+ ### POST /agents/{name}/invoke
109
+
110
+ Stateless invocation for task-oriented operations.
111
+
112
+ **Request:**
113
+ ```json
114
+ {
115
+ "input": {
116
+ "prompt": "Summarize this text: ..."
117
+ }
118
+ }
119
+ ```
120
+
121
+ Or with messages:
122
+ ```json
123
+ {
124
+ "input": {
125
+ "messages": [
126
+ {"role": "user", "content": "Hello!"}
127
+ ]
128
+ }
129
+ }
130
+ ```
131
+
132
+ **Response:**
133
+ ```json
134
+ {
135
+ "output": "Hello! How can I help you today?"
136
+ }
137
+ ```
138
+
139
+ ### POST /agents/{name}/chat
140
+
141
+ Conversational chat with message history.
142
+
143
+ **Request:**
144
+ ```json
145
+ {
146
+ "messages": [
147
+ {"role": "user", "content": "What is the capital of France?"}
148
+ ]
149
+ }
150
+ ```
151
+
152
+ **Response:**
153
+ ```json
154
+ {
155
+ "output": "The capital of France is Paris.",
156
+ "messages": [
157
+ {"role": "user", "content": "What is the capital of France?"},
158
+ {"role": "assistant", "content": "The capital of France is Paris."}
159
+ ]
160
+ }
161
+ ```
162
+
163
+ ## Runtime Documentation
164
+
165
+ For information about the server, endpoints, request/response formats, and more, see the [`@reminix/runtime`](https://www.npmjs.com/package/@reminix/runtime) package.
166
+
167
+ ## Links
168
+
169
+ - [GitHub Repository](https://github.com/reminix-ai/runtime-typescript)
170
+ - [Vercel AI SDK Documentation](https://sdk.vercel.ai/)
171
+
172
+ ## License
173
+
174
+ Apache-2.0
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Vercel AI SDK adapter for Reminix Runtime.
3
+ *
4
+ * Supports both ToolLoopAgent (for agents with tools) and LanguageModel (for generateText).
5
+ */
6
+ import type { ToolLoopAgent } from 'ai';
7
+ import { generateText, streamText, type LanguageModel } from 'ai';
8
+ import { BaseAdapter, type InvokeRequest, type InvokeResponse, type ChatRequest, type ChatResponse } from '@reminix/runtime';
9
+ /**
10
+ * Options for wrapping a Vercel AI model or agent.
11
+ */
12
+ export interface VercelAIAdapterOptions {
13
+ name?: string;
14
+ }
15
+ type AnyToolLoopAgent = ToolLoopAgent<any, any, any>;
16
+ /**
17
+ * Adapter for Vercel AI SDK models and agents.
18
+ *
19
+ * Supports:
20
+ * - ToolLoopAgent: Full agent with tools and automatic tool loop handling
21
+ * - LanguageModel: Simple model for text generation without tools
22
+ */
23
+ export declare class VercelAIAdapter extends BaseAdapter {
24
+ static adapterName: string;
25
+ private modelOrAgent;
26
+ private isAgent;
27
+ private _name;
28
+ /**
29
+ * Internal generateText function, can be overridden for testing.
30
+ */
31
+ protected _generateText: typeof generateText;
32
+ /**
33
+ * Internal streamText function, can be overridden for testing.
34
+ */
35
+ protected _streamText: typeof streamText;
36
+ /**
37
+ * Initialize the adapter.
38
+ *
39
+ * @param modelOrAgent - A Vercel AI SDK ToolLoopAgent or LanguageModel.
40
+ * @param options - Adapter options.
41
+ */
42
+ constructor(modelOrAgent: LanguageModel | AnyToolLoopAgent, options?: VercelAIAdapterOptions);
43
+ get name(): string;
44
+ /**
45
+ * Convert Reminix messages to Vercel AI ModelMessage format.
46
+ */
47
+ private toModelMessages;
48
+ /**
49
+ * Handle an invoke request.
50
+ *
51
+ * For task-oriented operations. Expects input with 'messages' key
52
+ * or a 'prompt' key for simple text generation.
53
+ *
54
+ * @param request - The invoke request with input data.
55
+ * @returns The invoke response with the output.
56
+ */
57
+ invoke(request: InvokeRequest): Promise<InvokeResponse>;
58
+ /**
59
+ * Handle a chat request.
60
+ *
61
+ * For conversational interactions.
62
+ *
63
+ * @param request - The chat request with messages.
64
+ * @returns The chat response with output and messages.
65
+ */
66
+ chat(request: ChatRequest): Promise<ChatResponse>;
67
+ /**
68
+ * Handle a streaming invoke request.
69
+ *
70
+ * @param request - The invoke request with input data.
71
+ * @yields JSON-encoded chunks from the stream.
72
+ */
73
+ invokeStream(request: InvokeRequest): AsyncGenerator<string, void, unknown>;
74
+ /**
75
+ * Handle a streaming chat request.
76
+ *
77
+ * @param request - The chat request with messages.
78
+ * @yields JSON-encoded chunks from the stream.
79
+ */
80
+ chatStream(request: ChatRequest): AsyncGenerator<string, void, unknown>;
81
+ }
82
+ /**
83
+ * Wrap a Vercel AI SDK model or agent for use with Reminix Runtime.
84
+ *
85
+ * Supports both ToolLoopAgent (for agents with tools) and LanguageModel (for generateText).
86
+ *
87
+ * @param modelOrAgent - A Vercel AI SDK ToolLoopAgent or LanguageModel.
88
+ * @param options - Adapter options.
89
+ * @returns A VercelAIAdapter instance.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * // Option 1: ToolLoopAgent (with tools)
94
+ * import { ToolLoopAgent, tool } from 'ai';
95
+ * import { openai } from '@ai-sdk/openai';
96
+ * import { wrap } from '@reminix/vercel-ai';
97
+ * import { serve } from '@reminix/runtime';
98
+ *
99
+ * const agent = new ToolLoopAgent({
100
+ * model: openai('gpt-4o'),
101
+ * tools: {
102
+ * getWeather: tool({
103
+ * description: 'Get weather for a city',
104
+ * inputSchema: z.object({ city: z.string() }),
105
+ * execute: async ({ city }) => ({ temp: 72, condition: 'sunny' })
106
+ * })
107
+ * }
108
+ * });
109
+ *
110
+ * const reminixAgent = wrap(agent, { name: 'weather-agent' });
111
+ * serve([reminixAgent], { port: 8080 });
112
+ *
113
+ * // Option 2: Model (simple completions with generateText)
114
+ * import { openai } from '@ai-sdk/openai';
115
+ * import { wrap } from '@reminix/vercel-ai';
116
+ *
117
+ * const model = openai('gpt-4o');
118
+ * const reminixAgent = wrap(model, { name: 'chat-agent' });
119
+ * ```
120
+ */
121
+ export declare function wrap(modelOrAgent: LanguageModel | AnyToolLoopAgent, options?: VercelAIAdapterOptions): VercelAIAdapter;
122
+ export {};
123
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,aAAa,EAAqB,MAAM,IAAI,CAAC;AAErF,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;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Agent (for agents with tools) and LanguageModel (for generateText).
5
+ */
6
+ import { generateText, streamText } from 'ai';
7
+ import { BaseAdapter, } from '@reminix/runtime';
8
+ /**
9
+ * Type guard to check if the input is a ToolLoopAgent.
10
+ */
11
+ function isToolLoopAgent(input) {
12
+ return (input !== null &&
13
+ typeof input === 'object' &&
14
+ 'generate' in input &&
15
+ typeof input.generate === 'function');
16
+ }
17
+ /**
18
+ * Adapter for Vercel AI SDK models and agents.
19
+ *
20
+ * Supports:
21
+ * - ToolLoopAgent: Full agent with tools and automatic tool loop handling
22
+ * - LanguageModel: Simple model for text generation without tools
23
+ */
24
+ export class VercelAIAdapter extends BaseAdapter {
25
+ static adapterName = 'vercel-ai';
26
+ modelOrAgent;
27
+ isAgent;
28
+ _name;
29
+ /**
30
+ * Internal generateText function, can be overridden for testing.
31
+ */
32
+ _generateText = generateText;
33
+ /**
34
+ * Internal streamText function, can be overridden for testing.
35
+ */
36
+ _streamText = streamText;
37
+ /**
38
+ * Initialize the adapter.
39
+ *
40
+ * @param modelOrAgent - A Vercel AI SDK ToolLoopAgent or LanguageModel.
41
+ * @param options - Adapter options.
42
+ */
43
+ constructor(modelOrAgent, options = {}) {
44
+ super();
45
+ this.modelOrAgent = modelOrAgent;
46
+ this.isAgent = isToolLoopAgent(modelOrAgent);
47
+ this._name = options.name ?? 'vercel-ai-agent';
48
+ }
49
+ get name() {
50
+ return this._name;
51
+ }
52
+ /**
53
+ * Convert Reminix messages to Vercel AI ModelMessage format.
54
+ */
55
+ toModelMessages(messages) {
56
+ return messages.map((m) => ({
57
+ role: m.role,
58
+ content: m.content || '',
59
+ }));
60
+ }
61
+ /**
62
+ * Handle an invoke request.
63
+ *
64
+ * For task-oriented operations. Expects input with 'messages' key
65
+ * or a 'prompt' key for simple text generation.
66
+ *
67
+ * @param request - The invoke request with input data.
68
+ * @returns The invoke response with the output.
69
+ */
70
+ async invoke(request) {
71
+ const input = request.input;
72
+ // Build prompt from input
73
+ let prompt;
74
+ if ('prompt' in input) {
75
+ prompt = String(input.prompt);
76
+ }
77
+ else if ('messages' in input) {
78
+ const messages = input.messages;
79
+ prompt = messages.map((m) => m.content).join('\n');
80
+ }
81
+ else {
82
+ prompt = JSON.stringify(input);
83
+ }
84
+ let output;
85
+ if (this.isAgent) {
86
+ // Use ToolLoopAgent.generate()
87
+ const agent = this.modelOrAgent;
88
+ const result = await agent.generate({ prompt, options: {} });
89
+ output = result.text;
90
+ }
91
+ else {
92
+ // Use generateText with LanguageModel
93
+ const model = this.modelOrAgent;
94
+ const result = await this._generateText({
95
+ model,
96
+ prompt,
97
+ });
98
+ output = result.text;
99
+ }
100
+ return { output };
101
+ }
102
+ /**
103
+ * Handle a chat request.
104
+ *
105
+ * For conversational interactions.
106
+ *
107
+ * @param request - The chat request with messages.
108
+ * @returns The chat response with output and messages.
109
+ */
110
+ async chat(request) {
111
+ const messages = this.toModelMessages(request.messages);
112
+ let output;
113
+ if (this.isAgent) {
114
+ // Use ToolLoopAgent.generate()
115
+ const agent = this.modelOrAgent;
116
+ const result = await agent.generate({ messages, options: {} });
117
+ output = result.text;
118
+ }
119
+ else {
120
+ // Use generateText with LanguageModel
121
+ const model = this.modelOrAgent;
122
+ const result = await this._generateText({
123
+ model,
124
+ messages,
125
+ });
126
+ output = result.text;
127
+ }
128
+ // Build response messages (original + assistant response)
129
+ const responseMessages = [
130
+ ...request.messages,
131
+ { role: 'assistant', content: output },
132
+ ];
133
+ return { output, messages: responseMessages };
134
+ }
135
+ /**
136
+ * Handle a streaming invoke request.
137
+ *
138
+ * @param request - The invoke request with input data.
139
+ * @yields JSON-encoded chunks from the stream.
140
+ */
141
+ async *invokeStream(request) {
142
+ const input = request.input;
143
+ // Build prompt from input
144
+ let prompt;
145
+ if ('prompt' in input) {
146
+ prompt = String(input.prompt);
147
+ }
148
+ else if ('messages' in input) {
149
+ const messages = input.messages;
150
+ prompt = messages.map((m) => m.content).join('\n');
151
+ }
152
+ else {
153
+ prompt = JSON.stringify(input);
154
+ }
155
+ if (this.isAgent) {
156
+ // Use ToolLoopAgent.stream()
157
+ const agent = this.modelOrAgent;
158
+ const result = await agent.stream({ prompt, options: {} });
159
+ for await (const chunk of result.textStream) {
160
+ yield JSON.stringify({ chunk });
161
+ }
162
+ }
163
+ else {
164
+ // Use streamText with LanguageModel
165
+ const model = this.modelOrAgent;
166
+ const result = this._streamText({
167
+ model,
168
+ prompt,
169
+ });
170
+ for await (const chunk of result.textStream) {
171
+ yield JSON.stringify({ chunk });
172
+ }
173
+ }
174
+ }
175
+ /**
176
+ * Handle a streaming chat request.
177
+ *
178
+ * @param request - The chat request with messages.
179
+ * @yields JSON-encoded chunks from the stream.
180
+ */
181
+ async *chatStream(request) {
182
+ const messages = this.toModelMessages(request.messages);
183
+ if (this.isAgent) {
184
+ // Use ToolLoopAgent.stream()
185
+ const agent = this.modelOrAgent;
186
+ const result = await agent.stream({ messages, options: {} });
187
+ for await (const chunk of result.textStream) {
188
+ yield JSON.stringify({ chunk });
189
+ }
190
+ }
191
+ else {
192
+ // Use streamText with LanguageModel
193
+ const model = this.modelOrAgent;
194
+ const result = this._streamText({
195
+ model,
196
+ messages,
197
+ });
198
+ for await (const chunk of result.textStream) {
199
+ yield JSON.stringify({ chunk });
200
+ }
201
+ }
202
+ }
203
+ }
204
+ /**
205
+ * Wrap a Vercel AI SDK model or agent for use with Reminix Runtime.
206
+ *
207
+ * Supports both ToolLoopAgent (for agents with tools) and LanguageModel (for generateText).
208
+ *
209
+ * @param modelOrAgent - A Vercel AI SDK ToolLoopAgent or LanguageModel.
210
+ * @param options - Adapter options.
211
+ * @returns A VercelAIAdapter instance.
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * // Option 1: ToolLoopAgent (with tools)
216
+ * import { ToolLoopAgent, tool } from 'ai';
217
+ * import { openai } from '@ai-sdk/openai';
218
+ * import { wrap } from '@reminix/vercel-ai';
219
+ * import { serve } from '@reminix/runtime';
220
+ *
221
+ * const agent = new ToolLoopAgent({
222
+ * model: openai('gpt-4o'),
223
+ * tools: {
224
+ * getWeather: tool({
225
+ * description: 'Get weather for a city',
226
+ * inputSchema: z.object({ city: z.string() }),
227
+ * execute: async ({ city }) => ({ temp: 72, condition: 'sunny' })
228
+ * })
229
+ * }
230
+ * });
231
+ *
232
+ * const reminixAgent = wrap(agent, { name: 'weather-agent' });
233
+ * serve([reminixAgent], { port: 8080 });
234
+ *
235
+ * // Option 2: Model (simple completions with generateText)
236
+ * import { openai } from '@ai-sdk/openai';
237
+ * import { wrap } from '@reminix/vercel-ai';
238
+ *
239
+ * const model = openai('gpt-4o');
240
+ * const reminixAgent = wrap(model, { name: 'chat-agent' });
241
+ * ```
242
+ */
243
+ export function wrap(modelOrAgent, options = {}) {
244
+ return new VercelAIAdapter(modelOrAgent, options);
245
+ }
246
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAyC,MAAM,IAAI,CAAC;AAErF,OAAO,EACL,WAAW,GAMZ,MAAM,kBAAkB,CAAC;AAY1B;;GAEG;AACH,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,UAAU,IAAI,KAAK;QACnB,OAAQ,KAA0B,CAAC,QAAQ,KAAK,UAAU,CAC3D,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;IAEzB,YAAY,CAAmC;IAC/C,OAAO,CAAU;IACjB,KAAK,CAAS;IAEtB;;OAEG;IACO,aAAa,GAAG,YAAY,CAAC;IAEvC;;OAEG;IACO,WAAW,GAAG,UAAU,CAAC;IAEnC;;;;;OAKG;IACH,YACE,YAA8C,EAC9C,UAAkC,EAAE;QAEpC,KAAK,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.js';
2
+ export type { VercelAIAdapterOptions } from './adapter.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { VercelAIAdapter, wrap } from './adapter.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@reminix/vercel-ai",
3
+ "version": "0.0.1",
4
+ "description": "Reminix adapter for Vercel AI SDK",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@reminix/runtime": "^0.0.1"
20
+ },
21
+ "peerDependencies": {
22
+ "ai": ">=6.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^22.0.0",
26
+ "ai": "^6.0.31",
27
+ "typescript": "^5.9.3",
28
+ "vitest": "^3.1.3"
29
+ },
30
+ "scripts": {
31
+ "build": "tsc",
32
+ "clean": "rm -rf dist",
33
+ "test": "vitest run",
34
+ "test:watch": "vitest"
35
+ }
36
+ }