@lanonasis/ai-sdk 0.1.0 → 0.2.2
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/README.md +255 -12
- package/dist/client.d.ts +79 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +425 -0
- package/dist/client.js.map +1 -0
- package/dist/http/client.d.ts +66 -0
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/client.js +243 -0
- package/dist/http/client.js.map +1 -0
- package/dist/index.d.ts +49 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -17
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.d.ts +64 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/hooks.js +231 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/types/index.d.ts +257 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +46 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +53 -7
package/README.md
CHANGED
|
@@ -1,36 +1,279 @@
|
|
|
1
1
|
# @lanonasis/ai-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Drop-in AI SDK for browser and Node.js applications with persistent memory, chat completions, and vortexai-l0 orchestration.
|
|
4
|
+
|
|
5
|
+
## Version
|
|
6
|
+
|
|
7
|
+
**Current Release:** v0.2.1
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🔑 **API Key Authentication** - Secure `lano_xxx...` format keys
|
|
12
|
+
- 💾 **Persistent Memory** - Built-in integration with `@lanonasis/memory-sdk-standalone`
|
|
13
|
+
- 🌊 **Streaming Support** - Real-time response streaming
|
|
14
|
+
- 🎭 **Orchestration** - Complex multi-agent workflows via vortexai-l0
|
|
15
|
+
- ⚛️ **React Hooks** - First-class React integration
|
|
16
|
+
- 📦 **Tree-shakeable** - Only import what you need
|
|
17
|
+
- 🔒 **Type-safe** - Full TypeScript support
|
|
4
18
|
|
|
5
19
|
## Installation
|
|
20
|
+
|
|
6
21
|
```bash
|
|
7
22
|
npm install @lanonasis/ai-sdk
|
|
8
23
|
# or
|
|
9
24
|
bun add @lanonasis/ai-sdk
|
|
10
25
|
```
|
|
11
26
|
|
|
12
|
-
##
|
|
13
|
-
|
|
27
|
+
## Environment Setup
|
|
28
|
+
|
|
29
|
+
Add your API key to your environment:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# .env.local (Next.js) or .env
|
|
33
|
+
LANONASIS_API_KEY=lano_your_api_key_here
|
|
34
|
+
|
|
35
|
+
# For client-side usage in Next.js
|
|
36
|
+
NEXT_PUBLIC_LANONASIS_API_KEY=lano_your_api_key_here
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Once configured, the SDK works seamlessly with no additional setup required.
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
14
43
|
```ts
|
|
15
|
-
import {
|
|
44
|
+
import { LanonasisAI } from '@lanonasis/ai-sdk';
|
|
16
45
|
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
46
|
+
// Initialize with API key from environment
|
|
47
|
+
const ai = new LanonasisAI({
|
|
48
|
+
apiKey: process.env.LANONASIS_API_KEY!,
|
|
49
|
+
// baseUrl defaults to https://api.lanonasis.com
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Simple message
|
|
53
|
+
const response = await ai.send('Hello, who are you?');
|
|
54
|
+
console.log(response);
|
|
55
|
+
|
|
56
|
+
// Chat with full control
|
|
57
|
+
const result = await ai.chat({
|
|
58
|
+
messages: [
|
|
59
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
60
|
+
{ role: 'user', content: 'What is 2+2?' },
|
|
61
|
+
],
|
|
62
|
+
model: 'gpt-4o-mini',
|
|
63
|
+
temperature: 0.7,
|
|
64
|
+
maxTokens: 1000,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log(result.response);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Detailed Examples
|
|
71
|
+
|
|
72
|
+
### Basic Chat Completion
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { LanonasisAI } from '@lanonasis/ai-sdk';
|
|
76
|
+
|
|
77
|
+
const ai = new LanonasisAI({
|
|
78
|
+
apiKey: process.env.LANONASIS_API_KEY!,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Single turn conversation
|
|
82
|
+
const response = await ai.chat({
|
|
83
|
+
messages: [
|
|
84
|
+
{ role: 'user', content: 'Explain quantum computing in simple terms' }
|
|
85
|
+
],
|
|
86
|
+
model: 'gpt-4o-mini',
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
console.log(response.response);
|
|
90
|
+
// Output: "Quantum computing is like having a super-powered calculator..."
|
|
20
91
|
```
|
|
21
92
|
|
|
22
|
-
|
|
93
|
+
### Multi-turn Conversation
|
|
94
|
+
|
|
23
95
|
```ts
|
|
24
|
-
|
|
96
|
+
const ai = new LanonasisAI({ apiKey: process.env.LANONASIS_API_KEY! });
|
|
97
|
+
|
|
98
|
+
// Build conversation history
|
|
99
|
+
const messages = [
|
|
100
|
+
{ role: 'system', content: 'You are a coding assistant specializing in TypeScript.' },
|
|
101
|
+
{ role: 'user', content: 'How do I create a generic function?' },
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
const response1 = await ai.chat({ messages });
|
|
105
|
+
console.log(response1.response);
|
|
106
|
+
|
|
107
|
+
// Continue the conversation
|
|
108
|
+
messages.push({ role: 'assistant', content: response1.response });
|
|
109
|
+
messages.push({ role: 'user', content: 'Can you show me an example with arrays?' });
|
|
110
|
+
|
|
111
|
+
const response2 = await ai.chat({ messages });
|
|
112
|
+
console.log(response2.response);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### With Persistent Memory
|
|
116
|
+
|
|
117
|
+
The SDK automatically integrates with `@lanonasis/memory-sdk-standalone`:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const ai = new LanonasisAI({
|
|
121
|
+
apiKey: process.env.LANONASIS_API_KEY!,
|
|
122
|
+
memory: {
|
|
123
|
+
enabled: true,
|
|
124
|
+
autoSave: true,
|
|
125
|
+
contextStrategy: 'relevance',
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Store important information
|
|
130
|
+
await ai.memory.createMemory({
|
|
131
|
+
title: 'User Preferences',
|
|
132
|
+
content: 'User prefers dark mode and concise responses',
|
|
133
|
+
status: 'active',
|
|
134
|
+
});
|
|
25
135
|
|
|
136
|
+
// Search memories
|
|
137
|
+
const memories = await ai.memory.searchMemories({
|
|
138
|
+
query: 'user preferences',
|
|
139
|
+
status: 'active',
|
|
140
|
+
threshold: 0.7,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Chat with memory context
|
|
144
|
+
const response = await ai.chat({
|
|
145
|
+
messages: [{ role: 'user', content: 'Remember my preferences?' }],
|
|
146
|
+
conversationId: 'user-123-session',
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Get context from memories
|
|
150
|
+
const context = await ai.memory.searchWithContext('previous conversations');
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Streaming Responses
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
// Async iterator style
|
|
157
|
+
for await (const chunk of ai.chatStream({
|
|
158
|
+
messages: [{ role: 'user', content: 'Tell me a story' }],
|
|
159
|
+
})) {
|
|
160
|
+
process.stdout.write(chunk.choices[0]?.delta?.content || '');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Callback style
|
|
164
|
+
await ai.streamChat(
|
|
165
|
+
{ messages: [{ role: 'user', content: 'Count to 10' }] },
|
|
166
|
+
(chunk) => console.log(chunk.choices[0]?.delta?.content)
|
|
167
|
+
);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Orchestration
|
|
171
|
+
|
|
172
|
+
Use vortexai-l0 for complex workflows:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// Remote API orchestration (default)
|
|
176
|
+
const result = await ai.orchestrate('Create a viral TikTok campaign');
|
|
177
|
+
|
|
178
|
+
// Local orchestration (no API call)
|
|
179
|
+
const ai = new LanonasisAI({
|
|
180
|
+
apiKey: 'lnss_xxx',
|
|
181
|
+
useLocalOrchestration: true,
|
|
182
|
+
});
|
|
183
|
+
const result = await ai.orchestrate('analyze trending hashtags');
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## React Integration
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { useLanonasis, useChat } from '@lanonasis/ai-sdk/react';
|
|
190
|
+
|
|
191
|
+
function ChatComponent() {
|
|
192
|
+
const { client, isReady } = useLanonasis({
|
|
193
|
+
apiKey: process.env.NEXT_PUBLIC_LANONASIS_KEY!,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const { messages, send, isLoading, sendWithStream } = useChat({
|
|
197
|
+
client,
|
|
198
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<div>
|
|
203
|
+
{messages.map((msg, i) => (
|
|
204
|
+
<div key={i} className={msg.role}>{msg.content}</div>
|
|
205
|
+
))}
|
|
206
|
+
{isLoading && <div>Thinking...</div>}
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Configuration
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
new LanonasisAI({
|
|
216
|
+
apiKey: string; // Required: lano_xxx format
|
|
217
|
+
baseUrl?: string; // Default: https://api.lanonasis.com
|
|
218
|
+
memoryUrl?: string; // Default: same as baseUrl
|
|
219
|
+
timeout?: number; // Default: 30000 (30s)
|
|
220
|
+
maxRetries?: number; // Default: 3
|
|
221
|
+
debug?: boolean; // Default: false
|
|
222
|
+
organizationId?: string; // For multi-tenant setups
|
|
223
|
+
useLocalOrchestration?: bool // Use vortexai-l0 locally
|
|
224
|
+
memory?: {
|
|
225
|
+
enabled?: boolean; // Default: true
|
|
226
|
+
autoSave?: boolean; // Default: true
|
|
227
|
+
contextStrategy?: string; // 'relevance' | 'temporal' | 'hybrid'
|
|
228
|
+
maxContextTokens?: number; // Default: 4000
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## API Endpoints
|
|
234
|
+
|
|
235
|
+
The SDK connects to these endpoints by default:
|
|
236
|
+
|
|
237
|
+
| Feature | Endpoint |
|
|
238
|
+
|---------|----------|
|
|
239
|
+
| Chat Completions | `POST /v1/chat/completions` |
|
|
240
|
+
| Memory API | `GET/POST /api/v1/memory` |
|
|
241
|
+
| Health Check | `GET /health` |
|
|
242
|
+
|
|
243
|
+
All requests are authenticated via the `Authorization: Bearer lano_xxx` header.
|
|
244
|
+
|
|
245
|
+
## Architecture
|
|
246
|
+
|
|
247
|
+
This SDK integrates with existing Lanonasis infrastructure:
|
|
248
|
+
|
|
249
|
+
- **@lanonasis/memory-sdk** - Persistent memory and context building
|
|
250
|
+
- **vortexai-l0** - Local orchestration engine
|
|
251
|
+
- **Backend API** - Chat completions and remote orchestration
|
|
252
|
+
|
|
253
|
+
## Migration from v0.1.0
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
// Old (v0.1.0)
|
|
257
|
+
import { AiSDK } from '@lanonasis/ai-sdk';
|
|
26
258
|
const sdk = new AiSDK();
|
|
27
|
-
|
|
28
|
-
|
|
259
|
+
await sdk.orchestrate('query');
|
|
260
|
+
|
|
261
|
+
// New (v0.2.x)
|
|
262
|
+
import { LanonasisAI } from '@lanonasis/ai-sdk';
|
|
263
|
+
const ai = new LanonasisAI({ apiKey: process.env.LANONASIS_API_KEY! });
|
|
264
|
+
await ai.orchestrate('query');
|
|
265
|
+
// Or simple:
|
|
266
|
+
const message = await ai.send('query');
|
|
29
267
|
```
|
|
30
268
|
|
|
269
|
+
## License
|
|
270
|
+
|
|
271
|
+
MIT
|
|
272
|
+
|
|
31
273
|
## Advanced (Plugins)
|
|
274
|
+
|
|
32
275
|
```ts
|
|
33
|
-
import {
|
|
276
|
+
import { LanonasisAI, createPluginManager } from '@lanonasis/ai-sdk';
|
|
34
277
|
|
|
35
278
|
const plugins = createPluginManager();
|
|
36
279
|
plugins.register({
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LanonasisAI - Main SDK Client
|
|
3
|
+
*
|
|
4
|
+
* Drop-in AI SDK that integrates with existing Lanonasis infrastructure:
|
|
5
|
+
* - @lanonasis/memory-sdk for persistent memory and context
|
|
6
|
+
* - vortexai-l0 for local orchestration
|
|
7
|
+
* - Backend API for chat completions
|
|
8
|
+
*/
|
|
9
|
+
import MemoryClient from '@lanonasis/memory-sdk-standalone';
|
|
10
|
+
import type { LanonasisConfig, ChatRequest, ChatResponse, ChatStreamChunk, OrchestrateRequest, OrchestrateResponse, ApiKeyInfo, StreamCallback, EventType, EventHandler } from './types/index.js';
|
|
11
|
+
export declare class LanonasisAI {
|
|
12
|
+
private http;
|
|
13
|
+
private localOrchestrator;
|
|
14
|
+
private eventHandlers;
|
|
15
|
+
/** Memory client from @lanonasis/memory-sdk */
|
|
16
|
+
readonly memory: MemoryClient;
|
|
17
|
+
/** SDK configuration */
|
|
18
|
+
readonly config: Required<Omit<LanonasisConfig, 'memory'>> & {
|
|
19
|
+
memory: LanonasisConfig['memory'];
|
|
20
|
+
};
|
|
21
|
+
constructor(config: LanonasisConfig);
|
|
22
|
+
on(event: EventType, handler: EventHandler): () => void;
|
|
23
|
+
off(event: EventType, handler: EventHandler): void;
|
|
24
|
+
private emit;
|
|
25
|
+
/**
|
|
26
|
+
* Send a chat message with optional memory context
|
|
27
|
+
*/
|
|
28
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Simple message send (convenience method)
|
|
31
|
+
*/
|
|
32
|
+
send(message: string, options?: Partial<ChatRequest>): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Stream chat response
|
|
35
|
+
*/
|
|
36
|
+
chatStream(request: ChatRequest): AsyncGenerator<ChatStreamChunk, void, unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Stream with callback (alternative API)
|
|
39
|
+
*/
|
|
40
|
+
streamChat(request: ChatRequest, onChunk: StreamCallback): Promise<ChatResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Orchestrate a complex request
|
|
43
|
+
* Uses local vortexai-l0 or remote API based on config
|
|
44
|
+
*/
|
|
45
|
+
orchestrate(request: OrchestrateRequest | string): Promise<OrchestrateResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Convert L0Orchestrator response to OrchestrateResponse format
|
|
48
|
+
*/
|
|
49
|
+
private convertL0Response;
|
|
50
|
+
/**
|
|
51
|
+
* Build context from memory using memory-sdk's searchWithContext
|
|
52
|
+
*/
|
|
53
|
+
private buildMemoryContext;
|
|
54
|
+
/**
|
|
55
|
+
* Inject context into messages
|
|
56
|
+
*/
|
|
57
|
+
private injectContext;
|
|
58
|
+
/**
|
|
59
|
+
* Save conversation to memory
|
|
60
|
+
*/
|
|
61
|
+
private saveToMemory;
|
|
62
|
+
validateKey(): Promise<ApiKeyInfo>;
|
|
63
|
+
getUsage(): Promise<ApiKeyInfo['usage']>;
|
|
64
|
+
getRateLimitStatus(): {
|
|
65
|
+
remaining: number;
|
|
66
|
+
reset: number;
|
|
67
|
+
};
|
|
68
|
+
healthCheck(): Promise<{
|
|
69
|
+
status: 'ok' | 'error';
|
|
70
|
+
latency: number;
|
|
71
|
+
}>;
|
|
72
|
+
memoryHealth(): Promise<{
|
|
73
|
+
status: 'ok' | 'error';
|
|
74
|
+
}>;
|
|
75
|
+
withConfig(overrides: Partial<LanonasisConfig>): LanonasisAI;
|
|
76
|
+
private debug;
|
|
77
|
+
}
|
|
78
|
+
export declare function createClient(config: LanonasisConfig): LanonasisAI;
|
|
79
|
+
//# sourceMappingURL=client.d.ts.map
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