@gibs-dev/sdk 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.
- package/LICENSE +21 -0
- package/README.md +206 -0
- package/dist/cjs/client.d.ts +151 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +328 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/errors.d.ts +66 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +99 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.d.ts +21 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types.d.ts +163 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/client.d.ts +151 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +324 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors.d.ts +66 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +90 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +21 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.d.ts +163 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gibbr AB
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# @gibs/sdk
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript SDK for the [Gibs](https://gibs.dev) multi-regulation compliance API.
|
|
4
|
+
|
|
5
|
+
Gibs provides instant, source-cited compliance answers for EU regulations including the AI Act and GDPR. Every claim is traced to a specific article in the legal corpus.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @gibs/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { GibsClient } from '@gibs/sdk';
|
|
17
|
+
|
|
18
|
+
const client = new GibsClient({ apiKey: 'gbs_live_xxx' });
|
|
19
|
+
|
|
20
|
+
// Classify an AI system's risk level
|
|
21
|
+
const classification = await client.classify({
|
|
22
|
+
description: 'Facial recognition system for airport security',
|
|
23
|
+
sector: 'security',
|
|
24
|
+
data_types: ['biometric'],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log(classification.risk_level); // "high"
|
|
28
|
+
console.log(classification.obligations); // [{id: "risk_mgmt", ...}, ...]
|
|
29
|
+
console.log(classification.sources); // [{article_id: "ai_act_art6", ...}]
|
|
30
|
+
|
|
31
|
+
// Ask a compliance question
|
|
32
|
+
const answer = await client.check({
|
|
33
|
+
question: 'What are the transparency requirements for chatbots under the AI Act?',
|
|
34
|
+
regulation: 'ai_act',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
console.log(answer.answer); // Detailed answer with article citations
|
|
38
|
+
console.log(answer.confidence); // "high" | "medium" | "low"
|
|
39
|
+
console.log(answer.sources); // Source citations
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Requirements
|
|
43
|
+
|
|
44
|
+
- Node.js 18+ (uses native `fetch`)
|
|
45
|
+
- Also works in modern browsers, Deno, and Bun
|
|
46
|
+
|
|
47
|
+
## API Reference
|
|
48
|
+
|
|
49
|
+
### `new GibsClient(options)`
|
|
50
|
+
|
|
51
|
+
Create a new client instance.
|
|
52
|
+
|
|
53
|
+
| Option | Type | Default | Description |
|
|
54
|
+
|--------|------|---------|-------------|
|
|
55
|
+
| `apiKey` | `string` | *required* | Your API key (`gbs_live_xxx` or `gbs_test_xxx`) |
|
|
56
|
+
| `baseUrl` | `string` | `https://api.gibs.dev` | API base URL |
|
|
57
|
+
| `timeout` | `number` | `120000` | Request timeout in milliseconds |
|
|
58
|
+
| `maxRetries` | `number` | `3` | Max retries on transient failures |
|
|
59
|
+
|
|
60
|
+
### `client.classify(request)`
|
|
61
|
+
|
|
62
|
+
Classify an AI system under EU AI Act risk levels.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const result = await client.classify({
|
|
66
|
+
description: 'CV screening tool that ranks job applicants',
|
|
67
|
+
sector: 'employment',
|
|
68
|
+
data_types: ['biometric'],
|
|
69
|
+
decision_scope: 'hiring decisions',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// result.risk_level: "prohibited" | "high" | "limited" | "minimal"
|
|
73
|
+
// result.confidence: 0.0 - 1.0
|
|
74
|
+
// result.reasoning: string
|
|
75
|
+
// result.obligations: Obligation[]
|
|
76
|
+
// result.sources: SourceCitation[]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `client.check(request)`
|
|
80
|
+
|
|
81
|
+
Ask a compliance question and get a grounded answer with source citations.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const answer = await client.check({
|
|
85
|
+
question: 'What are GDPR data subject rights?',
|
|
86
|
+
regulation: 'gdpr',
|
|
87
|
+
system_context: {
|
|
88
|
+
industry: 'healthcare',
|
|
89
|
+
data_types: 'patient records',
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// answer.answer: string
|
|
94
|
+
// answer.confidence: "high" | "medium" | "low"
|
|
95
|
+
// answer.sources: SourceCitation[]
|
|
96
|
+
// answer.should_abstain: boolean
|
|
97
|
+
// answer.abstention_reason: string | null
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### `client.health()`
|
|
101
|
+
|
|
102
|
+
Check API health and component status. Does not require authentication.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const health = await client.health();
|
|
106
|
+
// health.status: "healthy" | "degraded" | "unhealthy"
|
|
107
|
+
// health.components: { api: "healthy", qdrant: "healthy", ... }
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### `client.listKeys()`
|
|
111
|
+
|
|
112
|
+
List all active API keys for your organization.
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
const keys = await client.listKeys();
|
|
116
|
+
// keys: KeyInfo[]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `client.createKey(request?)`
|
|
120
|
+
|
|
121
|
+
Create a new API key. The full key value is shown only once in the response.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const key = await client.createKey({ name: 'Production' });
|
|
125
|
+
console.log(key.api_key); // Store this securely -- cannot be retrieved again
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### `client.deleteKey(keyId)`
|
|
129
|
+
|
|
130
|
+
Revoke an API key.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
await client.deleteKey(42);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Error Handling
|
|
137
|
+
|
|
138
|
+
The SDK provides a hierarchy of error classes for precise error handling:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import {
|
|
142
|
+
GibsError, // Base class for all SDK errors
|
|
143
|
+
GibsAPIError, // HTTP 4xx/5xx responses
|
|
144
|
+
GibsAuthError, // HTTP 401 (invalid/missing API key)
|
|
145
|
+
GibsRateLimitError, // HTTP 429 (rate limit exceeded)
|
|
146
|
+
GibsTimeoutError, // Request timed out
|
|
147
|
+
GibsConnectionError // Network connectivity issues
|
|
148
|
+
} from '@gibs/sdk';
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const result = await client.classify({
|
|
152
|
+
description: 'My AI system',
|
|
153
|
+
});
|
|
154
|
+
} catch (err) {
|
|
155
|
+
if (err instanceof GibsAuthError) {
|
|
156
|
+
// Invalid or missing API key
|
|
157
|
+
console.error('Authentication failed:', err.message);
|
|
158
|
+
} else if (err instanceof GibsRateLimitError) {
|
|
159
|
+
// Rate limit exceeded -- check retryAfter
|
|
160
|
+
console.error(`Rate limited. Retry after ${err.retryAfter} seconds`);
|
|
161
|
+
} else if (err instanceof GibsTimeoutError) {
|
|
162
|
+
// Request took too long
|
|
163
|
+
console.error('Request timed out');
|
|
164
|
+
} else if (err instanceof GibsConnectionError) {
|
|
165
|
+
// Network issue
|
|
166
|
+
console.error('Could not reach API:', err.message);
|
|
167
|
+
} else if (err instanceof GibsAPIError) {
|
|
168
|
+
// Other API error (404, 409, 500, etc.)
|
|
169
|
+
console.error(`API error ${err.status}: ${err.message}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Retries
|
|
175
|
+
|
|
176
|
+
The SDK automatically retries failed requests with exponential backoff for transient errors:
|
|
177
|
+
|
|
178
|
+
- **Retried:** 408, 429, 500, 502, 503, 504, network errors, timeouts
|
|
179
|
+
- **Not retried:** 401, 403, 404, 409, 422 (client errors)
|
|
180
|
+
|
|
181
|
+
For 429 responses, the SDK respects the `Retry-After` header.
|
|
182
|
+
|
|
183
|
+
Default: 3 retries with exponential backoff starting at 500ms.
|
|
184
|
+
|
|
185
|
+
## TypeScript
|
|
186
|
+
|
|
187
|
+
The SDK is written in TypeScript with strict mode and exports all types:
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import type {
|
|
191
|
+
ClassifyRequest,
|
|
192
|
+
ClassifyResponse,
|
|
193
|
+
CheckRequest,
|
|
194
|
+
CheckResponse,
|
|
195
|
+
HealthResponse,
|
|
196
|
+
SourceCitation,
|
|
197
|
+
Obligation,
|
|
198
|
+
RiskLevel,
|
|
199
|
+
ConfidenceLevel,
|
|
200
|
+
KeyInfo,
|
|
201
|
+
} from '@gibs/sdk';
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gibs API client.
|
|
3
|
+
*
|
|
4
|
+
* Provides typed methods for all Gibs compliance API endpoints.
|
|
5
|
+
* Uses native `fetch` -- works in Node.js 18+, browsers, Deno, and Bun.
|
|
6
|
+
*
|
|
7
|
+
* @module client
|
|
8
|
+
*/
|
|
9
|
+
import type { CheckRequest, CheckResponse, ClassifyRequest, ClassifyResponse, CreateKeyRequest, GibsClientOptions, HealthResponse, KeyCreatedResponse, KeyDeletedResponse, KeyInfo } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Official client for the Gibs multi-regulation compliance API.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { GibsClient } from '@gibs/sdk';
|
|
16
|
+
*
|
|
17
|
+
* const client = new GibsClient({ apiKey: 'gbs_live_xxx' });
|
|
18
|
+
*
|
|
19
|
+
* const result = await client.classify({
|
|
20
|
+
* description: 'Facial recognition system for airport security',
|
|
21
|
+
* });
|
|
22
|
+
* console.log(result.risk_level);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class GibsClient {
|
|
26
|
+
private readonly apiKey;
|
|
27
|
+
private readonly baseUrl;
|
|
28
|
+
private readonly timeout;
|
|
29
|
+
private readonly maxRetries;
|
|
30
|
+
constructor(options: GibsClientOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Classify an AI system under EU AI Act risk levels.
|
|
33
|
+
*
|
|
34
|
+
* Returns the risk classification, relevant obligations,
|
|
35
|
+
* and source citations from the legal corpus.
|
|
36
|
+
*
|
|
37
|
+
* @param request - Description of the AI system to classify.
|
|
38
|
+
* @returns Classification result with risk level and obligations.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const result = await client.classify({
|
|
43
|
+
* description: 'CV screening tool that ranks job applicants',
|
|
44
|
+
* sector: 'employment',
|
|
45
|
+
* data_types: ['biometric'],
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* console.log(result.risk_level); // "high"
|
|
49
|
+
* console.log(result.obligations); // [{id: "risk_mgmt", ...}, ...]
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
classify(request: ClassifyRequest): Promise<ClassifyResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Ask a compliance question and get a grounded answer with citations.
|
|
55
|
+
*
|
|
56
|
+
* Every claim in the answer is traceable to a specific article
|
|
57
|
+
* in the legal corpus. If the corpus doesn't cover the question,
|
|
58
|
+
* the response indicates abstention with a reason.
|
|
59
|
+
*
|
|
60
|
+
* @param request - The compliance question and optional context.
|
|
61
|
+
* @returns Answer with source citations and confidence level.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const answer = await client.check({
|
|
66
|
+
* question: 'What are the transparency requirements for chatbots under the AI Act?',
|
|
67
|
+
* regulation: 'ai_act',
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* console.log(answer.answer);
|
|
71
|
+
* console.log(answer.sources);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
check(request: CheckRequest): Promise<CheckResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Check API health and component status.
|
|
77
|
+
*
|
|
78
|
+
* Does not require authentication.
|
|
79
|
+
*
|
|
80
|
+
* @returns Health status with component details.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const health = await client.health();
|
|
85
|
+
* console.log(health.status); // "healthy"
|
|
86
|
+
* console.log(health.components); // {api: "healthy", qdrant: "healthy", ...}
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
health(): Promise<HealthResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* List all active API keys for your organization.
|
|
92
|
+
*
|
|
93
|
+
* Returns metadata only -- never includes the full key value.
|
|
94
|
+
*
|
|
95
|
+
* @returns Array of key metadata.
|
|
96
|
+
*/
|
|
97
|
+
listKeys(): Promise<KeyInfo[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Create a new API key for your organization.
|
|
100
|
+
*
|
|
101
|
+
* The full key value is returned exactly once in the response.
|
|
102
|
+
* Store it securely -- it cannot be retrieved again.
|
|
103
|
+
*
|
|
104
|
+
* Maximum 5 active keys per organization.
|
|
105
|
+
*
|
|
106
|
+
* @param request - Optional name for the key.
|
|
107
|
+
* @returns The created key including the full key value (shown once).
|
|
108
|
+
*/
|
|
109
|
+
createKey(request?: CreateKeyRequest): Promise<KeyCreatedResponse>;
|
|
110
|
+
/**
|
|
111
|
+
* Revoke an API key.
|
|
112
|
+
*
|
|
113
|
+
* The key must belong to your organization. You cannot revoke
|
|
114
|
+
* the key that is currently being used for authentication.
|
|
115
|
+
*
|
|
116
|
+
* @param keyId - Database ID of the key to revoke.
|
|
117
|
+
* @returns Confirmation with status "revoked".
|
|
118
|
+
*/
|
|
119
|
+
deleteKey(keyId: number): Promise<KeyDeletedResponse>;
|
|
120
|
+
/**
|
|
121
|
+
* Execute an HTTP request with retries, timeout, and error handling.
|
|
122
|
+
*/
|
|
123
|
+
private _request;
|
|
124
|
+
/**
|
|
125
|
+
* Fetch with an AbortController-based timeout.
|
|
126
|
+
*/
|
|
127
|
+
private _fetchWithTimeout;
|
|
128
|
+
/**
|
|
129
|
+
* Build the correct error class for a given HTTP status code.
|
|
130
|
+
*/
|
|
131
|
+
private _buildError;
|
|
132
|
+
/**
|
|
133
|
+
* Calculate retry delay with exponential backoff and jitter.
|
|
134
|
+
*
|
|
135
|
+
* For rate limit errors, respects the Retry-After header.
|
|
136
|
+
*/
|
|
137
|
+
private _retryDelay;
|
|
138
|
+
/**
|
|
139
|
+
* Extract response headers into a plain object.
|
|
140
|
+
*/
|
|
141
|
+
private _extractHeaders;
|
|
142
|
+
/**
|
|
143
|
+
* Check if an error is a network-level error (no HTTP response received).
|
|
144
|
+
*/
|
|
145
|
+
private _isNetworkError;
|
|
146
|
+
/**
|
|
147
|
+
* Sleep for a given number of milliseconds.
|
|
148
|
+
*/
|
|
149
|
+
private _sleep;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,OAAO,EACR,MAAM,YAAY,CAAC;AAgBpB;;;;;;;;;;;;;;GAcG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,OAAO,EAAE,iBAAiB;IAiBtC;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAInE;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAI1D;;;;;;;;;;;;;OAaG;IACG,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC;IAIvC;;;;;;OAMG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAIpC;;;;;;;;;;OAUG;IACG,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIxE;;;;;;;;OAQG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAQ3D;;OAEG;YACW,QAAQ;IA4FtB;;OAEG;YACW,iBAAiB;IA2B/B;;OAEG;IACH,OAAO,CAAC,WAAW;IAenB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAenB;;OAEG;IACH,OAAO,CAAC,eAAe;IAQvB;;OAEG;IACH,OAAO,CAAC,eAAe;IAgBvB;;OAEG;IACH,OAAO,CAAC,MAAM;CAGf"}
|