@lanonasis/ai-sdk 0.1.0 → 0.2.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/README.md +166 -12
- package/dist/client.d.ts +79 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +420 -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 +47 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -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,190 @@
|
|
|
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.0
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🔑 **API Key Authentication** - Secure `lnss_xxx...` or `onasis_xxx...` format keys
|
|
12
|
+
- 💾 **Persistent Memory** - Built-in integration with `@lanonasis/memory-sdk`
|
|
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
|
+
## Quick Start
|
|
28
|
+
|
|
14
29
|
```ts
|
|
15
|
-
import {
|
|
30
|
+
import { LanonasisAI } from '@lanonasis/ai-sdk';
|
|
16
31
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
const ai = new LanonasisAI({
|
|
33
|
+
apiKey: 'lnss_your_api_key_here',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Simple message
|
|
37
|
+
const response = await ai.send('Hello, who are you?');
|
|
38
|
+
console.log(response);
|
|
39
|
+
|
|
40
|
+
// Chat with full control
|
|
41
|
+
const result = await ai.chat({
|
|
42
|
+
messages: [
|
|
43
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
44
|
+
{ role: 'user', content: 'What is 2+2?' },
|
|
45
|
+
],
|
|
46
|
+
temperature: 0.7,
|
|
47
|
+
maxTokens: 1000,
|
|
48
|
+
});
|
|
20
49
|
```
|
|
21
50
|
|
|
22
|
-
##
|
|
51
|
+
## With Persistent Memory
|
|
52
|
+
|
|
53
|
+
The SDK automatically integrates with `@lanonasis/memory-sdk`:
|
|
54
|
+
|
|
23
55
|
```ts
|
|
24
|
-
|
|
56
|
+
const ai = new LanonasisAI({
|
|
57
|
+
apiKey: 'lnss_your_key',
|
|
58
|
+
memory: {
|
|
59
|
+
enabled: true,
|
|
60
|
+
autoSave: true,
|
|
61
|
+
contextStrategy: 'relevance',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Conversation automatically persists
|
|
66
|
+
const response = await ai.chat({
|
|
67
|
+
messages: [{ role: 'user', content: 'My name is Alex' }],
|
|
68
|
+
conversationId: 'user-123-session',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Use memory-sdk directly for advanced operations
|
|
72
|
+
const context = await ai.memory.searchWithContext('previous conversations');
|
|
73
|
+
const memories = await ai.memory.searchMemories({ query: 'Alex', limit: 5 });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Streaming Responses
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// Async iterator style
|
|
80
|
+
for await (const chunk of ai.chatStream({
|
|
81
|
+
messages: [{ role: 'user', content: 'Tell me a story' }],
|
|
82
|
+
})) {
|
|
83
|
+
process.stdout.write(chunk.choices[0]?.delta?.content || '');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Callback style
|
|
87
|
+
await ai.streamChat(
|
|
88
|
+
{ messages: [{ role: 'user', content: 'Count to 10' }] },
|
|
89
|
+
(chunk) => console.log(chunk.choices[0]?.delta?.content)
|
|
90
|
+
);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Orchestration
|
|
94
|
+
|
|
95
|
+
Use vortexai-l0 for complex workflows:
|
|
25
96
|
|
|
97
|
+
```ts
|
|
98
|
+
// Remote API orchestration (default)
|
|
99
|
+
const result = await ai.orchestrate('Create a viral TikTok campaign');
|
|
100
|
+
|
|
101
|
+
// Local orchestration (no API call)
|
|
102
|
+
const ai = new LanonasisAI({
|
|
103
|
+
apiKey: 'lnss_xxx',
|
|
104
|
+
useLocalOrchestration: true,
|
|
105
|
+
});
|
|
106
|
+
const result = await ai.orchestrate('analyze trending hashtags');
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## React Integration
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import { useLanonasis, useChat } from '@lanonasis/ai-sdk/react';
|
|
113
|
+
|
|
114
|
+
function ChatComponent() {
|
|
115
|
+
const { client, isReady } = useLanonasis({
|
|
116
|
+
apiKey: process.env.NEXT_PUBLIC_LANONASIS_KEY!,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const { messages, send, isLoading, sendWithStream } = useChat({
|
|
120
|
+
client,
|
|
121
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div>
|
|
126
|
+
{messages.map((msg, i) => (
|
|
127
|
+
<div key={i} className={msg.role}>{msg.content}</div>
|
|
128
|
+
))}
|
|
129
|
+
{isLoading && <div>Thinking...</div>}
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Configuration
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
new LanonasisAI({
|
|
139
|
+
apiKey: string; // Required: lnss_xxx or onasis_xxx
|
|
140
|
+
baseUrl?: string; // Default: https://api.lanonasis.com
|
|
141
|
+
memoryUrl?: string; // Default: same as baseUrl
|
|
142
|
+
timeout?: number; // Default: 30000 (30s)
|
|
143
|
+
maxRetries?: number; // Default: 3
|
|
144
|
+
debug?: boolean; // Default: false
|
|
145
|
+
organizationId?: string; // For multi-tenant setups
|
|
146
|
+
useLocalOrchestration?: bool // Use vortexai-l0 locally
|
|
147
|
+
memory?: {
|
|
148
|
+
enabled?: boolean; // Default: true
|
|
149
|
+
autoSave?: boolean; // Default: true
|
|
150
|
+
contextStrategy?: string; // 'relevance' | 'temporal' | 'hybrid'
|
|
151
|
+
maxContextTokens?: number; // Default: 4000
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Architecture
|
|
157
|
+
|
|
158
|
+
This SDK integrates with existing Lanonasis infrastructure:
|
|
159
|
+
|
|
160
|
+
- **@lanonasis/memory-sdk** - Persistent memory and context building
|
|
161
|
+
- **vortexai-l0** - Local orchestration engine
|
|
162
|
+
- **Backend API** - Chat completions and remote orchestration
|
|
163
|
+
|
|
164
|
+
## Migration from v0.1.0
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
// Old (v0.1.0)
|
|
168
|
+
import { AiSDK } from '@lanonasis/ai-sdk';
|
|
26
169
|
const sdk = new AiSDK();
|
|
27
|
-
|
|
28
|
-
|
|
170
|
+
await sdk.orchestrate('query');
|
|
171
|
+
|
|
172
|
+
// New (v0.2.0)
|
|
173
|
+
import { LanonasisAI } from '@lanonasis/ai-sdk';
|
|
174
|
+
const ai = new LanonasisAI({ apiKey: 'lnss_xxx' });
|
|
175
|
+
await ai.orchestrate('query');
|
|
176
|
+
// Or simple:
|
|
177
|
+
const message = await ai.send('query');
|
|
29
178
|
```
|
|
30
179
|
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
MIT
|
|
183
|
+
|
|
31
184
|
## Advanced (Plugins)
|
|
185
|
+
|
|
32
186
|
```ts
|
|
33
|
-
import {
|
|
187
|
+
import { LanonasisAI, createPluginManager } from '@lanonasis/ai-sdk';
|
|
34
188
|
|
|
35
189
|
const plugins = createPluginManager();
|
|
36
190
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,YAAyD,MAAM,kCAAkC,CAAC;AAGzG,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EAEnB,UAAU,EACV,cAAc,EACd,SAAS,EACT,YAAY,EAGb,MAAM,kBAAkB,CAAC;AAM1B,qBAAa,WAAW;IACtB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,iBAAiB,CAA+B;IACxD,OAAO,CAAC,aAAa,CAAgD;IAErE,+CAA+C;IAC/C,SAAgB,MAAM,EAAE,YAAY,CAAC;IAErC,wBAAwB;IACxB,SAAgB,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,GAAG;QAAE,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAA;KAAE,CAAC;gBAE9F,MAAM,EAAE,eAAe;IA2CnC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,IAAI;IAQvD,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIlD,OAAO,CAAC,IAAI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