@attrove/sdk 0.1.3 → 0.1.5

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 (107) hide show
  1. package/cjs/README.md +247 -0
  2. package/cjs/package.json +56 -0
  3. package/cjs/src/__mocks__/version.js +17 -0
  4. package/cjs/src/__mocks__/version.js.map +1 -0
  5. package/cjs/src/admin-client.js +221 -0
  6. package/cjs/src/admin-client.js.map +1 -0
  7. package/cjs/src/client.js +312 -0
  8. package/cjs/src/client.js.map +1 -0
  9. package/cjs/src/constants.js +69 -0
  10. package/cjs/src/constants.js.map +1 -0
  11. package/cjs/src/errors/index.js +307 -0
  12. package/cjs/src/errors/index.js.map +1 -0
  13. package/cjs/src/index.js +98 -0
  14. package/cjs/src/index.js.map +1 -0
  15. package/cjs/src/resources/conversations.js +95 -0
  16. package/cjs/src/resources/conversations.js.map +1 -0
  17. package/cjs/src/resources/index.js +17 -0
  18. package/cjs/src/resources/index.js.map +1 -0
  19. package/cjs/src/resources/integrations.js +69 -0
  20. package/cjs/src/resources/integrations.js.map +1 -0
  21. package/cjs/src/resources/messages.js +98 -0
  22. package/cjs/src/resources/messages.js.map +1 -0
  23. package/cjs/src/resources/query.js +143 -0
  24. package/cjs/src/resources/query.js.map +1 -0
  25. package/cjs/src/resources/users.js +91 -0
  26. package/cjs/src/resources/users.js.map +1 -0
  27. package/cjs/src/types/index.js +292 -0
  28. package/cjs/src/types/index.js.map +1 -0
  29. package/cjs/src/utils/fetch.js +417 -0
  30. package/cjs/src/utils/fetch.js.map +1 -0
  31. package/cjs/src/utils/index.js +12 -0
  32. package/cjs/src/utils/index.js.map +1 -0
  33. package/cjs/src/utils/streaming.js +368 -0
  34. package/cjs/src/utils/streaming.js.map +1 -0
  35. package/cjs/src/version.js +31 -0
  36. package/cjs/src/version.js.map +1 -0
  37. package/esm/README.md +247 -0
  38. package/esm/package.json +56 -0
  39. package/esm/src/__mocks__/version.js +12 -0
  40. package/esm/src/__mocks__/version.js.map +1 -0
  41. package/esm/src/admin-client.js +216 -0
  42. package/esm/src/admin-client.js.map +1 -0
  43. package/esm/src/client.js +308 -0
  44. package/esm/src/client.js.map +1 -0
  45. package/esm/src/constants.js +65 -0
  46. package/esm/src/constants.js.map +1 -0
  47. package/esm/src/errors/index.js +285 -0
  48. package/esm/src/errors/index.js.map +1 -0
  49. package/esm/src/index.js +68 -0
  50. package/esm/src/index.js.map +1 -0
  51. package/esm/src/resources/conversations.js +91 -0
  52. package/esm/src/resources/conversations.js.map +1 -0
  53. package/esm/src/resources/index.js +9 -0
  54. package/esm/src/resources/index.js.map +1 -0
  55. package/esm/src/resources/integrations.js +65 -0
  56. package/esm/src/resources/integrations.js.map +1 -0
  57. package/esm/src/resources/messages.js +94 -0
  58. package/esm/src/resources/messages.js.map +1 -0
  59. package/esm/src/resources/query.js +139 -0
  60. package/esm/src/resources/query.js.map +1 -0
  61. package/esm/src/resources/users.js +87 -0
  62. package/esm/src/resources/users.js.map +1 -0
  63. package/esm/src/types/index.js +277 -0
  64. package/esm/src/types/index.js.map +1 -0
  65. package/esm/src/utils/fetch.js +413 -0
  66. package/esm/src/utils/fetch.js.map +1 -0
  67. package/esm/src/utils/index.js +6 -0
  68. package/esm/src/utils/index.js.map +1 -0
  69. package/esm/src/utils/streaming.js +363 -0
  70. package/esm/src/utils/streaming.js.map +1 -0
  71. package/esm/src/version.js +26 -0
  72. package/esm/src/version.js.map +1 -0
  73. package/package.json +16 -9
  74. package/types/src/__mocks__/version.d.ts +8 -0
  75. package/types/src/__mocks__/version.d.ts.map +1 -0
  76. package/types/src/admin-client.d.ts +144 -0
  77. package/types/src/admin-client.d.ts.map +1 -0
  78. package/types/src/client.d.ts +233 -0
  79. package/types/src/client.d.ts.map +1 -0
  80. package/types/src/constants.d.ts +47 -0
  81. package/types/src/constants.d.ts.map +1 -0
  82. package/types/src/errors/index.d.ts +206 -0
  83. package/types/src/errors/index.d.ts.map +1 -0
  84. package/types/src/index.d.ts +65 -0
  85. package/types/src/index.d.ts.map +1 -0
  86. package/types/src/resources/conversations.d.ts +81 -0
  87. package/types/src/resources/conversations.d.ts.map +1 -0
  88. package/types/src/resources/index.d.ts +12 -0
  89. package/types/src/resources/index.d.ts.map +1 -0
  90. package/types/src/resources/integrations.d.ts +63 -0
  91. package/types/src/resources/integrations.d.ts.map +1 -0
  92. package/types/src/resources/messages.d.ts +69 -0
  93. package/types/src/resources/messages.d.ts.map +1 -0
  94. package/types/src/resources/query.d.ts +86 -0
  95. package/types/src/resources/query.d.ts.map +1 -0
  96. package/types/src/resources/users.d.ts +88 -0
  97. package/types/src/resources/users.d.ts.map +1 -0
  98. package/types/src/types/index.d.ts +807 -0
  99. package/types/src/types/index.d.ts.map +1 -0
  100. package/types/src/utils/fetch.d.ts +161 -0
  101. package/types/src/utils/fetch.d.ts.map +1 -0
  102. package/types/src/utils/index.d.ts +8 -0
  103. package/types/src/utils/index.d.ts.map +1 -0
  104. package/types/src/utils/streaming.d.ts +210 -0
  105. package/types/src/utils/streaming.d.ts.map +1 -0
  106. package/types/src/version.d.ts +21 -0
  107. package/types/src/version.d.ts.map +1 -0
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@attrove/sdk",
3
+ "version": "0.1.5",
4
+ "description": "Official TypeScript SDK for the Attrove API - AI-powered context retrieval for your apps",
5
+ "main": "./src/index.ts",
6
+ "module": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.ts",
11
+ "import": "./src/index.ts",
12
+ "require": "./src/index.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "sideEffects": false,
20
+ "keywords": [
21
+ "attrove",
22
+ "sdk",
23
+ "api",
24
+ "ai",
25
+ "rag",
26
+ "retrieval-augmented-generation",
27
+ "context",
28
+ "llm"
29
+ ],
30
+ "author": "Attrove <support@attrove.com>",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/attrove/attrove-js.git",
35
+ "directory": "packages/sdk"
36
+ },
37
+ "homepage": "https://docs.attrove.com",
38
+ "bugs": {
39
+ "url": "https://github.com/attrove/attrove-js/issues"
40
+ },
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "scripts": {
45
+ "build": "nx build sdk",
46
+ "test": "nx test sdk"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^20.0.0",
50
+ "typescript": "~5.7.0"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "type": "module"
56
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Mock version module for Jest tests.
3
+ *
4
+ * This avoids the import.meta.url ESM issue when running tests with ts-jest.
5
+ */
6
+ export function getVersion() {
7
+ return '1.0.0-test';
8
+ }
9
+ export function resetVersionCache() {
10
+ // No-op in mock
11
+ }
12
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../../../../packages/sdk/src/__mocks__/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,UAAU,UAAU;IACxB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,gBAAgB;AAClB,CAAC"}
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Attrove Admin Client
3
+ *
4
+ * Server-to-server client for partner operations like user provisioning
5
+ * and integration token generation.
6
+ */
7
+ import { HttpClient } from './utils/fetch';
8
+ import { ValidationError } from './errors';
9
+ import { ErrorCodes } from './types';
10
+ import { isValidUUID, } from './types';
11
+ import { DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES } from './constants';
12
+ /**
13
+ * Validate the admin client configuration.
14
+ *
15
+ * @throws {ValidationError} If the configuration is invalid
16
+ */
17
+ function validateAdminConfig(config) {
18
+ // Validate clientId
19
+ if (!config.clientId || typeof config.clientId !== 'string') {
20
+ throw new ValidationError('clientId is required and must be a non-empty string', ErrorCodes.VALIDATION_REQUIRED_FIELD, { field: 'clientId' });
21
+ }
22
+ // Validate clientSecret
23
+ if (!config.clientSecret || typeof config.clientSecret !== 'string') {
24
+ throw new ValidationError('clientSecret is required and must be a non-empty string', ErrorCodes.VALIDATION_REQUIRED_FIELD, { field: 'clientSecret' });
25
+ }
26
+ // Validate optional fields
27
+ if (config.timeout !== undefined && (typeof config.timeout !== 'number' || config.timeout <= 0)) {
28
+ throw new ValidationError('timeout must be a positive number in milliseconds', ErrorCodes.VALIDATION_OUT_OF_RANGE, { field: 'timeout', value: config.timeout });
29
+ }
30
+ if (config.maxRetries !== undefined && (typeof config.maxRetries !== 'number' || config.maxRetries < 0)) {
31
+ throw new ValidationError('maxRetries must be a non-negative number', ErrorCodes.VALIDATION_OUT_OF_RANGE, { field: 'maxRetries', value: config.maxRetries });
32
+ }
33
+ }
34
+ /**
35
+ * Users admin resource for managing users.
36
+ *
37
+ * Provides methods for creating users, generating integration tokens,
38
+ * and managing user data.
39
+ */
40
+ export class AdminUsersResource {
41
+ constructor(http, clientId) {
42
+ this.http = http;
43
+ this.clientId = clientId;
44
+ }
45
+ /**
46
+ * Create or retrieve a user.
47
+ *
48
+ * Creates a new user by email, or retrieves an existing user if one exists.
49
+ * Returns an API key (sk_) for authenticating requests on behalf of this user.
50
+ *
51
+ * @param options - User creation options
52
+ * @returns User ID and API key
53
+ *
54
+ * @throws {ValidationError} If the email is invalid
55
+ * @throws {AuthenticationError} If partner credentials are invalid
56
+ * @throws {RateLimitError} If rate limits are exceeded
57
+ * @throws {NetworkError} If unable to reach the API
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const admin = Attrove.admin({ clientId, clientSecret });
62
+ *
63
+ * const { id, apiKey } = await admin.users.create({
64
+ * email: 'user@example.com',
65
+ * firstName: 'John',
66
+ * lastName: 'Doe'
67
+ * });
68
+ *
69
+ * // Use the apiKey to make API calls on behalf of this user
70
+ * const attrove = new Attrove({ apiKey, userId: id });
71
+ * ```
72
+ */
73
+ async create(options) {
74
+ const body = {
75
+ email: options.email,
76
+ client_id: this.clientId,
77
+ };
78
+ if (options.firstName)
79
+ body.first_name = options.firstName;
80
+ if (options.lastName)
81
+ body.last_name = options.lastName;
82
+ if (options.role)
83
+ body.role = options.role;
84
+ // API returns { id, token } but we rename to { id, apiKey } for clarity
85
+ // Route: POST /v1/users with X-Auth-Type: partner header
86
+ const response = await this.http.post('/v1/users', body);
87
+ return {
88
+ id: response.id,
89
+ apiKey: response.token,
90
+ };
91
+ }
92
+ /**
93
+ * Create an integration token for a user.
94
+ *
95
+ * Generates a short-lived token (pit_) for initiating OAuth flows.
96
+ * Use this token to redirect end-users to connect their integrations.
97
+ *
98
+ * @param userId - User ID (UUID format)
99
+ * @returns Integration token and expiration time
100
+ *
101
+ * @throws {ValidationError} If the userId is not a valid UUID
102
+ * @throws {AuthenticationError} If partner credentials are invalid
103
+ * @throws {NotFoundError} If the user doesn't exist
104
+ * @throws {RateLimitError} If rate limits are exceeded
105
+ * @throws {NetworkError} If unable to reach the API
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const admin = Attrove.admin({ clientId, clientSecret });
110
+ *
111
+ * const { token, expires_at } = await admin.users.createConnectToken(userId);
112
+ *
113
+ * // Redirect user to OAuth flow with this token
114
+ * const oauthUrl = `https://connect.attrove.com/oauth/gmail?token=${token}`;
115
+ * ```
116
+ */
117
+ async createConnectToken(userId) {
118
+ // Validate userId format
119
+ if (!isValidUUID(userId)) {
120
+ throw new ValidationError('userId must be a valid UUID format', ErrorCodes.VALIDATION_INVALID_FORMAT, { field: 'userId', expected: 'UUID format' });
121
+ }
122
+ const body = {
123
+ client_id: this.clientId,
124
+ };
125
+ // Route: POST /v1/users/:user_id/tokens with X-Auth-Type: partner header
126
+ return this.http.post(`/v1/users/${userId}/tokens`, body);
127
+ }
128
+ /**
129
+ * Delete a user.
130
+ *
131
+ * Permanently deletes a user and all associated data.
132
+ *
133
+ * @experimental This method is not yet implemented and will throw an error.
134
+ *
135
+ * @param userId - User ID (UUID format)
136
+ *
137
+ * @throws {Error} Always throws - not yet implemented
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * // Not yet available
142
+ * const admin = Attrove.admin({ clientId, clientSecret });
143
+ * await admin.users.delete(userId);
144
+ * ```
145
+ */
146
+ async delete(userId) {
147
+ // TODO: Implement user deletion endpoint
148
+ throw new Error('User deletion not yet implemented. This feature is coming soon.');
149
+ }
150
+ }
151
+ /**
152
+ * Admin client for server-to-server operations.
153
+ *
154
+ * Use this client for operations that require partner authentication:
155
+ * - Creating users
156
+ * - Generating integration tokens
157
+ * - Managing user data
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * import { Attrove } from '@attrove/sdk';
162
+ *
163
+ * const admin = Attrove.admin({
164
+ * clientId: 'your-client-id',
165
+ * clientSecret: 'your-client-secret'
166
+ * });
167
+ *
168
+ * // Create a user
169
+ * const { id, apiKey } = await admin.users.create({
170
+ * email: 'user@example.com'
171
+ * });
172
+ *
173
+ * // Generate an integration token
174
+ * const { token: connectToken } = await admin.users.createConnectToken(id);
175
+ * ```
176
+ */
177
+ export class AttroveAdmin {
178
+ /**
179
+ * Create a new admin client.
180
+ *
181
+ * @param config - Admin client configuration
182
+ * @throws {ValidationError} If the configuration is invalid (missing clientId, clientSecret, etc.)
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * const admin = new AttroveAdmin({
187
+ * clientId: 'your-client-id',
188
+ * clientSecret: 'your-client-secret',
189
+ * timeout: 60000 // 60 seconds
190
+ * });
191
+ * ```
192
+ */
193
+ constructor(config) {
194
+ // Validate configuration before proceeding
195
+ validateAdminConfig(config);
196
+ this.config = {
197
+ clientId: config.clientId,
198
+ clientSecret: config.clientSecret,
199
+ baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
200
+ timeout: config.timeout ?? DEFAULT_TIMEOUT,
201
+ maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,
202
+ onRetry: config.onRetry,
203
+ };
204
+ this.http = new HttpClient({
205
+ baseUrl: this.config.baseUrl,
206
+ clientId: this.config.clientId,
207
+ clientSecret: this.config.clientSecret,
208
+ timeout: this.config.timeout,
209
+ maxRetries: this.config.maxRetries,
210
+ onRetry: this.config.onRetry,
211
+ });
212
+ // Initialize resources
213
+ this.users = new AdminUsersResource(this.http, this.config.clientId);
214
+ }
215
+ }
216
+ //# sourceMappingURL=admin-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-client.js","sourceRoot":"","sources":["../../../../../packages/sdk/src/admin-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAKL,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErF;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,MAA0B;IACrD,oBAAoB;IACpB,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC5D,MAAM,IAAI,eAAe,CACvB,qDAAqD,EACrD,UAAU,CAAC,yBAAyB,EACpC,EAAE,KAAK,EAAE,UAAU,EAAE,CACtB,CAAC;IACJ,CAAC;IAED,wBAAwB;IACxB,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;QACpE,MAAM,IAAI,eAAe,CACvB,yDAAyD,EACzD,UAAU,CAAC,yBAAyB,EACpC,EAAE,KAAK,EAAE,cAAc,EAAE,CAC1B,CAAC;IACJ,CAAC;IAED,2BAA2B;IAC3B,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,OAAO,MAA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AO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC;QAEF,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC;YACzB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9B,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;YACtC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;SAC7B,CAAC,CAAC;QAEH,uBAAuB;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACvE,CAAC;CACF"}
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Attrove Client
3
+ *
4
+ * Main entry point for the Attrove SDK. Provides a simple, intuitive API
5
+ * for accessing user context through connected integrations.
6
+ */
7
+ import { HttpClient } from './utils/fetch';
8
+ import { StreamingClient, generateMessageId } from './utils/streaming';
9
+ import { UsersResource } from './resources/users';
10
+ import { MessagesResource } from './resources/messages';
11
+ import { ConversationsResource } from './resources/conversations';
12
+ import { IntegrationsResource } from './resources/integrations';
13
+ import { QueryResource } from './resources/query';
14
+ import { ValidationError } from './errors';
15
+ import { ErrorCodes } from './types';
16
+ import { isValidUUID, } from './types';
17
+ import { DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES } from './constants';
18
+ /**
19
+ * Validate the Attrove client configuration.
20
+ *
21
+ * @throws {ValidationError} If the configuration is invalid
22
+ */
23
+ function validateConfig(config) {
24
+ // Validate apiKey
25
+ if (!config.apiKey || typeof config.apiKey !== 'string') {
26
+ throw new ValidationError('apiKey is required and must be a non-empty string', ErrorCodes.VALIDATION_REQUIRED_FIELD, { field: 'apiKey' });
27
+ }
28
+ if (!config.apiKey.startsWith('sk_')) {
29
+ throw new ValidationError('apiKey must start with "sk_" prefix. Make sure you are using a valid API key.', ErrorCodes.VALIDATION_INVALID_FORMAT, { field: 'apiKey', expected: 'sk_...' });
30
+ }
31
+ // Validate userId
32
+ if (!config.userId || typeof config.userId !== 'string') {
33
+ throw new ValidationError('userId is required and must be a non-empty string', ErrorCodes.VALIDATION_REQUIRED_FIELD, { field: 'userId' });
34
+ }
35
+ if (!isValidUUID(config.userId)) {
36
+ throw new ValidationError('userId must be a valid UUID format (e.g., "123e4567-e89b-12d3-a456-426614174000")', ErrorCodes.VALIDATION_INVALID_FORMAT, { field: 'userId', expected: 'UUID format' });
37
+ }
38
+ // Validate optional fields
39
+ if (config.timeout !== undefined && (typeof config.timeout !== 'number' || config.timeout <= 0)) {
40
+ throw new ValidationError('timeout must be a positive number in milliseconds', ErrorCodes.VALIDATION_OUT_OF_RANGE, { field: 'timeout', value: config.timeout });
41
+ }
42
+ if (config.maxRetries !== undefined && (typeof config.maxRetries !== 'number' || config.maxRetries < 0)) {
43
+ throw new ValidationError('maxRetries must be a non-negative number', ErrorCodes.VALIDATION_OUT_OF_RANGE, { field: 'maxRetries', value: config.maxRetries });
44
+ }
45
+ }
46
+ /**
47
+ * The Attrove client for accessing user context.
48
+ *
49
+ * This is the main entry point for the Attrove SDK. It provides methods for:
50
+ * - Querying user context with AI (query, search)
51
+ * - Streaming query responses in real-time
52
+ * - Accessing user data, messages, conversations, and integrations
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { Attrove } from '@attrove/sdk';
57
+ *
58
+ * const attrove = new Attrove({
59
+ * apiKey: 'sk_...',
60
+ * userId: 'user-uuid'
61
+ * });
62
+ *
63
+ * // Query user's context
64
+ * const response = await attrove.query('What meetings do I have tomorrow?');
65
+ * console.log(response.answer);
66
+ *
67
+ * // Search for specific information
68
+ * const results = await attrove.search('quarterly report');
69
+ * ```
70
+ */
71
+ export class Attrove {
72
+ /**
73
+ * Create a new Attrove client.
74
+ *
75
+ * @param config - Client configuration
76
+ * @throws {ValidationError} If the configuration is invalid (missing apiKey, invalid userId format, etc.)
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const attrove = new Attrove({
81
+ * apiKey: 'sk_...',
82
+ * userId: 'user-uuid',
83
+ * timeout: 60000, // 60 seconds
84
+ * onRetry: (info) => console.log(`Retrying (${info.attempt}/${info.maxRetries})...`)
85
+ * });
86
+ * ```
87
+ */
88
+ constructor(config) {
89
+ // Validate configuration before proceeding
90
+ validateConfig(config);
91
+ this.config = {
92
+ apiKey: config.apiKey,
93
+ userId: config.userId,
94
+ baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
95
+ timeout: config.timeout ?? DEFAULT_TIMEOUT,
96
+ maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,
97
+ onRetry: config.onRetry,
98
+ };
99
+ this.http = new HttpClient({
100
+ baseUrl: this.config.baseUrl,
101
+ apiKey: this.config.apiKey,
102
+ userId: this.config.userId,
103
+ timeout: this.config.timeout,
104
+ maxRetries: this.config.maxRetries,
105
+ onRetry: this.config.onRetry,
106
+ });
107
+ // Initialize resources
108
+ this.users = new UsersResource(this.http, this.config.userId);
109
+ this.messages = new MessagesResource(this.http, this.config.userId);
110
+ this.conversations = new ConversationsResource(this.http, this.config.userId);
111
+ this.integrations = new IntegrationsResource(this.http, this.config.userId);
112
+ this.queryResource = new QueryResource(this.http, this.config.userId);
113
+ }
114
+ /**
115
+ * Query the user's unified context with AI.
116
+ *
117
+ * This is the primary method for asking questions about the user's data.
118
+ * It performs semantic search across all connected integrations and returns
119
+ * an AI-generated answer based on the relevant context.
120
+ *
121
+ * @param prompt - The natural language question to answer
122
+ * @param options - Query options including history, filters, etc.
123
+ * @returns AI-generated answer with source references
124
+ *
125
+ * @throws {AuthenticationError} If the API key is invalid or expired
126
+ * @throws {ValidationError} If the request parameters are invalid
127
+ * @throws {RateLimitError} If rate limits are exceeded
128
+ * @throws {NetworkError} If unable to reach the API
129
+ * @throws {ServerError} If the server encounters an error
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * // Simple query
134
+ * const response = await attrove.query('What did Sarah say about the Q4 budget?');
135
+ * console.log(response.answer);
136
+ *
137
+ * // Multi-turn conversation
138
+ * let history: ConversationMessage[] = [];
139
+ *
140
+ * const first = await attrove.query('What meetings do I have tomorrow?');
141
+ * history = first.history;
142
+ *
143
+ * const followUp = await attrove.query('Who is attending?', { history });
144
+ * console.log(followUp.answer);
145
+ * ```
146
+ */
147
+ async query(prompt, options) {
148
+ return this.queryResource.query(prompt, options);
149
+ }
150
+ /**
151
+ * Semantic search across the user's context.
152
+ *
153
+ * Returns raw matching messages grouped by conversation, without AI summarization.
154
+ * Use this when you need full control over how results are displayed.
155
+ *
156
+ * @param query - The search query (semantic, not keyword-based)
157
+ * @param options - Search options including filters, date range, etc.
158
+ * @returns Matching messages grouped by conversation
159
+ *
160
+ * @throws {AuthenticationError} If the API key is invalid or expired
161
+ * @throws {ValidationError} If the request parameters are invalid
162
+ * @throws {RateLimitError} If rate limits are exceeded
163
+ * @throws {NetworkError} If unable to reach the API
164
+ * @throws {ServerError} If the server encounters an error
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const results = await attrove.search('quarterly report', {
169
+ * afterDate: '2024-01-01T00:00:00Z',
170
+ * includeBodyText: true
171
+ * });
172
+ *
173
+ * for (const [convId, conv] of Object.entries(results.conversations)) {
174
+ * console.log(`Conversation: ${conv.conversation_name}`);
175
+ * for (const [threadId, messages] of Object.entries(conv.threads)) {
176
+ * console.log(` Thread ${threadId}: ${messages.length} messages`);
177
+ * }
178
+ * }
179
+ * ```
180
+ */
181
+ async search(query, options) {
182
+ return this.queryResource.search(query, options);
183
+ }
184
+ /**
185
+ * Stream a query response in real-time.
186
+ *
187
+ * Connects to the WebSocket endpoint and streams the AI-generated answer
188
+ * as it's being generated. Useful for displaying results progressively.
189
+ *
190
+ * @param prompt - The natural language question to answer
191
+ * @param options - Query and streaming options
192
+ * @returns Stream result with full answer and metadata
193
+ *
194
+ * @throws {AuthenticationError} If the API key is invalid or expired
195
+ * @throws {NetworkError} If WebSocket connection fails
196
+ * @throws {TimeoutError} If connection times out
197
+ * @throws {AttroveError} If the server returns an error
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * const result = await attrove.stream('What happened in the meeting?', {
202
+ * onChunk: (chunk) => process.stdout.write(chunk),
203
+ * onState: (state) => console.log('State:', state),
204
+ * });
205
+ *
206
+ * console.log('\\nFull answer:', result.answer);
207
+ * ```
208
+ */
209
+ async stream(prompt, options = {}) {
210
+ const { history = [], timezone, integrationIds, conversationIds, allowBotMessages, includeSources, ...streamOptions } = options;
211
+ // Add the user's prompt to history
212
+ const fullHistory = [
213
+ ...history,
214
+ { role: 'user', content: prompt },
215
+ ];
216
+ // Extract query options (separate from stream options)
217
+ const queryOptions = {
218
+ timezone,
219
+ integrationIds,
220
+ conversationIds,
221
+ allowBotMessages,
222
+ includeSources,
223
+ };
224
+ const streaming = new StreamingClient(this.config.baseUrl, this.config.apiKey);
225
+ try {
226
+ const messageId = generateMessageId();
227
+ return await streaming.stream(prompt, messageId, fullHistory, queryOptions, streamOptions);
228
+ }
229
+ finally {
230
+ streaming.close();
231
+ }
232
+ }
233
+ /**
234
+ * Get meeting preparation brief.
235
+ *
236
+ * Retrieves context about attendees, recent conversations, and relevant
237
+ * information to help prepare for an upcoming meeting.
238
+ *
239
+ * @experimental This method is not yet implemented and will throw an error.
240
+ *
241
+ * @param meetingId - Meeting ID (UUID format)
242
+ * @returns Meeting brief with attendee info and relevant context
243
+ *
244
+ * @throws {Error} Always throws - not yet implemented
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * // Not yet available
249
+ * const brief = await attrove.brief('meeting-uuid-here');
250
+ * console.log(brief.summary);
251
+ * console.log('Attendees:', brief.attendees);
252
+ * ```
253
+ */
254
+ async brief(meetingId) {
255
+ // TODO: Implement meeting brief endpoint
256
+ throw new Error('Meeting brief not yet implemented. This feature is coming soon.');
257
+ }
258
+ /**
259
+ * Get information about an entity (person, company, etc.).
260
+ *
261
+ * Retrieves profile information and interaction history for an entity
262
+ * identified from the user's communications.
263
+ *
264
+ * @experimental This method is not yet implemented and will throw an error.
265
+ *
266
+ * @param entityId - Entity ID (UUID format)
267
+ * @returns Entity profile with interaction history
268
+ *
269
+ * @throws {Error} Always throws - not yet implemented
270
+ *
271
+ * @example
272
+ * ```ts
273
+ * // Not yet available
274
+ * const entity = await attrove.entity('entity-uuid');
275
+ * console.log(`${entity.name}: ${entity.message_count} messages`);
276
+ * ```
277
+ */
278
+ async entity(entityId) {
279
+ // TODO: Implement entity endpoint
280
+ throw new Error('Entity lookup not yet implemented. This feature is coming soon.');
281
+ }
282
+ /**
283
+ * Get a conversation thread.
284
+ *
285
+ * Retrieves all messages in a specific conversation thread.
286
+ *
287
+ * @experimental This method is not yet implemented and will throw an error.
288
+ *
289
+ * @param conversationId - Conversation ID (UUID format)
290
+ * @returns Conversation thread with messages
291
+ *
292
+ * @throws {Error} Always throws - not yet implemented
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * // Not yet available
297
+ * const thread = await attrove.thread('conversation-uuid-here');
298
+ * for (const msg of thread.messages) {
299
+ * console.log(`${msg.sender_name}: ${msg.body_text}`);
300
+ * }
301
+ * ```
302
+ */
303
+ async thread(conversationId) {
304
+ // TODO: Implement thread endpoint
305
+ throw new Error('Thread retrieval not yet implemented. This feature is coming soon.');
306
+ }
307
+ }
308
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../packages/sdk/src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,eAAe,EAA+B,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,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,CAAC,CAAC;IACrF,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,MAAM,CAAC,cAAsB;QACjC,kCAAkC;QAClC,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;CACF"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * SDK Constants
3
+ *
4
+ * Centralized constants used across the SDK. Consolidating these ensures
5
+ * consistency and makes maintenance easier.
6
+ */
7
+ /**
8
+ * SDK version string.
9
+ *
10
+ * This version is updated by the release process. Keep it in sync with
11
+ * the version in package.json. For programmatic access, use `getVersion()`
12
+ * from './version'.
13
+ */
14
+ export const SDK_VERSION = '0.1.3';
15
+ /**
16
+ * Default API base URL for Attrove services.
17
+ */
18
+ export const DEFAULT_BASE_URL = 'https://api.attrove.com';
19
+ /**
20
+ * Default request timeout in milliseconds.
21
+ */
22
+ export const DEFAULT_TIMEOUT = 30000;
23
+ /**
24
+ * Default number of retry attempts for failed requests.
25
+ */
26
+ export const DEFAULT_MAX_RETRIES = 3;
27
+ /**
28
+ * Initial delay for retry backoff in milliseconds.
29
+ */
30
+ export const INITIAL_RETRY_DELAY = 1000;
31
+ /**
32
+ * HTTP status codes that trigger automatic retries.
33
+ */
34
+ export const RETRY_STATUS_CODES = [408, 429, 500, 502, 503, 504];
35
+ /**
36
+ * Set of retryable status codes for O(1) lookup.
37
+ */
38
+ export const RETRYABLE_STATUS_SET = new Set(RETRY_STATUS_CODES);
39
+ /**
40
+ * WebSocket close code descriptions for better error messages.
41
+ */
42
+ export const WS_CLOSE_CODES = {
43
+ 1000: 'Normal closure',
44
+ 1001: 'Server going away',
45
+ 1002: 'Protocol error',
46
+ 1003: 'Unsupported data type',
47
+ 1005: 'No status code received',
48
+ 1006: 'Connection lost abnormally (no close frame)',
49
+ 1007: 'Invalid frame payload data',
50
+ 1008: 'Policy violation',
51
+ 1009: 'Message too large',
52
+ 1010: 'Missing expected extension',
53
+ 1011: 'Internal server error',
54
+ 1012: 'Service restart',
55
+ 1013: 'Try again later',
56
+ 1014: 'Bad gateway',
57
+ 1015: 'TLS handshake failure',
58
+ };
59
+ /**
60
+ * Get a human-readable description for a WebSocket close code.
61
+ */
62
+ export function getWsCloseReason(code) {
63
+ return WS_CLOSE_CODES[code] || 'Unknown close reason';
64
+ }
65
+ //# sourceMappingURL=constants.js.map