@aiassesstech/sdk 0.7.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 +29 -0
- package/README.md +350 -0
- package/dist/__tests__/__mocks__/node-fetch.d.ts +6 -0
- package/dist/__tests__/__mocks__/node-fetch.js +7 -0
- package/dist/__tests__/setup.d.ts +3 -0
- package/dist/__tests__/setup.js +13 -0
- package/dist/api.d.ts +55 -0
- package/dist/api.js +78 -0
- package/dist/cli.d.ts +28 -0
- package/dist/cli.js +182 -0
- package/dist/client.d.ts +146 -0
- package/dist/client.js +393 -0
- package/dist/environment.d.ts +18 -0
- package/dist/environment.js +137 -0
- package/dist/errors.d.ts +87 -0
- package/dist/errors.js +140 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +39 -0
- package/dist/types.d.ts +317 -0
- package/dist/types.js +9 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AI Assess Tech
|
|
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.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# AI Assess Tech SDK
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for assessing AI systems for ethical alignment. Test your AI across 4 dimensions: **Lying**, **Cheating**, **Stealing**, and **Harm**.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@aiassesstech/sdk)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🔒 **Privacy-First**: Your AI's API keys, system prompts, and configuration never leave your environment
|
|
11
|
+
- 🎯 **Server-Controlled**: Test configuration, questions, and thresholds managed via Health Check Key
|
|
12
|
+
- 🔄 **CI/CD Ready**: Auto-detects GitHub Actions, GitLab CI, CircleCI, and more
|
|
13
|
+
- 📊 **Full Traceability**: Each assessment generates IDs for audit trails
|
|
14
|
+
- ⚡ **Simple Integration**: One-line assessment with any AI provider
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @aiassesstech/sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { AIAssessClient } from '@aiassesstech/sdk';
|
|
26
|
+
|
|
27
|
+
// 1. Create client with your Health Check Key
|
|
28
|
+
const client = new AIAssessClient({
|
|
29
|
+
healthCheckKey: process.env.AIASSESS_KEY!
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 2. Run assessment - configuration comes from server
|
|
33
|
+
const result = await client.assess(async (question) => {
|
|
34
|
+
// Your AI callback - send question to your AI and return response
|
|
35
|
+
return await myAI.chat(question);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 3. Check result
|
|
39
|
+
console.log('Passed:', result.overallPassed);
|
|
40
|
+
console.log('Scores:', result.scores);
|
|
41
|
+
console.log('Classification:', result.classification);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## How It Works
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
48
|
+
│ Your Environment │
|
|
49
|
+
├─────────────────────────────────────────────────────────────┤
|
|
50
|
+
│ │
|
|
51
|
+
│ 1. SDK fetches config from AI Assess Tech server │
|
|
52
|
+
│ (questions, thresholds, test mode) │
|
|
53
|
+
│ │
|
|
54
|
+
│ 2. SDK sends questions to YOUR AI via your callback │
|
|
55
|
+
│ → Your API keys stay private │
|
|
56
|
+
│ → Your system prompts stay private │
|
|
57
|
+
│ │
|
|
58
|
+
│ 3. SDK submits responses to server for scoring │
|
|
59
|
+
│ │
|
|
60
|
+
│ 4. You receive scores, pass/fail, and classification │
|
|
61
|
+
│ │
|
|
62
|
+
└─────────────────────────────────────────────────────────────┘
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Usage Examples
|
|
66
|
+
|
|
67
|
+
### Basic Assessment
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const result = await client.assess(async (question) => {
|
|
71
|
+
return await myAI.chat(question);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
console.log(`Classification: ${result.classification}`);
|
|
75
|
+
console.log(`Lying Score: ${result.scores.lying}/10`);
|
|
76
|
+
console.log(`Overall: ${result.overallPassed ? 'PASSED ✅' : 'FAILED ❌'}`);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### With Progress Updates
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const result = await client.assess(
|
|
83
|
+
async (question) => await myAI.chat(question),
|
|
84
|
+
{
|
|
85
|
+
onProgress: (progress) => {
|
|
86
|
+
console.log(`${progress.percentage}% - Testing ${progress.dimension}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Startup Health Check (Blocking)
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// Block until AI passes - exits process on failure
|
|
96
|
+
await client.blockUntilPass(
|
|
97
|
+
async (question) => await myAI.chat(question),
|
|
98
|
+
{
|
|
99
|
+
maxRetries: 3,
|
|
100
|
+
retryDelayMs: 60000, // 1 minute between retries
|
|
101
|
+
exitOnFailure: true
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
console.log('✅ AI passed ethical assessment, starting app...');
|
|
106
|
+
startApp();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### CI/CD Pipeline Integration
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const result = await client.assess(
|
|
113
|
+
async (question) => await myAI.chat(question),
|
|
114
|
+
{
|
|
115
|
+
metadata: {
|
|
116
|
+
gitCommit: process.env.GITHUB_SHA,
|
|
117
|
+
branch: process.env.GITHUB_REF_NAME,
|
|
118
|
+
deployVersion: process.env.VERSION
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
// Exit code for CI/CD
|
|
124
|
+
process.exit(result.overallPassed ? 0 : 1);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### With OpenAI
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import OpenAI from 'openai';
|
|
131
|
+
import { AIAssessClient } from '@aiassesstech/sdk';
|
|
132
|
+
|
|
133
|
+
const openai = new OpenAI();
|
|
134
|
+
const client = new AIAssessClient({
|
|
135
|
+
healthCheckKey: process.env.AIASSESS_KEY!
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const result = await client.assess(async (question) => {
|
|
139
|
+
const response = await openai.chat.completions.create({
|
|
140
|
+
model: 'gpt-4',
|
|
141
|
+
messages: [{ role: 'user', content: question }]
|
|
142
|
+
});
|
|
143
|
+
return response.choices[0].message.content || '';
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### With Anthropic
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
151
|
+
import { AIAssessClient } from '@aiassesstech/sdk';
|
|
152
|
+
|
|
153
|
+
const anthropic = new Anthropic();
|
|
154
|
+
const client = new AIAssessClient({
|
|
155
|
+
healthCheckKey: process.env.AIASSESS_KEY!
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const result = await client.assess(async (question) => {
|
|
159
|
+
const response = await anthropic.messages.create({
|
|
160
|
+
model: 'claude-3-sonnet-20240229',
|
|
161
|
+
max_tokens: 100,
|
|
162
|
+
messages: [{ role: 'user', content: question }]
|
|
163
|
+
});
|
|
164
|
+
return response.content[0].type === 'text'
|
|
165
|
+
? response.content[0].text
|
|
166
|
+
: '';
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### With Retry Wrapper (for Flaky APIs)
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { AIAssessClient, withRetry } from '@aiassesstech/sdk';
|
|
174
|
+
|
|
175
|
+
const result = await client.assess(
|
|
176
|
+
withRetry(
|
|
177
|
+
async (question) => await flakyAI.chat(question),
|
|
178
|
+
{ maxRetries: 3, backoffMs: 1000 }
|
|
179
|
+
)
|
|
180
|
+
);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Dry Run Mode (Development)
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// Only asks 5 questions, returns mock scores
|
|
187
|
+
const result = await client.assess(
|
|
188
|
+
async (question) => await myAI.chat(question),
|
|
189
|
+
{ dryRun: true }
|
|
190
|
+
);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Assessment Result
|
|
194
|
+
|
|
195
|
+
The `assess()` method returns an `AssessmentResult` object:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
interface AssessmentResult {
|
|
199
|
+
runId: string; // Server-generated ID for verification
|
|
200
|
+
sdkSessionId: string; // Client-generated session ID
|
|
201
|
+
|
|
202
|
+
scores: {
|
|
203
|
+
lying: number; // 0-10 scale
|
|
204
|
+
cheating: number;
|
|
205
|
+
stealing: number;
|
|
206
|
+
harm: number;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
passed: {
|
|
210
|
+
lying: boolean; // Did score meet threshold?
|
|
211
|
+
cheating: boolean;
|
|
212
|
+
stealing: boolean;
|
|
213
|
+
harm: boolean;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
overallPassed: boolean; // All dimensions must pass
|
|
217
|
+
|
|
218
|
+
classification:
|
|
219
|
+
| "Well Adjusted" // High scores across all dimensions
|
|
220
|
+
| "Misguided" // Low lying, high harm (believes false things but tries to do good)
|
|
221
|
+
| "Manipulative" // High lying, low harm (deceives but avoids direct harm)
|
|
222
|
+
| "Psychopath"; // Low scores across the board
|
|
223
|
+
|
|
224
|
+
thresholds: { ... }; // Thresholds used from server config
|
|
225
|
+
verifyUrl: string; // URL to verify this result
|
|
226
|
+
completedAt: string; // ISO timestamp
|
|
227
|
+
versions: { ... }; // SDK and question set versions
|
|
228
|
+
keyName: string; // Name of Health Check Key used
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Server-Controlled Configuration
|
|
233
|
+
|
|
234
|
+
Configuration is managed via the **Health Check Key** on the AI Assess Tech dashboard:
|
|
235
|
+
|
|
236
|
+
- **Test Mode**: ISOLATED (each question independent) or CONVERSATIONAL (coming in v0.8.0)
|
|
237
|
+
- **Framework**: Which question set to use
|
|
238
|
+
- **Thresholds**: Pass thresholds per dimension (0-10 scale)
|
|
239
|
+
- **Rate Limits**: Hourly/monthly assessment limits
|
|
240
|
+
|
|
241
|
+
Create different keys for different scenarios:
|
|
242
|
+
- `prod-strict`: Production with strict thresholds
|
|
243
|
+
- `staging-relaxed`: Staging with relaxed thresholds
|
|
244
|
+
- `ci-quick`: CI/CD pipeline checks
|
|
245
|
+
|
|
246
|
+
## Error Handling
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import {
|
|
250
|
+
AIAssessClient,
|
|
251
|
+
SDKError,
|
|
252
|
+
ValidationError,
|
|
253
|
+
RateLimitError,
|
|
254
|
+
QuestionTimeoutError,
|
|
255
|
+
ErrorCode
|
|
256
|
+
} from '@aiassesstech/sdk';
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
const result = await client.assess(callback);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
if (error instanceof RateLimitError) {
|
|
262
|
+
console.log(`Rate limited. Retry after ${error.retryAfterMs}ms`);
|
|
263
|
+
} else if (error instanceof ValidationError) {
|
|
264
|
+
if (error.code === ErrorCode.KEY_EXPIRED) {
|
|
265
|
+
console.log('Health Check Key has expired');
|
|
266
|
+
} else if (error.code === ErrorCode.INVALID_KEY) {
|
|
267
|
+
console.log('Invalid Health Check Key');
|
|
268
|
+
}
|
|
269
|
+
} else if (error instanceof QuestionTimeoutError) {
|
|
270
|
+
console.log(`Question ${error.questionId} timed out`);
|
|
271
|
+
} else if (error instanceof SDKError) {
|
|
272
|
+
console.log(`SDK Error: ${error.message} (${error.code})`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Configuration Options
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
const client = new AIAssessClient({
|
|
281
|
+
// Required: Your Health Check Key from the dashboard
|
|
282
|
+
healthCheckKey: 'hck_...',
|
|
283
|
+
|
|
284
|
+
// Optional: Override base URL (default: https://www.aiassesstech.com)
|
|
285
|
+
baseUrl: 'https://www.aiassesstech.com',
|
|
286
|
+
|
|
287
|
+
// Optional: Per-question timeout in ms (default: 30000 = 30s)
|
|
288
|
+
perQuestionTimeoutMs: 30000,
|
|
289
|
+
|
|
290
|
+
// Optional: Overall timeout in ms (default: 360000 = 6 min)
|
|
291
|
+
overallTimeoutMs: 360000
|
|
292
|
+
});
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Environment Detection
|
|
296
|
+
|
|
297
|
+
The SDK automatically detects CI/CD environments:
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
import { detectEnvironment, isCI } from '@aiassesstech/sdk';
|
|
301
|
+
|
|
302
|
+
console.log('Is CI:', isCI());
|
|
303
|
+
console.log('Environment:', detectEnvironment());
|
|
304
|
+
// {
|
|
305
|
+
// nodeVersion: 'v20.10.0',
|
|
306
|
+
// platform: 'linux',
|
|
307
|
+
// ciProvider: 'github-actions',
|
|
308
|
+
// ciJobId: '12345678',
|
|
309
|
+
// gitCommit: 'abc123...',
|
|
310
|
+
// gitBranch: 'main'
|
|
311
|
+
// }
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Supported CI providers:
|
|
315
|
+
- GitHub Actions
|
|
316
|
+
- GitLab CI
|
|
317
|
+
- CircleCI
|
|
318
|
+
- Jenkins
|
|
319
|
+
- Travis CI
|
|
320
|
+
- Buildkite
|
|
321
|
+
- Azure Pipelines
|
|
322
|
+
- AWS CodeBuild
|
|
323
|
+
- Bitbucket Pipelines
|
|
324
|
+
- Drone CI
|
|
325
|
+
- Vercel
|
|
326
|
+
- Netlify
|
|
327
|
+
- And more...
|
|
328
|
+
|
|
329
|
+
## Requirements
|
|
330
|
+
|
|
331
|
+
- Node.js 18.0.0 or higher
|
|
332
|
+
- Valid Health Check Key from [AI Assess Tech](https://www.aiassesstech.com)
|
|
333
|
+
|
|
334
|
+
## Getting a Health Check Key
|
|
335
|
+
|
|
336
|
+
1. Sign up at [https://www.aiassesstech.com](https://www.aiassesstech.com)
|
|
337
|
+
2. Go to Settings → Health Check Keys
|
|
338
|
+
3. Click "Create New Key"
|
|
339
|
+
4. Configure your key (test mode, thresholds, rate limits)
|
|
340
|
+
5. Copy the key (`hck_...`) and store it securely
|
|
341
|
+
|
|
342
|
+
## Support
|
|
343
|
+
|
|
344
|
+
- 📚 [Documentation](https://www.aiassesstech.com/docs)
|
|
345
|
+
- 🐛 [Issue Tracker](https://github.com/aiassesstech/sdk-ts/issues)
|
|
346
|
+
- 📧 [Support](mailto:support@aiassesstech.com)
|
|
347
|
+
|
|
348
|
+
## License
|
|
349
|
+
|
|
350
|
+
MIT © AI Assess Tech
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Jest setup for SDK tests
|
|
4
|
+
*/
|
|
5
|
+
// Mock node-fetch globally
|
|
6
|
+
global.fetch = jest.fn();
|
|
7
|
+
// Mock console methods to keep test output clean
|
|
8
|
+
global.console = {
|
|
9
|
+
...console,
|
|
10
|
+
log: jest.fn(),
|
|
11
|
+
error: jest.fn(),
|
|
12
|
+
warn: jest.fn(),
|
|
13
|
+
};
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Assess Tech SDK - API Functions
|
|
3
|
+
*
|
|
4
|
+
* Server communication functions for config fetching and response submission
|
|
5
|
+
*
|
|
6
|
+
* @version 0.7.0
|
|
7
|
+
*/
|
|
8
|
+
import { ServerConfig, AssessmentResult, ClientEnvironment } from "./types";
|
|
9
|
+
/**
|
|
10
|
+
* Parameters for fetching configuration
|
|
11
|
+
*/
|
|
12
|
+
interface FetchConfigParams {
|
|
13
|
+
healthCheckKey: string;
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
sdkVersion: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Fetch server configuration for a Health Check Key
|
|
19
|
+
*
|
|
20
|
+
* @param params - Configuration fetch parameters
|
|
21
|
+
* @returns Server configuration including questions and thresholds
|
|
22
|
+
*/
|
|
23
|
+
export declare function fetchConfig(params: FetchConfigParams): Promise<ServerConfig>;
|
|
24
|
+
/**
|
|
25
|
+
* Parameters for submitting responses
|
|
26
|
+
*/
|
|
27
|
+
interface SubmitResponsesParams {
|
|
28
|
+
healthCheckKey: string;
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
sdkSessionId: string;
|
|
31
|
+
sdkVersion: string;
|
|
32
|
+
questionSetVersion: string;
|
|
33
|
+
responses: Array<{
|
|
34
|
+
questionId: string;
|
|
35
|
+
response: string;
|
|
36
|
+
answerLetter: string;
|
|
37
|
+
durationMs: number;
|
|
38
|
+
}>;
|
|
39
|
+
timing: {
|
|
40
|
+
clientStartedAt: string;
|
|
41
|
+
clientCompletedAt: string;
|
|
42
|
+
totalDurationMs: number;
|
|
43
|
+
averageQuestionMs: number;
|
|
44
|
+
};
|
|
45
|
+
environment?: ClientEnvironment;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Submit responses to server for scoring
|
|
50
|
+
*
|
|
51
|
+
* @param params - Response submission parameters
|
|
52
|
+
* @returns Assessment result with scores and pass/fail
|
|
53
|
+
*/
|
|
54
|
+
export declare function submitResponses(params: SubmitResponsesParams): Promise<AssessmentResult>;
|
|
55
|
+
export {};
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI Assess Tech SDK - API Functions
|
|
4
|
+
*
|
|
5
|
+
* Server communication functions for config fetching and response submission
|
|
6
|
+
*
|
|
7
|
+
* @version 0.7.0
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.fetchConfig = fetchConfig;
|
|
11
|
+
exports.submitResponses = submitResponses;
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
/**
|
|
14
|
+
* Fetch server configuration for a Health Check Key
|
|
15
|
+
*
|
|
16
|
+
* @param params - Configuration fetch parameters
|
|
17
|
+
* @returns Server configuration including questions and thresholds
|
|
18
|
+
*/
|
|
19
|
+
async function fetchConfig(params) {
|
|
20
|
+
const response = await fetch(`${params.baseUrl}/api/sdk/config`, {
|
|
21
|
+
method: "GET",
|
|
22
|
+
headers: {
|
|
23
|
+
"X-Health-Check-Key": params.healthCheckKey,
|
|
24
|
+
"X-SDK-Version": params.sdkVersion,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const error = await response.json().catch(() => ({}));
|
|
29
|
+
if (response.status === 401) {
|
|
30
|
+
throw new errors_1.ValidationError(error.error || error.message || "Invalid Health Check Key", error.code === "KEY_EXPIRED"
|
|
31
|
+
? errors_1.ErrorCode.KEY_EXPIRED
|
|
32
|
+
: errors_1.ErrorCode.INVALID_KEY);
|
|
33
|
+
}
|
|
34
|
+
if (response.status === 429) {
|
|
35
|
+
const retryAfterMs = parseInt(response.headers.get("Retry-After") || "3600") * 1000;
|
|
36
|
+
throw new errors_1.RateLimitError("Rate limit exceeded", retryAfterMs);
|
|
37
|
+
}
|
|
38
|
+
throw new errors_1.NetworkError(`Failed to fetch config: ${response.status}`, response.status);
|
|
39
|
+
}
|
|
40
|
+
return await response.json();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Submit responses to server for scoring
|
|
44
|
+
*
|
|
45
|
+
* @param params - Response submission parameters
|
|
46
|
+
* @returns Assessment result with scores and pass/fail
|
|
47
|
+
*/
|
|
48
|
+
async function submitResponses(params) {
|
|
49
|
+
const response = await fetch(`${params.baseUrl}/api/sdk/assess`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
"X-Health-Check-Key": params.healthCheckKey,
|
|
54
|
+
"X-SDK-Version": params.sdkVersion,
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify({
|
|
57
|
+
sdkSessionId: params.sdkSessionId,
|
|
58
|
+
questionSetVersion: params.questionSetVersion,
|
|
59
|
+
responses: params.responses,
|
|
60
|
+
timing: params.timing,
|
|
61
|
+
environment: params.environment,
|
|
62
|
+
metadata: params.metadata,
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
const error = await response.json().catch(() => ({}));
|
|
67
|
+
if (response.status === 401) {
|
|
68
|
+
throw new errors_1.ValidationError(error.error || error.message || "Invalid Health Check Key", error.code === "KEY_EXPIRED"
|
|
69
|
+
? errors_1.ErrorCode.KEY_EXPIRED
|
|
70
|
+
: errors_1.ErrorCode.INVALID_KEY);
|
|
71
|
+
}
|
|
72
|
+
if (response.status === 429) {
|
|
73
|
+
throw new errors_1.RateLimitError("Rate limit exceeded", error.retryAfterMs || parseInt(response.headers.get("Retry-After") || "3600") * 1000);
|
|
74
|
+
}
|
|
75
|
+
throw new errors_1.NetworkError(error.error || error.message || `Server error: ${response.status}`, response.status);
|
|
76
|
+
}
|
|
77
|
+
return await response.json();
|
|
78
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* AI Assess Tech CLI
|
|
4
|
+
*
|
|
5
|
+
* Command-line utility for SDK operations.
|
|
6
|
+
*
|
|
7
|
+
* Note: For actual assessments, use the SDK programmatically
|
|
8
|
+
* since assessments require a custom callback to your AI.
|
|
9
|
+
*
|
|
10
|
+
* @version 0.7.0
|
|
11
|
+
*/
|
|
12
|
+
declare const VERSION = "0.7.0";
|
|
13
|
+
/**
|
|
14
|
+
* Print CLI help
|
|
15
|
+
*/
|
|
16
|
+
declare function printHelp(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Print SDK information
|
|
19
|
+
*/
|
|
20
|
+
declare function printInfo(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Verify a test result
|
|
23
|
+
*/
|
|
24
|
+
declare function verify(runId: string, baseUrl: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Main CLI function
|
|
27
|
+
*/
|
|
28
|
+
declare function main(): Promise<void>;
|