@attrove/sdk 0.0.1 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +247 -0
  2. package/package.json +60 -1
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # @attrove/sdk
2
+
3
+ Official TypeScript SDK for the Attrove API. Access AI-powered context from your users' Gmail, Slack, Google Calendar, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @attrove/sdk
9
+ # or
10
+ yarn add @attrove/sdk
11
+ # or
12
+ pnpm add @attrove/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { Attrove } from '@attrove/sdk';
19
+
20
+ // Create a client
21
+ const attrove = new Attrove({
22
+ apiKey: 'sk_...', // API key from your dashboard
23
+ userId: 'user-uuid' // User ID from provisioning
24
+ });
25
+
26
+ // Query user's context
27
+ const response = await attrove.query('What meetings do I have tomorrow?');
28
+ console.log(response.answer);
29
+
30
+ // Search for specific information
31
+ const results = await attrove.search('quarterly report');
32
+ ```
33
+
34
+ ## Core Methods
35
+
36
+ ### `query(prompt, options?)`
37
+
38
+ Ask questions about the user's unified context with AI-generated answers.
39
+
40
+ ```typescript
41
+ // Simple query
42
+ const response = await attrove.query('What did Sarah say about the Q4 budget?');
43
+ console.log(response.answer);
44
+
45
+ // Multi-turn conversation - pass history from previous response
46
+ let history = response.history;
47
+ const followUp = await attrove.query('What about Q3?', { history });
48
+ // Update history for subsequent queries
49
+ history = followUp.history;
50
+
51
+ // With filters
52
+ const filtered = await attrove.query('Latest updates', {
53
+ integrationIds: ['integration-uuid'], // Only search specific integration
54
+ includeSources: true // Include source snippets
55
+ });
56
+ ```
57
+
58
+ ### `search(query, options?)`
59
+
60
+ Semantic search that returns raw messages without AI summarization.
61
+
62
+ ```typescript
63
+ const results = await attrove.search('product launch', {
64
+ afterDate: '2024-01-01T00:00:00Z',
65
+ senderDomains: ['acme.com'],
66
+ includeBodyText: true
67
+ });
68
+
69
+ for (const [convId, conv] of Object.entries(results.conversations)) {
70
+ console.log(`Conversation: ${conv.conversation_name}`);
71
+ }
72
+ ```
73
+
74
+ ## Resource Namespaces
75
+
76
+ ### Users
77
+
78
+ ```typescript
79
+ // Get user profile and integrations
80
+ const { user, integrations } = await attrove.users.get();
81
+
82
+ // Update user profile
83
+ await attrove.users.update({
84
+ timezone: 'America/New_York'
85
+ });
86
+
87
+ // Get sync statistics
88
+ const stats = await attrove.users.syncStats();
89
+ console.log(`Messages: ${stats.totals.messages.count}`);
90
+ ```
91
+
92
+ ### Messages
93
+
94
+ ```typescript
95
+ // List messages
96
+ const { data, pagination } = await attrove.messages.list({
97
+ limit: 20,
98
+ expand: ['body_text']
99
+ });
100
+
101
+ // Get specific messages (e.g., after a query)
102
+ const { data: messages } = await attrove.messages.list({
103
+ ids: response.used_message_ids,
104
+ expand: ['body_text']
105
+ });
106
+
107
+ // Get a single message by ID
108
+ const message = await attrove.messages.get('message-uuid');
109
+ ```
110
+
111
+ ### Conversations
112
+
113
+ ```typescript
114
+ // List conversations
115
+ const { data: conversations } = await attrove.conversations.list({
116
+ syncedOnly: true
117
+ });
118
+
119
+ // Update sync settings
120
+ await attrove.conversations.updateSync([
121
+ { id: 'conversation-uuid-1', importMessages: true },
122
+ { id: 'conversation-uuid-2', importMessages: false }
123
+ ]);
124
+ ```
125
+
126
+ ### Integrations
127
+
128
+ ```typescript
129
+ // List integrations
130
+ const integrations = await attrove.integrations.list();
131
+
132
+ // Disconnect an integration
133
+ await attrove.integrations.disconnect('integration-uuid');
134
+ ```
135
+
136
+ ## Server-to-Server (Admin) API
137
+
138
+ Use the admin client for operations that require partner authentication:
139
+
140
+ ```typescript
141
+ import { Attrove } from '@attrove/sdk';
142
+
143
+ // Create admin client
144
+ const admin = Attrove.admin({
145
+ clientId: 'your-client-id',
146
+ clientSecret: 'your-client-secret'
147
+ });
148
+
149
+ // Create a user
150
+ const { id, apiKey } = await admin.users.create({
151
+ email: 'user@example.com',
152
+ firstName: 'John',
153
+ lastName: 'Doe'
154
+ });
155
+
156
+ // Generate integration token for OAuth flow
157
+ const { token: connectToken, expires_at } = await admin.users.createConnectToken(id);
158
+
159
+ // Use the apiKey for subsequent API calls
160
+ const attrove = new Attrove({ apiKey, userId: id });
161
+
162
+ // Redirect user to OAuth flow
163
+ // The URL format depends on your deployment - check your dashboard for the exact URL
164
+ // Example: const oauthUrl = `${YOUR_BASE_URL}/connect/gmail?token=${connectToken}`;
165
+ ```
166
+
167
+ ## Error Handling
168
+
169
+ The SDK provides typed errors for better error handling:
170
+
171
+ ```typescript
172
+ import {
173
+ Attrove,
174
+ AttroveError,
175
+ AuthenticationError,
176
+ NotFoundError,
177
+ RateLimitError
178
+ } from '@attrove/sdk';
179
+
180
+ try {
181
+ const response = await attrove.query('...');
182
+ } catch (error) {
183
+ if (error instanceof AuthenticationError) {
184
+ console.log('Invalid API key');
185
+ } else if (error instanceof RateLimitError) {
186
+ console.log(`Rate limited. Retry after ${error.retryAfter}s`);
187
+ } else if (error instanceof NotFoundError) {
188
+ console.log('Resource not found');
189
+ } else if (error instanceof AttroveError) {
190
+ console.log(`Error: ${error.code} - ${error.message}`);
191
+ }
192
+ }
193
+ ```
194
+
195
+ ## Streaming (Advanced)
196
+
197
+ For real-time streaming of query responses:
198
+
199
+ ```typescript
200
+ const result = await attrove.stream('What happened in the meeting?', {
201
+ onChunk: (chunk) => process.stdout.write(chunk),
202
+ onState: (state) => console.log('State:', state),
203
+ onEnd: (reason) => console.log('Stream ended:', reason)
204
+ });
205
+
206
+ console.log('Full answer:', result.answer);
207
+ ```
208
+
209
+ > **Note:** Streaming uses WebSocket connections and requires the same API key authentication as other SDK methods. It is primarily intended for end-user facing applications where progressive display of responses improves the user experience.
210
+
211
+ ## Configuration
212
+
213
+ ```typescript
214
+ const attrove = new Attrove({
215
+ apiKey: 'sk_...', // Required: API key
216
+ userId: 'user-uuid', // Required: User ID
217
+ baseUrl: 'https://api.attrove.com', // Optional: API base URL
218
+ timeout: 30000, // Optional: Request timeout (ms)
219
+ maxRetries: 3 // Optional: Retry attempts
220
+ });
221
+ ```
222
+
223
+ ## TypeScript Support
224
+
225
+ The SDK is fully typed. Import types as needed:
226
+
227
+ ```typescript
228
+ import {
229
+ QueryOptions,
230
+ QueryResponse,
231
+ SearchOptions,
232
+ SearchResponse,
233
+ User,
234
+ Message,
235
+ Integration,
236
+ ConversationMessage
237
+ } from '@attrove/sdk';
238
+ ```
239
+
240
+ ## Requirements
241
+
242
+ - Node.js 18.0.0 or later
243
+ - TypeScript 4.7+ (if using TypeScript)
244
+
245
+ ## License
246
+
247
+ MIT
package/package.json CHANGED
@@ -1 +1,60 @@
1
- {"name":"@attrove/sdk","version":"0.0.1"}
1
+ {
2
+ "name": "@attrove/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Official TypeScript SDK for the Attrove API - AI-powered context retrieval for your apps",
5
+ "main": "./cjs/index.js",
6
+ "module": "./esm/index.js",
7
+ "types": "./types/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./types/src/index.d.ts",
12
+ "default": "./esm/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./types/src/index.d.ts",
16
+ "default": "./cjs/index.js"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "sideEffects": false,
25
+ "keywords": [
26
+ "attrove",
27
+ "sdk",
28
+ "api",
29
+ "ai",
30
+ "rag",
31
+ "retrieval-augmented-generation",
32
+ "context",
33
+ "llm"
34
+ ],
35
+ "author": "Attrove <support@attrove.com>",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/attrove/attrove-js.git",
40
+ "directory": "packages/sdk"
41
+ },
42
+ "homepage": "https://docs.attrove.com",
43
+ "bugs": {
44
+ "url": "https://github.com/attrove/attrove-js/issues"
45
+ },
46
+ "engines": {
47
+ "node": ">=18.0.0"
48
+ },
49
+ "scripts": {
50
+ "build": "nx build sdk",
51
+ "test": "nx test sdk"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^20.0.0",
55
+ "typescript": "~5.7.0"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ }
60
+ }