@inkeep/ai-sdk-provider 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,49 @@
1
+ # Inkeep SDK – Elastic License 2.0 with Supplemental Terms
2
+
3
+ NOTE: The Inkeep SDK is licensed under the Elastic License 2.0 (ELv2), subject to Supplemental Terms included in [SUPPLEMENTAL_TERMS.md](SUPPLEMENTAL_TERMS.md). In the event of conflict, the Supplemental Terms control.
4
+
5
+ # Elastic License 2.0
6
+
7
+ ## Acceptance
8
+ By using the software, you agree to all of the terms and conditions below.
9
+
10
+ ## Copyright License
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
12
+
13
+ ## Limitations
14
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
15
+
16
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
17
+
18
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
19
+
20
+ ## Patents
21
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
22
+
23
+ ## Notices
24
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
25
+
26
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
27
+
28
+ ## No Other Rights
29
+ These terms do not imply any licenses other than those expressly granted in these terms.
30
+
31
+ ## Termination
32
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
33
+
34
+ ## No Liability
35
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
36
+
37
+ ## Definitions
38
+ The **licensor** is the entity offering these terms, and the **software** is the software the licensor makes available under these terms, including any portion of it.
39
+
40
+ **you** refers to the individual or entity agreeing to these terms.
41
+
42
+ **your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
43
+
44
+ **your licenses** are all the licenses granted to you for the software under these terms.
45
+
46
+ **use** means anything you do with the software requiring one of your licenses.
47
+
48
+ **trademark** means trademarks, service marks, and similar rights.
49
+
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # @inkeep/ai-sdk-provider
2
+
3
+ AI SDK provider for Inkeep Agent Framework. This package allows you to use Inkeep agents through the [Vercel AI SDK](https://sdk.vercel.ai/docs).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @inkeep/ai-sdk-provider
9
+
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ## Basic Usage
15
+
16
+ ### Text Generation
17
+
18
+ ```typescript
19
+ import { generateText } from 'ai';
20
+ import { createInkeep } from '@inkeep/ai-sdk-provider';
21
+
22
+ const inkeep = createInkeep({
23
+ baseURL: proccess.env.INKEEP_AGENTS_RUN_API_URL, // Required
24
+ apiKey: <your-agent-api-key>, // Created in the Agents Dashboard
25
+ headers: { // Optional if you are developing locally and dont want to use an api key
26
+ 'x-inkeep-agent-id': 'your-agent-id',
27
+ 'x-inkeep-tenant-id': 'your-tenant-id',
28
+ 'x-inkeep-project-id': 'your-project-id',
29
+ },
30
+ });
31
+
32
+ const { text } = await generateText({
33
+ model: inkeep('agent-123'),
34
+ prompt: 'What is the weather in NYC?',
35
+ });
36
+
37
+ console.log(text);
38
+ ```
39
+
40
+ ### Streaming Responses
41
+
42
+ ```typescript
43
+ import { streamText } from 'ai';
44
+ import { createInkeep } from '@inkeep/ai-sdk-provider';
45
+
46
+ const inkeep = createInkeep({
47
+ baseURL: proccess.env.INKEEP_AGENTS_RUN_API_URL,
48
+ headers: {
49
+ 'x-emit-operations': 'true', // Enable tool event streaming
50
+ },
51
+ });
52
+
53
+ const result = await streamText({
54
+ model: inkeep('agent-123'),
55
+ prompt: 'Plan an event in NYC',
56
+ });
57
+
58
+ for await (const chunk of result.textStream) {
59
+ process.stdout.write(chunk);
60
+ }
61
+ ```
62
+
63
+ ```typescript
64
+ createInkeep({
65
+ baseURL: string, // Required. Your agents-run-api URL
66
+ apiKey?: string, // Optional. Bearer token for authentication
67
+ headers?: Record<string, string>, // Optional. Additional headers
68
+ })
69
+ ```
70
+
71
+ ### Model Options
72
+
73
+ Pass options when creating a provider instance:
74
+
75
+ ```typescript
76
+ const provider = inkeep({
77
+ conversationId: 'conv-456',
78
+ headers: { 'user-id': 'user-789' },
79
+ });
80
+ ```
81
+
82
+ ### Additional Options
83
+
84
+ ```typescript
85
+ import { inkeep } from '@inkeep/ai-sdk-provider';
86
+ import { generateText } from 'ai';
87
+
88
+ const result = await generateText({
89
+ model: inkeep('agent-123', {
90
+ conversationId: 'conv-123',
91
+ headers: {
92
+ 'user-id': 'user-456',
93
+ },
94
+ }),
95
+ prompt: 'Hello!',
96
+ });
97
+ ```
98
+
99
+ ## Configuration
100
+
101
+ ### Provider Settings
102
+
103
+ When creating a custom provider with `createInkeep()`, you can configure:
104
+
105
+ - `baseURL` - **Required.** The base URL of your Inkeep agents API (can also be set via `INKEEP_AGENTS_RUN_API_URL` environment variable)
106
+ - `apiKey` - Your Inkeep API key (can also be set via `INKEEP_API_KEY` environment variable)
107
+ - `headers` - Additional headers to include in requests
108
+
109
+ ### Model Options
110
+
111
+ When creating a model instance, you can configure:
112
+
113
+ - `conversationId` - Conversation ID for multi-turn conversations
114
+ - `headers` - Additional headers for context (validated against agent's context config)
115
+
116
+ ## Environment Variables
117
+
118
+ - `INKEEP_AGENTS_RUN_API_URL` - Base URL for the Inkeep agents API (unless provided via `baseURL` option)
119
+
120
+ ## Features
121
+
122
+ - ✅ Text generation (`generateText`)
123
+ - ✅ Streaming responses (`streamText`)
124
+ - ✅ Multi-turn conversations
125
+ - ✅ Custom headers for context
126
+ - ✅ Authentication with Bearer tokens
127
+ - ✅ Tool call observability (with `x-emit-operations` header)
128
+
129
+ ## API Endpoint
130
+
131
+ This provider communicates with the `/api/chat` endpoint of your Inkeep Agents Run API.
132
+
133
+ - **Non-streaming** (`generateText`): Sends `stream: false` parameter - returns complete JSON response
134
+ - **Streaming** (`streamText`): Sends `stream: true` parameter - returns Vercel AI SDK data stream
135
+
136
+ The endpoint supports both streaming and non-streaming modes and uses Bearer token authentication.
137
+
138
+ ### Tool Call Observability
139
+
140
+ To receive tool call and tool result events in your stream, include the `x-emit-operations: true` header:
141
+
142
+ ```typescript
143
+ import { streamText } from 'ai';
144
+ import { createInkeep } from '@inkeep/ai-sdk-provider';
145
+
146
+ const inkeep = createInkeep({
147
+ baseURL: 'https://your-api.example.com',
148
+ apiKey: process.env.INKEEP_API_KEY,
149
+ headers: {
150
+ 'x-emit-operations': 'true', // Enable tool event streaming
151
+ },
152
+ });
153
+
154
+ const result = await streamText({
155
+ model: inkeep('agent-123'),
156
+ prompt: 'Search for recent papers on AI',
157
+ });
158
+
159
+ // Listen for all stream events
160
+ for await (const event of result.fullStream) {
161
+ switch (event.type) {
162
+ case 'text-start':
163
+ console.log('📝 Text streaming started');
164
+ break;
165
+ case 'text-delta':
166
+ process.stdout.write(event.delta);
167
+ break;
168
+ case 'text-end':
169
+ console.log('\n📝 Text streaming ended');
170
+ break;
171
+ case 'tool-call':
172
+ console.log(`🔧 Calling tool: ${event.toolName}`);
173
+ console.log(` Input: ${event.input}`);
174
+ break;
175
+ case 'tool-result':
176
+ console.log(`✅ Tool result from: ${event.toolName}`);
177
+ console.log(` Output:`, event.result);
178
+ break;
179
+ }
180
+ }
181
+ ```
182
+
183
+ **Note**: Tool events are only emitted when the `x-emit-operations: true` header is set. Without this header, you'll only receive text lifecycle events (text-start, text-delta, text-end) and the final response.
184
+
185
+ ### Supported Stream Events
186
+
187
+ The provider emits the following AI SDK v2 stream events:
188
+
189
+ **Text Events** (always emitted):
190
+ - `text-start` - Marks the beginning of a text stream
191
+ - `text-delta` - Text content chunks as they arrive
192
+ - `text-end` - Marks the end of a text stream
193
+
194
+ **Tool Events** (requires `x-emit-operations: true` header):
195
+ - `tool-call` - Agent is calling a tool
196
+ - `tool-result` - Tool execution completed
197
+
198
+ **Control Events** (always emitted):
199
+ - `finish` - Stream completion with usage statistics
200
+ - `error` - Stream error occurred
201
+
202
+ ## Model Identification
203
+
204
+ Models are identified by agent ID in the format:
205
+ - `agent-123` - Direct agent ID
206
+ - `inkeep/agent-123` - With provider prefix (when used with custom factories)