@gpt-core/client 0.1.0-alpha.1 → 0.2.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 (6) hide show
  1. package/README.md +306 -23
  2. package/dist/index.d.mts +16102 -6910
  3. package/dist/index.d.ts +16102 -6910
  4. package/dist/index.js +2743 -1838
  5. package/dist/index.mjs +2612 -1885
  6. package/package.json +10 -3
package/README.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # @gpt-core/client
2
2
 
3
- The official TypeScript Client SDK for the GPT Core Platform.
3
+ The official TypeScript SDK for the GPT Core Platform - document extraction, AI agents, and workspace management.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@gpt-core/client.svg)](https://www.npmjs.com/package/@gpt-core/client)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue)](https://www.typescriptlang.org/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ ## Features
10
+
11
+ ✅ **Fully Typed** - Complete TypeScript support with auto-generated types from OpenAPI specs
12
+ ✅ **Runtime Validation** - Zod schemas for request validation
13
+ ✅ **Smart Error Handling** - Custom error classes with detailed context
14
+ ✅ **Automatic Retries** - Exponential backoff for transient failures
15
+ ✅ **Pagination Support** - Async iterators for easy iteration over large datasets
16
+ ✅ **Streaming Support** - Server-Sent Events (SSE) for real-time AI responses
17
+ ✅ **JSON:API Compliant** - Automatic envelope unwrapping
4
18
 
5
19
  ## Installation
6
20
 
@@ -8,6 +22,8 @@ The official TypeScript Client SDK for the GPT Core Platform.
8
22
  npm install @gpt-core/client
9
23
  # or
10
24
  yarn add @gpt-core/client
25
+ # or
26
+ pnpm add @gpt-core/client
11
27
  ```
12
28
 
13
29
  ## Quick Start
@@ -15,50 +31,317 @@ yarn add @gpt-core/client
15
31
  ```typescript
16
32
  import { GptClient } from '@gpt-core/client';
17
33
 
34
+ // Initialize client
18
35
  const client = new GptClient({
19
36
  baseUrl: 'https://api.gpt-core.com',
20
- apiKey: 'your-public-key', // Optional for some endpoints
21
- token: 'user-jwt-token', // Optional for authenticated endpoints
37
+ apiKey: 'your-api-key', // For machine-to-machine
38
+ token: 'user-jwt-token', // For user-authenticated requests
22
39
  });
23
40
 
24
- // Authenticate
25
- const { user, token } = await client.identity.login('user@example.com', 'password');
26
- console.log(`Welcome, ${user.attributes.full_name}`);
41
+ // Authenticate a user
42
+ const { user, token } = await client.identity.login(
43
+ 'user@example.com',
44
+ 'password'
45
+ );
46
+
47
+ console.log(`Welcome, ${user.attributes.full_name}!`);
27
48
 
28
- // Search AI
29
- const results = await client.ai.search('quarterly earnings');
49
+ // Use the token for subsequent requests
50
+ const authenticatedClient = new GptClient({
51
+ baseUrl: 'https://api.gpt-core.com',
52
+ token: token,
53
+ });
54
+
55
+ // List workspaces
56
+ const workspaces = await authenticatedClient.platform.workspaces.mine();
30
57
  ```
31
58
 
32
- ## Features
59
+ ## Configuration
60
+
61
+ ```typescript
62
+ const client = new GptClient({
63
+ // Required: API base URL
64
+ baseUrl: 'https://api.gpt-core.com',
65
+
66
+ // Authentication (provide one or both)
67
+ apiKey: 'sk_live_...', // Application API key
68
+ token: 'eyJhbGc...', // User JWT token
33
69
 
34
- - **Typed Inputs & Outputs**: Fully typed request/response bodies generated from OpenAPI specs.
35
- - **Auto-Unwrapping**: Automatically handles JSON:API envelopes (`data: { type: ..., attributes: ... }`) so you get clean objects.
36
- - **Modular**: Grouped by domain (`identity`, `platform`, `ai`, `extraction`, `billing`).
70
+ // Retry configuration (optional)
71
+ retry: {
72
+ maxRetries: 3, // Default: 3
73
+ minTimeout: 1000, // Default: 1000ms
74
+ maxTimeout: 30000, // Default: 30000ms
75
+ randomize: true, // Default: true (adds jitter)
76
+ },
37
77
 
38
- ## Domains
78
+ // Disable retries
79
+ retry: false,
80
+ });
81
+ ```
82
+
83
+ ## API Reference
39
84
 
40
85
  ### Identity
41
- Manage users, profiles, and API keys.
86
+
87
+ Manage users, authentication, and API keys.
88
+
42
89
  ```typescript
43
- await client.identity.me();
44
- await client.identity.apiKeys.create('My Key');
90
+ // Login
91
+ const { user, token } = await client.identity.login(email, password);
92
+
93
+ // Register
94
+ const user = await client.identity.register(email, password, passwordConfirmation);
95
+
96
+ // Get current user
97
+ const user = await client.identity.me();
98
+
99
+ // Get user profile
100
+ const profile = await client.identity.profile();
101
+
102
+ // API Keys
103
+ const keys = await client.identity.apiKeys.list();
104
+ const newKey = await client.identity.apiKeys.create('Production Key');
105
+ await client.identity.apiKeys.allocate('key-id', 1000, 'Monthly credits');
45
106
  ```
46
107
 
47
108
  ### Platform
109
+
48
110
  Manage applications, workspaces, and tenants.
111
+
49
112
  ```typescript
50
- await client.platform.applications.list();
51
- await client.platform.workspaces.create('New Workspace');
113
+ // Applications
114
+ const apps = await client.platform.applications.list();
115
+ const app = await client.platform.applications.create({
116
+ name: 'My App',
117
+ slug: 'my-app',
118
+ });
119
+ const app = await client.platform.applications.getBySlug('my-app');
120
+
121
+ // Workspaces
122
+ const workspaces = await client.platform.workspaces.list();
123
+ const myWorkspaces = await client.platform.workspaces.mine();
124
+ const workspace = await client.platform.workspaces.create('New Workspace', 'new-workspace');
125
+
126
+ // Invitations
127
+ await client.platform.invitations.invite(
128
+ 'colleague@example.com',
129
+ 'editor',
130
+ 'workspace',
131
+ 'workspace-id'
132
+ );
52
133
  ```
53
134
 
54
135
  ### AI
55
- Interact with Agents, Threads, and semantic search.
136
+
137
+ Interact with agents, threads, and semantic search.
138
+
139
+ ```typescript
140
+ // Agents
141
+ const agents = await client.ai.agents.list();
142
+ const agent = await client.ai.agents.create(
143
+ 'Support Agent',
144
+ 'You are a helpful customer support agent'
145
+ );
146
+
147
+ // Threads (Conversations)
148
+ const threads = await client.ai.threads.list();
149
+ const thread = await client.ai.threads.create('Bug Report Discussion');
150
+ const message = await client.ai.threads.sendMessage(thread.id, 'Hello AI!');
151
+
152
+ // Search
153
+ const results = await client.ai.search('quarterly earnings', 10);
154
+
155
+ // Embeddings
156
+ const embedding = await client.ai.embed('text to embed');
157
+ ```
158
+
159
+ ### Extraction
160
+
161
+ Upload and analyze documents.
162
+
163
+ ```typescript
164
+ // Documents
165
+ const documents = await client.extraction.documents.list();
166
+
167
+ // Upload (base64)
168
+ const doc = await client.extraction.documents.uploadBase64(
169
+ 'report.pdf',
170
+ base64Content
171
+ );
172
+
173
+ // Analyze
174
+ await client.extraction.documents.analyze(doc.id);
175
+
176
+ // Retrieve
177
+ const doc = await client.extraction.documents.get('doc-id');
178
+
179
+ // Delete
180
+ await client.extraction.documents.delete('doc-id');
181
+
182
+ // Results
183
+ const results = await client.extraction.results.list();
184
+ ```
185
+
186
+ ### Storage
187
+
188
+ Manage buckets and files.
189
+
190
+ ```typescript
191
+ // Buckets
192
+ const buckets = await client.storage.buckets.list();
193
+ const bucket = await client.storage.buckets.create('uploads', false);
194
+
195
+ // Presigned URLs
196
+ const uploadUrl = await client.storage.presigned.upload(
197
+ 'image.png',
198
+ 'image/png'
199
+ );
200
+ const downloadUrl = await client.storage.presigned.download('file-id');
201
+ ```
202
+
203
+ ### Billing
204
+
205
+ Access wallet and plan information.
206
+
207
+ ```typescript
208
+ // Wallet
209
+ const wallet = await client.billing.wallet.get();
210
+
211
+ // Plans
212
+ const plans = await client.billing.plans.list();
213
+ ```
214
+
215
+ ## Advanced Features
216
+
217
+ ### Error Handling
218
+
219
+ The SDK provides detailed error classes:
220
+
221
+ ```typescript
222
+ import {
223
+ AuthenticationError,
224
+ AuthorizationError,
225
+ NotFoundError,
226
+ ValidationError,
227
+ RateLimitError,
228
+ ServerError,
229
+ } from '@gpt-core/client';
230
+
231
+ try {
232
+ await client.identity.login('user@example.com', 'wrong-password');
233
+ } catch (error) {
234
+ if (error instanceof AuthenticationError) {
235
+ console.error('Invalid credentials:', error.message);
236
+ console.error('Request ID:', error.requestId);
237
+ } else if (error instanceof ValidationError) {
238
+ console.error('Validation errors:', error.errors);
239
+ } else if (error instanceof RateLimitError) {
240
+ console.error(`Rate limited. Retry after ${error.retryAfter}s`);
241
+ }
242
+ }
243
+ ```
244
+
245
+ [Read more about error handling](docs/ERROR_HANDLING.md)
246
+
247
+ ### Pagination
248
+
249
+ Easily iterate over large datasets:
250
+
251
+ ```typescript
252
+ import { paginateAll } from '@gpt-core/client';
253
+
254
+ // Using async iteration
255
+ for await (const workspace of client.platform.workspaces.listAll()) {
256
+ console.log(workspace.attributes.name);
257
+ }
258
+
259
+ // With limit
260
+ for await (const doc of client.extraction.documents.listAll({ limit: 100 })) {
261
+ console.log(doc.attributes.filename);
262
+ }
263
+ ```
264
+
265
+ [Read more about pagination](docs/PAGINATION.md)
266
+
267
+ ### Streaming
268
+
269
+ Stream AI responses in real-time:
270
+
271
+ ```typescript
272
+ import { streamMessage } from '@gpt-core/client';
273
+
274
+ // Make streaming request
275
+ const response = await fetch(streamingEndpoint, {
276
+ method: 'POST',
277
+ headers: { 'Accept': 'text/event-stream' },
278
+ body: JSON.stringify({ content: 'Hello AI' }),
279
+ });
280
+
281
+ // Stream the response
282
+ for await (const chunk of streamMessage(response)) {
283
+ if (chunk.type === 'content') {
284
+ process.stdout.write(chunk.content); // Real-time output
285
+ }
286
+ }
287
+ ```
288
+
289
+ [Read more about streaming](docs/STREAMING.md)
290
+
291
+ ### Retry Logic
292
+
293
+ Automatic retries with exponential backoff:
294
+
56
295
  ```typescript
57
- await client.ai.threads.sendMessage('thread-id', 'Hello AI');
296
+ // Retries are enabled by default
297
+ const client = new GptClient({
298
+ baseUrl: 'https://api.gpt-core.com',
299
+ token: 'token',
300
+ retry: {
301
+ maxRetries: 5, // Retry up to 5 times
302
+ minTimeout: 2000, // Start with 2s delay
303
+ },
304
+ });
305
+
306
+ // Disable retries for specific operations
307
+ const noRetryClient = new GptClient({
308
+ baseUrl: 'https://api.gpt-core.com',
309
+ token: 'token',
310
+ retry: false,
311
+ });
58
312
  ```
59
313
 
60
- ### Extraction & Storage
61
- Upload documents and manage files.
314
+ ## Guides
315
+
316
+ - [Authentication Guide](docs/AUTHENTICATION.md)
317
+ - [Error Handling Guide](docs/ERROR_HANDLING.md)
318
+ - [Pagination Guide](docs/PAGINATION.md)
319
+ - [Streaming Guide](docs/STREAMING.md)
320
+
321
+ ## TypeScript Support
322
+
323
+ The SDK is written in TypeScript and provides full type safety:
324
+
62
325
  ```typescript
63
- await client.extraction.documents.uploadBase64('file.pdf', 'base64string...');
326
+ import type { user, workspace, document } from '@gpt-core/client';
327
+
328
+ const user: user = await client.identity.me();
329
+ // TypeScript knows: user.attributes.email, user.id, etc.
330
+
331
+ const workspace: workspace = await client.platform.workspaces.create('Test');
332
+ // TypeScript enforces correct parameters
64
333
  ```
334
+
335
+ ## Contributing
336
+
337
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md).
338
+
339
+ ## License
340
+
341
+ MIT © GPT Integrators
342
+
343
+ ## Support
344
+
345
+ - 📧 Email: support@gpt-core.com
346
+ - 📚 Documentation: https://docs.gpt-core.com
347
+ - 🐛 Issues: https://github.com/GPT-Integrators/gpt-core-sdks/issues