@gpt-core/admin 0.10.13 → 0.10.21
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 +56 -49
- package/dist/index.d.mts +165 -11
- package/dist/index.d.ts +165 -11
- package/dist/index.js +69 -9
- package/dist/index.mjs +69 -9
- package/llms.txt +1 -0
- package/package.json +10 -10
- package/dist/index.cjs +0 -1606
package/README.md
CHANGED
|
@@ -32,8 +32,11 @@ AI_CONTEXT_END -->
|
|
|
32
32
|
> **TL;DR for Claude, Cursor, Copilot, and other AI assistants:**
|
|
33
33
|
>
|
|
34
34
|
> ```typescript
|
|
35
|
-
> import { GptAdmin } from
|
|
36
|
-
> const admin = new GptAdmin({
|
|
35
|
+
> import { GptAdmin } from "@gpt-core/admin";
|
|
36
|
+
> const admin = new GptAdmin({
|
|
37
|
+
> baseUrl: "https://api.example.com",
|
|
38
|
+
> token: "admin-jwt",
|
|
39
|
+
> });
|
|
37
40
|
> ```
|
|
38
41
|
>
|
|
39
42
|
> **Common operations:**
|
|
@@ -75,12 +78,12 @@ pnpm add @gpt-core/admin
|
|
|
75
78
|
## Quick Start
|
|
76
79
|
|
|
77
80
|
```typescript
|
|
78
|
-
import { GptAdmin } from
|
|
81
|
+
import { GptAdmin } from "@gpt-core/admin";
|
|
79
82
|
|
|
80
83
|
// Initialize admin client
|
|
81
84
|
const admin = new GptAdmin({
|
|
82
|
-
baseUrl:
|
|
83
|
-
token: process.env.ADMIN_JWT_TOKEN,
|
|
85
|
+
baseUrl: "https://api.gpt-core.com",
|
|
86
|
+
token: process.env.ADMIN_JWT_TOKEN, // Admin JWT token
|
|
84
87
|
applicationId: process.env.APPLICATION_ID, // Your application ID
|
|
85
88
|
});
|
|
86
89
|
|
|
@@ -91,7 +94,9 @@ console.log(`Total files: ${stats.file_count}`);
|
|
|
91
94
|
|
|
92
95
|
// List webhook configurations
|
|
93
96
|
const webhooks = await admin.webhooks.configs.list();
|
|
94
|
-
console.log(
|
|
97
|
+
console.log(
|
|
98
|
+
`Active webhooks: ${webhooks.filter((w) => w.attributes.enabled).length}`,
|
|
99
|
+
);
|
|
95
100
|
```
|
|
96
101
|
|
|
97
102
|
## Configuration
|
|
@@ -99,13 +104,13 @@ console.log(`Active webhooks: ${webhooks.filter(w => w.attributes.enabled).lengt
|
|
|
99
104
|
```typescript
|
|
100
105
|
const admin = new GptAdmin({
|
|
101
106
|
// Required: API base URL
|
|
102
|
-
baseUrl:
|
|
107
|
+
baseUrl: "https://api.gpt-core.com",
|
|
103
108
|
|
|
104
109
|
// Required: Admin JWT token
|
|
105
|
-
token:
|
|
110
|
+
token: "admin-jwt-token",
|
|
106
111
|
|
|
107
112
|
// Required: Application ID
|
|
108
|
-
applicationId:
|
|
113
|
+
applicationId: "your-app-id",
|
|
109
114
|
});
|
|
110
115
|
```
|
|
111
116
|
|
|
@@ -120,7 +125,7 @@ APPLICATION_ID=your-application-id
|
|
|
120
125
|
|
|
121
126
|
```typescript
|
|
122
127
|
// lib/admin-client.ts
|
|
123
|
-
import { GptAdmin } from
|
|
128
|
+
import { GptAdmin } from "@gpt-core/admin";
|
|
124
129
|
|
|
125
130
|
export const admin = new GptAdmin({
|
|
126
131
|
baseUrl: process.env.ADMIN_API_URL!,
|
|
@@ -149,10 +154,10 @@ Pin a specific API version to protect your integration from breaking changes:
|
|
|
149
154
|
|
|
150
155
|
```typescript
|
|
151
156
|
const admin = new GptAdmin({
|
|
152
|
-
baseUrl:
|
|
157
|
+
baseUrl: "https://api.gpt-core.com",
|
|
153
158
|
token: process.env.ADMIN_JWT_TOKEN,
|
|
154
159
|
applicationId: process.env.APPLICATION_ID,
|
|
155
|
-
apiVersion:
|
|
160
|
+
apiVersion: "2025-12-03", // Pin to this version
|
|
156
161
|
});
|
|
157
162
|
```
|
|
158
163
|
|
|
@@ -195,35 +200,35 @@ const configs = await admin.webhooks.configs.list();
|
|
|
195
200
|
|
|
196
201
|
```typescript
|
|
197
202
|
const webhook = await admin.webhooks.configs.create(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
[
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
true
|
|
203
|
+
"My Webhook", // name
|
|
204
|
+
"https://your-server.com/webhook", // url
|
|
205
|
+
["document.analyzed", "thread.message.created"], // events
|
|
206
|
+
"app-123", // application_id
|
|
207
|
+
"your-webhook-secret", // secret (optional)
|
|
208
|
+
true, // enabled
|
|
204
209
|
);
|
|
205
210
|
```
|
|
206
211
|
|
|
207
212
|
#### Update Webhook Config
|
|
208
213
|
|
|
209
214
|
```typescript
|
|
210
|
-
const config = await admin.webhooks.configs.update(
|
|
215
|
+
const config = await admin.webhooks.configs.update("webhook-id", {
|
|
211
216
|
enabled: false,
|
|
212
|
-
events: [
|
|
217
|
+
events: ["document.analyzed"],
|
|
213
218
|
});
|
|
214
219
|
```
|
|
215
220
|
|
|
216
221
|
#### Delete Webhook Config
|
|
217
222
|
|
|
218
223
|
```typescript
|
|
219
|
-
await admin.webhooks.configs.delete(
|
|
224
|
+
await admin.webhooks.configs.delete("webhook-id");
|
|
220
225
|
```
|
|
221
226
|
|
|
222
227
|
#### Test Webhook Config
|
|
223
228
|
|
|
224
229
|
```typescript
|
|
225
|
-
const result = await admin.webhooks.configs.test(
|
|
226
|
-
console.log(
|
|
230
|
+
const result = await admin.webhooks.configs.test("webhook-id");
|
|
231
|
+
console.log("Test delivery ID:", result.delivery_id);
|
|
227
232
|
```
|
|
228
233
|
|
|
229
234
|
#### Webhook Deliveries
|
|
@@ -233,10 +238,10 @@ console.log('Test delivery ID:', result.delivery_id);
|
|
|
233
238
|
const deliveries = await admin.webhooks.deliveries.list();
|
|
234
239
|
|
|
235
240
|
// Get delivery details
|
|
236
|
-
const delivery = await admin.webhooks.deliveries.get(
|
|
241
|
+
const delivery = await admin.webhooks.deliveries.get("delivery-id");
|
|
237
242
|
|
|
238
243
|
// Retry failed delivery
|
|
239
|
-
await admin.webhooks.deliveries.retry(
|
|
244
|
+
await admin.webhooks.deliveries.retry("delivery-id");
|
|
240
245
|
```
|
|
241
246
|
|
|
242
247
|
### Storage Administration
|
|
@@ -247,19 +252,19 @@ const stats = await admin.storage.stats();
|
|
|
247
252
|
console.log(stats.total_size, stats.file_count);
|
|
248
253
|
|
|
249
254
|
// Get stats for specific workspace
|
|
250
|
-
const workspaceStats = await admin.storage.stats(
|
|
255
|
+
const workspaceStats = await admin.storage.stats("workspace-id");
|
|
251
256
|
|
|
252
257
|
// List all buckets
|
|
253
258
|
const buckets = await admin.storage.buckets.list();
|
|
254
259
|
|
|
255
260
|
// Get bucket details
|
|
256
|
-
const bucket = await admin.storage.buckets.get(
|
|
261
|
+
const bucket = await admin.storage.buckets.get("bucket-id");
|
|
257
262
|
|
|
258
263
|
// Get bucket stats
|
|
259
|
-
const bucketStats = await admin.storage.buckets.stats(
|
|
264
|
+
const bucketStats = await admin.storage.buckets.stats("bucket-id");
|
|
260
265
|
|
|
261
266
|
// List bucket objects
|
|
262
|
-
const objects = await admin.storage.buckets.objects(
|
|
267
|
+
const objects = await admin.storage.buckets.objects("bucket-id");
|
|
263
268
|
```
|
|
264
269
|
|
|
265
270
|
### Account Management
|
|
@@ -269,13 +274,13 @@ const objects = await admin.storage.buckets.objects('bucket-id');
|
|
|
269
274
|
const accounts = await admin.accounts.list();
|
|
270
275
|
|
|
271
276
|
// Get account details
|
|
272
|
-
const account = await admin.accounts.get(
|
|
277
|
+
const account = await admin.accounts.get("account-id");
|
|
273
278
|
|
|
274
279
|
// Credit an account
|
|
275
|
-
await admin.accounts.credit(
|
|
280
|
+
await admin.accounts.credit("account-id", 1000, "Bonus credits");
|
|
276
281
|
|
|
277
282
|
// Debit an account
|
|
278
|
-
await admin.accounts.debit(
|
|
283
|
+
await admin.accounts.debit("account-id", 500, "Usage charge");
|
|
279
284
|
```
|
|
280
285
|
|
|
281
286
|
### Document Administration
|
|
@@ -285,13 +290,13 @@ await admin.accounts.debit('account-id', 500, 'Usage charge');
|
|
|
285
290
|
const documents = await admin.documents.list();
|
|
286
291
|
|
|
287
292
|
// Get document details
|
|
288
|
-
const document = await admin.documents.get(
|
|
293
|
+
const document = await admin.documents.get("doc-id");
|
|
289
294
|
|
|
290
295
|
// Bulk delete documents
|
|
291
|
-
await admin.documents.bulkDelete([
|
|
296
|
+
await admin.documents.bulkDelete(["doc-id-1", "doc-id-2"]);
|
|
292
297
|
|
|
293
298
|
// Bulk reprocess documents
|
|
294
|
-
await admin.documents.bulkReprocess([
|
|
299
|
+
await admin.documents.bulkReprocess(["doc-id-1", "doc-id-2"]);
|
|
295
300
|
```
|
|
296
301
|
|
|
297
302
|
### API Key Management
|
|
@@ -301,21 +306,22 @@ await admin.documents.bulkReprocess(['doc-id-1', 'doc-id-2']);
|
|
|
301
306
|
const keys = await admin.apiKeys.list();
|
|
302
307
|
|
|
303
308
|
// Get API key details
|
|
304
|
-
const key = await admin.apiKeys.get(
|
|
309
|
+
const key = await admin.apiKeys.get("key-id");
|
|
305
310
|
|
|
306
311
|
// Allocate credits to API key
|
|
307
|
-
await admin.apiKeys.allocate(
|
|
312
|
+
await admin.apiKeys.allocate("key-id", 5000, "Monthly allocation");
|
|
308
313
|
|
|
309
314
|
// Revoke API key
|
|
310
|
-
await admin.apiKeys.revoke(
|
|
315
|
+
await admin.apiKeys.revoke("key-id");
|
|
311
316
|
|
|
312
317
|
// Rotate API key
|
|
313
|
-
await admin.apiKeys.rotate(
|
|
318
|
+
await admin.apiKeys.rotate("key-id");
|
|
314
319
|
```
|
|
315
320
|
|
|
316
321
|
## Webhook Events
|
|
317
322
|
|
|
318
323
|
Available webhook events:
|
|
324
|
+
|
|
319
325
|
- `document.uploaded`
|
|
320
326
|
- `document.analyzed`
|
|
321
327
|
- `document.deleted`
|
|
@@ -328,13 +334,14 @@ Available webhook events:
|
|
|
328
334
|
## Bulk Operations
|
|
329
335
|
|
|
330
336
|
All bulk operations support:
|
|
337
|
+
|
|
331
338
|
- Minimum: 1 item
|
|
332
339
|
- Maximum: 100 items per request
|
|
333
340
|
- Validation via Zod schemas
|
|
334
341
|
|
|
335
342
|
```typescript
|
|
336
343
|
// Bulk delete up to 100 documents
|
|
337
|
-
const documentIds = [
|
|
344
|
+
const documentIds = ["doc-1", "doc-2", "doc-3"];
|
|
338
345
|
await admin.documents.bulkDelete(documentIds);
|
|
339
346
|
|
|
340
347
|
// Bulk reprocess documents
|
|
@@ -355,12 +362,12 @@ await admin.documents.bulkReprocess(documentIds);
|
|
|
355
362
|
|
|
356
363
|
```typescript
|
|
357
364
|
try {
|
|
358
|
-
await admin.accounts.credit(
|
|
365
|
+
await admin.accounts.credit("account-id", 1000);
|
|
359
366
|
} catch (error) {
|
|
360
367
|
if (error instanceof ZodError) {
|
|
361
|
-
console.error(
|
|
368
|
+
console.error("Validation error:", error.errors);
|
|
362
369
|
} else {
|
|
363
|
-
console.error(
|
|
370
|
+
console.error("API error:", error);
|
|
364
371
|
}
|
|
365
372
|
}
|
|
366
373
|
```
|
|
@@ -369,10 +376,10 @@ try {
|
|
|
369
376
|
|
|
370
377
|
```typescript
|
|
371
378
|
const admin = new GptAdmin({
|
|
372
|
-
baseUrl:
|
|
373
|
-
token:
|
|
374
|
-
applicationId:
|
|
375
|
-
apiKey:
|
|
379
|
+
baseUrl: "https://api.gpt-core.com", // API base URL
|
|
380
|
+
token: "admin-jwt-token", // Admin JWT token
|
|
381
|
+
applicationId: "app-id", // Application ID
|
|
382
|
+
apiKey: "api-key", // Optional: API key
|
|
376
383
|
});
|
|
377
384
|
```
|
|
378
385
|
|
|
@@ -387,8 +394,8 @@ import type {
|
|
|
387
394
|
Account,
|
|
388
395
|
Document,
|
|
389
396
|
ApiKey,
|
|
390
|
-
Bucket
|
|
391
|
-
} from
|
|
397
|
+
Bucket,
|
|
398
|
+
} from "@gpt-core/admin";
|
|
392
399
|
```
|
|
393
400
|
|
|
394
401
|
## Testing
|