@mirra-messenger/sdk 0.4.0 → 0.5.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/README.md DELETED
@@ -1,470 +0,0 @@
1
- # Mirra SDK for TypeScript/JavaScript
2
-
3
- Official TypeScript/JavaScript SDK for the [Mirra API](https://docs.getmirra.app).
4
-
5
- Build, deploy, and monetize AI agents, serverless scripts, and API integrations with a simple, type-safe client library.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install @mirra-messenger/sdk
11
- ```
12
-
13
- or with yarn:
14
-
15
- ```bash
16
- yarn add @mirra-messenger/sdk
17
- ```
18
-
19
- ## Quick Start
20
-
21
- ```typescript
22
- import { MirraSDK } from '@mirra-messenger/sdk';
23
-
24
- // Initialize the SDK with your API key
25
- const mirra = new MirraSDK({
26
- apiKey: 'your_api_key_here'
27
- });
28
-
29
- // Create a memory
30
- const memory = await mirra.memory.create({
31
- content: 'Important information to remember',
32
- type: 'note',
33
- metadata: { category: 'work' }
34
- });
35
-
36
- // Chat with AI
37
- const response = await mirra.ai.chat({
38
- messages: [
39
- { role: 'user', content: 'Hello, how are you?' }
40
- ]
41
- });
42
-
43
- console.log(response.content);
44
- ```
45
-
46
- ## Authentication
47
-
48
- Get your API key from the Mirra mobile app:
49
- 1. Open the Mirra app
50
- 2. Go to **Settings** → **API Keys**
51
- 3. Click **Generate New Key**
52
- 4. Copy your API key
53
-
54
- ⚠️ **Keep your API key secure!** Never commit it to version control or expose it in client-side code.
55
-
56
- ## Usage Examples
57
-
58
- ### Memory Operations
59
-
60
- Store and retrieve information in Mirra's knowledge graph with semantic search.
61
-
62
- ```typescript
63
- // Create a memory entity
64
- const memory = await mirra.memory.create({
65
- type: 'task',
66
- content: 'Buy groceries: milk, eggs, bread',
67
- metadata: { priority: 'high', dueDate: '2025-11-20' }
68
- });
69
-
70
- console.log(`Created memory with ID: ${memory.id}`);
71
-
72
- // Search memories semantically
73
- const results = await mirra.memory.search({
74
- query: 'grocery shopping',
75
- limit: 10
76
- });
77
-
78
- results.forEach(result => {
79
- console.log(`[${result.score}] ${result.content}`);
80
- });
81
-
82
- // Query memories with filters
83
- const tasks = await mirra.memory.query({
84
- type: 'task',
85
- limit: 20,
86
- offset: 0
87
- });
88
-
89
- // Find a specific memory
90
- const found = await mirra.memory.findOne({
91
- filters: { id: memory.id }
92
- });
93
-
94
- // Update a memory
95
- await mirra.memory.update({
96
- id: memory.id,
97
- content: 'Updated: Buy groceries and vegetables',
98
- metadata: { priority: 'medium', completed: false }
99
- });
100
-
101
- // Delete a memory
102
- await mirra.memory.delete(memory.id);
103
- ```
104
-
105
- #### Memory Types
106
-
107
- Supported entity types:
108
- - `task` - Tasks and todos
109
- - `topic` - Discussion topics and themes
110
- - `document` - Documents and notes
111
- - `contact` - Contact information
112
- - `event` - Calendar events and meetings
113
- - `idea` - Ideas and brainstorming notes
114
-
115
- ### AI Operations
116
-
117
- Access powerful AI capabilities with multi-provider support (Anthropic Claude, Google Gemini, OpenAI).
118
-
119
- #### Chat
120
-
121
- Simple conversational AI with support for system prompts and multi-turn conversations.
122
-
123
- ```typescript
124
- // Basic chat
125
- const response = await mirra.ai.chat({
126
- messages: [
127
- { role: 'user', content: 'Explain quantum computing in simple terms' }
128
- ]
129
- });
130
-
131
- console.log(response.content);
132
- console.log(`Tokens used: ${response.usage.inputTokens + response.usage.outputTokens}`);
133
-
134
- // Multi-turn conversation with system prompt
135
- const chat = await mirra.ai.chat({
136
- messages: [
137
- { role: 'system', content: 'You are a helpful coding assistant.' },
138
- { role: 'user', content: 'How do I reverse a string in Python?' },
139
- { role: 'assistant', content: 'You can reverse a string using slicing: text[::-1]' },
140
- { role: 'user', content: 'Can you show me with a function?' }
141
- ],
142
- provider: 'anthropic',
143
- model: 'claude-3-5-sonnet-20241022',
144
- temperature: 0.7,
145
- maxTokens: 1000
146
- });
147
- ```
148
-
149
- #### Streaming
150
-
151
- Stream AI responses in real-time for better user experience.
152
-
153
- ```typescript
154
- const stream = mirra.ai.chatStream({
155
- messages: [
156
- { role: 'user', content: 'Write a short story about a robot learning to paint' }
157
- ],
158
- provider: 'anthropic',
159
- model: 'claude-3-haiku-20240307'
160
- });
161
-
162
- // Process chunks as they arrive
163
- for await (const chunk of stream) {
164
- if (chunk.done) {
165
- console.log('\n\nStream complete!');
166
- console.log(`Tokens: ${chunk.usage?.inputTokens} in, ${chunk.usage?.outputTokens} out`);
167
- } else {
168
- process.stdout.write(chunk.delta);
169
- }
170
- }
171
- ```
172
-
173
- #### Decision Making
174
-
175
- Get structured AI decisions from multiple options with reasoning.
176
-
177
- ```typescript
178
- const decision = await mirra.ai.decide({
179
- prompt: 'Which programming language should I learn first?',
180
- options: [
181
- { id: 'python', label: 'Python', metadata: { difficulty: 'easy', versatile: true } },
182
- { id: 'javascript', label: 'JavaScript', metadata: { difficulty: 'medium', webFocused: true } },
183
- { id: 'rust', label: 'Rust', metadata: { difficulty: 'hard', performant: true } }
184
- ],
185
- context: 'I want to build web applications and have no prior coding experience',
186
- provider: 'anthropic',
187
- model: 'claude-3-haiku-20240307'
188
- });
189
-
190
- console.log(`Selected: ${decision.selectedOption}`);
191
- console.log(`Reasoning: ${decision.reasoning}`);
192
- ```
193
-
194
- #### Batch Processing
195
-
196
- Process multiple AI requests efficiently in a single call.
197
-
198
- ```typescript
199
- const batch = await mirra.ai.batchChat({
200
- requests: [
201
- { message: 'What is 2+2?' },
202
- { message: 'What is the capital of France?' },
203
- { message: 'Explain photosynthesis briefly' }
204
- ]
205
- });
206
-
207
- batch.forEach((response, index) => {
208
- console.log(`Response ${index + 1}:`, response.content);
209
- });
210
- ```
211
-
212
- #### Supported Providers & Models
213
-
214
- **Anthropic Claude:**
215
- - `claude-3-haiku-20240307` - Fast, cost-effective
216
- - `claude-3-sonnet-20240229` - Balanced performance
217
- - `claude-3-5-sonnet-20241022` - Advanced reasoning (default)
218
- - `claude-3-opus-20240229` - Highest quality
219
-
220
- **Google Gemini:**
221
- - `gemini-2.5-flash` - Fast, efficient
222
- - `gemini-2.5-pro` - Advanced capabilities
223
-
224
- **OpenAI GPT:**
225
- - `gpt-4o` - Latest GPT-4 Optimized
226
- - `gpt-4o-mini` - Compact and fast
227
- - Coming soon
228
-
229
- #### Token Consumption
230
-
231
- All AI operations consume tokens from your account balance. Monitor your usage:
232
- - Input tokens: Your messages and context
233
- - Output tokens: AI's responses
234
-
235
- View your balance in the Mirra app under Settings → API & Billing.
236
-
237
- ### Agent Management
238
-
239
- ```typescript
240
- // Create an agent
241
- const agent = await mirra.agents.create({
242
- subdomain: 'my-assistant',
243
- name: 'My Personal Assistant',
244
- systemPrompt: 'You are a helpful personal assistant.',
245
- description: 'An AI assistant for daily tasks',
246
- enabled: true
247
- });
248
-
249
- // List agents
250
- const agents = await mirra.agents.list();
251
-
252
- // Update an agent
253
- await mirra.agents.update(agent.id, {
254
- name: 'Updated Assistant Name',
255
- enabled: false
256
- });
257
-
258
- // Delete an agent
259
- await mirra.agents.delete(agent.id);
260
- ```
261
-
262
- ### Script Operations
263
-
264
- ```typescript
265
- // Create a script
266
- const script = await mirra.scripts.create({
267
- name: 'Data Processor',
268
- description: 'Processes incoming data',
269
- code: `
270
- export async function handler(event, context, mirra) {
271
- // Your script logic here
272
- const result = await mirra.memory.search({
273
- query: event.query,
274
- limit: 5
275
- });
276
-
277
- return { success: true, results: result };
278
- }
279
- `,
280
- runtime: 'nodejs18',
281
- config: {
282
- timeout: 30,
283
- memory: 256,
284
- allowedResources: []
285
- }
286
- });
287
-
288
- // Deploy a script
289
- await mirra.scripts.deploy(script.id);
290
-
291
- // Invoke a script
292
- const result = await mirra.scripts.invoke({
293
- scriptId: script.id,
294
- payload: { query: 'test data' }
295
- });
296
-
297
- console.log(result);
298
- ```
299
-
300
- ### Resource Operations
301
-
302
- ```typescript
303
- // List available resources
304
- const resources = await mirra.resources.list();
305
-
306
- // Call a resource method
307
- const result = await mirra.resources.call({
308
- resourceId: 'weather-api',
309
- method: 'getCurrentWeather',
310
- params: { city: 'San Francisco' }
311
- });
312
- ```
313
-
314
- ### Document Operations
315
-
316
- Upload, manage, and search documents with semantic search and multi-graph sharing.
317
-
318
- ```typescript
319
- import { readFileSync } from 'fs';
320
-
321
- // Upload a document
322
- const fileBuffer = readFileSync('report.pdf');
323
- const uploadResult = await mirra.documents.upload({
324
- file: fileBuffer.toString('base64'),
325
- filename: 'report.pdf',
326
- mimeType: 'application/pdf',
327
- title: 'Q4 Financial Report',
328
- productTags: ['finance', 'quarterly']
329
- });
330
-
331
- console.log(`Uploaded: ${uploadResult.documentId}`);
332
- console.log(`Chunks: ${uploadResult.chunkCount}`);
333
-
334
- // List documents
335
- const docs = await mirra.documents.list({ limit: 20 });
336
- console.log(`Found ${docs.count} documents`);
337
-
338
- // Get document details
339
- const doc = await mirra.documents.get(uploadResult.documentId);
340
- console.log(`Title: ${doc.document.title}`);
341
- console.log(`Chunks: ${doc.chunkCount}`);
342
-
343
- // Search documents semantically
344
- const searchResults = await mirra.documents.search({
345
- query: 'quarterly earnings revenue',
346
- limit: 10,
347
- threshold: 0.7
348
- });
349
-
350
- searchResults.results.forEach(result => {
351
- console.log(`[${result.score.toFixed(2)}] ${result.content.substring(0, 100)}...`);
352
- });
353
-
354
- // Share document to a group
355
- await mirra.documents.share(uploadResult.documentId, {
356
- targetGraphId: 'group-123',
357
- shareReason: 'For team review'
358
- });
359
-
360
- // List where a document is shared
361
- const graphs = await mirra.documents.listGraphs(uploadResult.documentId);
362
- graphs.graphs.forEach(g => {
363
- console.log(`Shared in: ${g.graphId} (primary: ${g.isPrimary})`);
364
- });
365
-
366
- // Remove sharing from a graph
367
- await mirra.documents.unshare(uploadResult.documentId, 'group-123');
368
-
369
- // Delete a document
370
- await mirra.documents.delete(uploadResult.documentId);
371
- ```
372
-
373
- #### Supported Document Types
374
-
375
- - PDF (`.pdf`) - `application/pdf`
376
- - Word (`.docx`) - `application/vnd.openxmlformats-officedocument.wordprocessingml.document`
377
- - Plain Text (`.txt`) - `text/plain`
378
- - Markdown (`.md`) - `text/markdown`
379
-
380
- ### Template Operations
381
-
382
- ```typescript
383
- // List templates
384
- const templates = await mirra.templates.list();
385
-
386
- // Get template details
387
- const template = await mirra.templates.get('template-id');
388
-
389
- // Install a template
390
- await mirra.templates.install('template-id');
391
- ```
392
-
393
- ### Marketplace
394
-
395
- ```typescript
396
- // Browse marketplace
397
- const items = await mirra.marketplace.browse({
398
- type: 'agent',
399
- category: 'productivity',
400
- limit: 20
401
- });
402
-
403
- // Search marketplace
404
- const searchResults = await mirra.marketplace.search('weather assistant');
405
- ```
406
-
407
- ## Configuration
408
-
409
- ### Custom Base URL
410
-
411
- For development or custom deployments:
412
-
413
- ```typescript
414
- const mirra = new MirraSDK({
415
- apiKey: 'your_api_key',
416
- baseUrl: 'http://localhost:3000/api/sdk/v1'
417
- });
418
- ```
419
-
420
- ### Error Handling
421
-
422
- All SDK methods throw errors that include:
423
- - `message`: Human-readable error message
424
- - `code`: Error code (e.g., 'VALIDATION_ERROR', 'NOT_FOUND')
425
- - `statusCode`: HTTP status code
426
- - `details`: Additional error details (if available)
427
-
428
- ```typescript
429
- try {
430
- await mirra.memory.create({ content: '' }); // Invalid: empty content
431
- } catch (error) {
432
- console.error('Error code:', error.code);
433
- console.error('Message:', error.message);
434
- console.error('Status:', error.statusCode);
435
- console.error('Details:', error.details);
436
- }
437
- ```
438
-
439
- ## TypeScript Support
440
-
441
- This SDK is written in TypeScript and provides full type definitions out of the box. No additional `@types` packages needed!
442
-
443
- ```typescript
444
- import { MirraSDK, ChatMessage, Agent } from '@mirra-messenger/sdk';
445
-
446
- const messages: ChatMessage[] = [
447
- { role: 'user', content: 'Hello!' }
448
- ];
449
-
450
- const agent: Agent = await mirra.agents.create({
451
- subdomain: 'test',
452
- name: 'Test Agent',
453
- systemPrompt: 'You are helpful.'
454
- });
455
- ```
456
-
457
- ## API Reference
458
-
459
- For complete API documentation, visit [https://docs.getmirra.app](https://docs.getmirra.app)
460
-
461
- ## Support
462
-
463
- - **Documentation**: [https://docs.getmirra.app](https://docs.getmirra.app)
464
- - **Issues**: [GitHub Issues](https://github.com/Oz-Networks/fxn-monorepo/issues)
465
- - **Email**: support@getmirra.app
466
-
467
- ## License
468
-
469
- MIT
470
-