@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/dist/cli.js ADDED
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * AI Assess Tech CLI
5
+ *
6
+ * Command-line utility for SDK operations.
7
+ *
8
+ * Note: For actual assessments, use the SDK programmatically
9
+ * since assessments require a custom callback to your AI.
10
+ *
11
+ * @version 0.7.0
12
+ */
13
+ const VERSION = '0.7.0';
14
+ /**
15
+ * Print CLI help
16
+ */
17
+ function printHelp() {
18
+ console.log(`
19
+ AI Assess Tech CLI v${VERSION}
20
+
21
+ Test AI systems for ethical alignment across 4 dimensions:
22
+ Lying, Cheating, Stealing, and Harm.
23
+
24
+ USAGE:
25
+ aiassess [command] [options]
26
+
27
+ COMMANDS:
28
+ verify <runId> Verify a test result by run ID
29
+ info Display SDK information
30
+ help Show this help message
31
+
32
+ OPTIONS:
33
+ --base-url <url> Base URL (default: https://www.aiassesstech.com)
34
+ -h, --help Show this help message
35
+ -v, --version Show version number
36
+
37
+ NOTE:
38
+ For running assessments, use the SDK programmatically:
39
+
40
+ import { AIAssessClient } from '@aiassesstech/sdk';
41
+
42
+ const client = new AIAssessClient({
43
+ healthCheckKey: process.env.AIASSESS_KEY
44
+ });
45
+
46
+ const result = await client.assess(async (question) => {
47
+ return await yourAI.chat(question);
48
+ });
49
+
50
+ DOCUMENTATION:
51
+ https://www.aiassesstech.com/docs
52
+
53
+ EXAMPLES:
54
+ # Verify a test result
55
+ aiassess verify cmjaq0lkv123...
56
+
57
+ # Show SDK info
58
+ aiassess info
59
+ `);
60
+ }
61
+ /**
62
+ * Print SDK information
63
+ */
64
+ function printInfo() {
65
+ console.log(`
66
+ AI Assess Tech SDK v${VERSION}
67
+
68
+ šŸ“¦ Package: @aiassesstech/sdk
69
+ 🌐 Website: https://www.aiassesstech.com
70
+ šŸ“š Docs: https://www.aiassesstech.com/docs
71
+
72
+ Features:
73
+ āœ… Client-side assessment (your AI keys stay private)
74
+ āœ… Server-controlled configuration
75
+ āœ… CI/CD environment detection
76
+ āœ… Full traceability with run IDs
77
+ āœ… Multiple key configurations
78
+
79
+ Dimensions Tested:
80
+ šŸ”¹ Lying - Truth vs. Deception
81
+ šŸ”¹ Cheating - Fairness vs. Exploitation
82
+ šŸ”¹ Stealing - Ownership vs. Theft
83
+ šŸ”¹ Harm - Benefit vs. Damage
84
+
85
+ Classifications:
86
+ 🟢 Well Adjusted - High scores across all dimensions
87
+ 🟔 Misguided - Believes false things but tries to do good
88
+ 🟠 Manipulative - Deceives but avoids direct harm
89
+ šŸ”“ Psychopath - Low scores across the board
90
+ `);
91
+ }
92
+ /**
93
+ * Verify a test result
94
+ */
95
+ async function verify(runId, baseUrl) {
96
+ console.log(`\nšŸ” Verifying test result: ${runId}\n`);
97
+ try {
98
+ const response = await fetch(`${baseUrl}/api/health-check/verify/${runId}`);
99
+ if (!response.ok) {
100
+ const error = await response.json().catch(() => ({}));
101
+ console.error(`āŒ Verification failed: ${error.error || response.statusText}`);
102
+ process.exit(1);
103
+ }
104
+ const result = await response.json();
105
+ console.log('='.repeat(60));
106
+ console.log('šŸ” VERIFICATION RESULT');
107
+ console.log('='.repeat(60));
108
+ console.log(`\nRun ID: ${result.runId}`);
109
+ console.log(`Verified: ${result.verified ? 'āœ… Yes' : 'āŒ No'}`);
110
+ if (result.classification) {
111
+ console.log(`Classification: ${result.classification}`);
112
+ }
113
+ if (result.passed !== undefined) {
114
+ console.log(`Passed: ${result.passed ? 'āœ… Yes' : 'āŒ No'}`);
115
+ }
116
+ if (result.resultHash) {
117
+ console.log(`Result Hash: ${result.resultHash.substring(0, 32)}...`);
118
+ }
119
+ if (result.calculatedAt) {
120
+ console.log(`Calculated: ${new Date(result.calculatedAt).toLocaleString()}`);
121
+ }
122
+ if (result.message) {
123
+ console.log(`\nMessage: ${result.message}`);
124
+ }
125
+ console.log('='.repeat(60) + '\n');
126
+ process.exit(result.verified ? 0 : 1);
127
+ }
128
+ catch (error) {
129
+ console.error(`āŒ Network error: ${error instanceof Error ? error.message : 'Unknown error'}`);
130
+ process.exit(1);
131
+ }
132
+ }
133
+ /**
134
+ * Main CLI function
135
+ */
136
+ async function main() {
137
+ const args = process.argv.slice(2);
138
+ // Handle flags
139
+ if (args.includes('--version') || args.includes('-v')) {
140
+ console.log(`aiassess v${VERSION}`);
141
+ return;
142
+ }
143
+ if (args.includes('--help') || args.includes('-h') || args.length === 0) {
144
+ printHelp();
145
+ return;
146
+ }
147
+ // Parse base URL option
148
+ let baseUrl = 'https://www.aiassesstech.com';
149
+ const baseUrlIndex = args.indexOf('--base-url');
150
+ if (baseUrlIndex !== -1 && args[baseUrlIndex + 1]) {
151
+ baseUrl = args[baseUrlIndex + 1];
152
+ args.splice(baseUrlIndex, 2);
153
+ }
154
+ // Handle commands
155
+ const command = args[0];
156
+ switch (command) {
157
+ case 'help':
158
+ printHelp();
159
+ break;
160
+ case 'info':
161
+ printInfo();
162
+ break;
163
+ case 'verify':
164
+ const runId = args[1];
165
+ if (!runId) {
166
+ console.error('āŒ Error: Run ID is required for verify command');
167
+ console.log('Usage: aiassess verify <runId>');
168
+ process.exit(1);
169
+ }
170
+ await verify(runId, baseUrl);
171
+ break;
172
+ default:
173
+ console.error(`āŒ Unknown command: ${command}`);
174
+ printHelp();
175
+ process.exit(1);
176
+ }
177
+ }
178
+ // Run CLI
179
+ main().catch((error) => {
180
+ console.error(`āŒ Error: ${error.message}`);
181
+ process.exit(1);
182
+ });
@@ -0,0 +1,146 @@
1
+ /**
2
+ * AI Assess Tech SDK - Main Client
3
+ *
4
+ * TypeScript SDK for assessing AI systems for ethical alignment.
5
+ * The AI interaction happens entirely within the developer's environment.
6
+ * Configuration is server-controlled via the Health Check Key.
7
+ *
8
+ * @version 0.7.0
9
+ */
10
+ import { ClientConfig, AICallback, AssessOptions, BlockUntilPassOptions, AssessmentResult, AssessmentArray } from "./types";
11
+ /**
12
+ * Main SDK client for AI ethical assessment
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { AIAssessClient } from '@aiassesstech/sdk';
17
+ *
18
+ * const client = new AIAssessClient({
19
+ * healthCheckKey: process.env.AIASSESS_KEY!
20
+ * });
21
+ *
22
+ * // Run assessment - configuration comes from server
23
+ * const result = await client.assess(async (question) => {
24
+ * return await myAI.chat(question);
25
+ * });
26
+ *
27
+ * console.log('Passed:', result.overallPassed);
28
+ * console.log('Scores:', result.scores);
29
+ * ```
30
+ */
31
+ export declare class AIAssessClient {
32
+ private readonly healthCheckKey;
33
+ private readonly baseUrl;
34
+ private readonly perQuestionTimeoutMs;
35
+ private readonly overallTimeoutMs;
36
+ private cachedConfig;
37
+ /**
38
+ * Create a new AI Assess client
39
+ *
40
+ * @param config - Client configuration
41
+ */
42
+ constructor(config: ClientConfig);
43
+ /**
44
+ * Fetch configuration from server (cached for session)
45
+ * Configuration is determined by the Health Check Key
46
+ */
47
+ private getConfig;
48
+ /**
49
+ * Assess an AI implementation for ethical alignment
50
+ *
51
+ * Configuration (thresholds, questions) comes from server
52
+ * based on the Health Check Key.
53
+ *
54
+ * v0.7.0: Runs in ISOLATED mode only (each question independent)
55
+ *
56
+ * @param aiCallback - Function that sends a question to your AI and returns the response
57
+ * @param options - Assessment options
58
+ * @returns Assessment result with scores and pass/fail status
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const result = await client.assess(async (question) => {
63
+ * const response = await openai.chat.completions.create({
64
+ * model: 'gpt-4',
65
+ * messages: [{ role: 'user', content: question }]
66
+ * });
67
+ * return response.choices[0].message.content || '';
68
+ * });
69
+ * ```
70
+ */
71
+ assess(aiCallback: AICallback, options?: AssessOptions): Promise<AssessmentResult>;
72
+ /**
73
+ * Block until assessment passes (for startup health checks)
74
+ *
75
+ * @param aiCallback - Function that sends a question to your AI
76
+ * @param options - Block options including retry settings
77
+ * @returns Assessment result (only returns if passed)
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * // Block until AI passes - exits process on failure
82
+ * await client.blockUntilPass(
83
+ * async (question) => await myAI.chat(question),
84
+ * {
85
+ * maxRetries: 3,
86
+ * exitOnFailure: true
87
+ * }
88
+ * );
89
+ *
90
+ * console.log('āœ… AI passed, starting application...');
91
+ * startApp();
92
+ * ```
93
+ */
94
+ blockUntilPass(aiCallback: AICallback, options?: BlockUntilPassOptions): Promise<AssessmentResult>;
95
+ /**
96
+ * Convenience method: Returns assessment as flat array
97
+ *
98
+ * @param aiCallback - Function that sends a question to your AI
99
+ * @param options - Assessment options
100
+ * @returns Array of [lyingScore, cheatingScore, stealingScore, harmScore, lyingPassed, cheatingPassed, stealingPassed, harmPassed]
101
+ */
102
+ assessArray(aiCallback: AICallback, options?: AssessOptions): Promise<AssessmentArray>;
103
+ /**
104
+ * Format a question for the AI (multiple choice format)
105
+ */
106
+ private formatQuestion;
107
+ /**
108
+ * Extract answer letter from AI response (robust extraction)
109
+ */
110
+ private extractAnswerLetter;
111
+ private mockDryRunResult;
112
+ private withTimeout;
113
+ private sleep;
114
+ }
115
+ /**
116
+ * Retry wrapper utility for developer's AI callback
117
+ * Wraps a callback with automatic retry logic with exponential backoff
118
+ *
119
+ * @param callback - The AI callback to wrap
120
+ * @param options - Retry options
121
+ * @returns Wrapped callback with retry logic
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const result = await client.assess(
126
+ * withRetry(async (question) => await flakyAI.chat(question), {
127
+ * maxRetries: 3,
128
+ * backoffMs: 1000
129
+ * })
130
+ * );
131
+ * ```
132
+ */
133
+ export declare function withRetry(callback: AICallback, options?: {
134
+ maxRetries?: number;
135
+ backoffMs?: number;
136
+ }): AICallback;
137
+ /**
138
+ * @deprecated Use AIAssessClient instead
139
+ */
140
+ export declare class HealthCheckClient extends AIAssessClient {
141
+ constructor(config: {
142
+ apiKey: string;
143
+ baseUrl?: string;
144
+ timeout?: number;
145
+ });
146
+ }