@aicr/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.
@@ -0,0 +1,13 @@
1
+ import type { AICRConfig, AskOptions, AskResponse } from './types';
2
+ export declare class AICR {
3
+ private apiKey;
4
+ private tenantId;
5
+ private baseUrl;
6
+ constructor(config: AICRConfig);
7
+ ask(options: AskOptions): Promise<AskResponse>;
8
+ }
9
+ export declare class AICRError extends Error {
10
+ status: number;
11
+ constructor(message: string, status: number);
12
+ }
13
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAIlE,qBAAa,IAAI;IACf,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,OAAO,CAAQ;gBAEX,MAAM,EAAE,UAAU;IASxB,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CA+BrD;AAED,qBAAa,SAAU,SAAQ,KAAK;IAClC,MAAM,EAAE,MAAM,CAAA;gBAEF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK5C"}
package/dist/client.js ADDED
@@ -0,0 +1,54 @@
1
+ const DEFAULT_BASE_URL = 'https://think.aicoderally.workers.dev';
2
+ export class AICR {
3
+ apiKey;
4
+ tenantId;
5
+ baseUrl;
6
+ constructor(config) {
7
+ if (!config.apiKey)
8
+ throw new Error('apiKey is required');
9
+ if (!config.tenantId)
10
+ throw new Error('tenantId is required');
11
+ this.apiKey = config.apiKey;
12
+ this.tenantId = config.tenantId;
13
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, '');
14
+ }
15
+ async ask(options) {
16
+ if (!options.prompt)
17
+ throw new Error('prompt is required');
18
+ const res = await fetch(`${this.baseUrl}/api/think/ask`, {
19
+ method: 'POST',
20
+ headers: {
21
+ 'Content-Type': 'application/json',
22
+ 'x-api-key': this.apiKey,
23
+ 'x-tenant-id': this.tenantId,
24
+ },
25
+ body: JSON.stringify({
26
+ prompt: options.prompt,
27
+ model: options.model,
28
+ maxTokens: options.maxTokens,
29
+ correlationId: options.correlationId,
30
+ }),
31
+ });
32
+ if (!res.ok) {
33
+ const body = await res.text();
34
+ let message;
35
+ try {
36
+ message = JSON.parse(body).error;
37
+ }
38
+ catch {
39
+ message = body || `HTTP ${res.status}`;
40
+ }
41
+ throw new AICRError(message, res.status);
42
+ }
43
+ return res.json();
44
+ }
45
+ }
46
+ export class AICRError extends Error {
47
+ status;
48
+ constructor(message, status) {
49
+ super(message);
50
+ this.name = 'AICRError';
51
+ this.status = status;
52
+ }
53
+ }
54
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAG,uCAAuC,CAAA;AAEhE,MAAM,OAAO,IAAI;IACP,MAAM,CAAQ;IACd,QAAQ,CAAQ;IAChB,OAAO,CAAQ;IAEvB,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;QACzD,IAAI,CAAC,MAAM,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QAE7D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC3B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;QAC/B,IAAI,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACxE,CAAC;IAED,KAAK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GAAG,MAAM,CAAA;IACtB,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export { AICR, AICRError } from './client';
2
+ export type { AICRConfig, AskOptions, AskResponse, ModelTier } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAC1C,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { AICR, AICRError } from './client';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,27 @@
1
+ export type ModelTier = 'scout' | 'claude';
2
+ export interface AICRConfig {
3
+ apiKey: string;
4
+ tenantId: string;
5
+ baseUrl?: string;
6
+ }
7
+ export interface AskOptions {
8
+ prompt: string;
9
+ model?: ModelTier;
10
+ maxTokens?: number;
11
+ correlationId?: string;
12
+ }
13
+ export interface AskResponse {
14
+ text: string;
15
+ model: string;
16
+ provider: string;
17
+ tokenUsage?: {
18
+ promptTokens: number;
19
+ completionTokens: number;
20
+ };
21
+ eventId: string;
22
+ }
23
+ export interface AICRError {
24
+ error: string;
25
+ status: number;
26
+ }
27
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAA;AAE1C,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE;QACX,YAAY,EAAE,MAAM,CAAA;QACpB,gBAAgB,EAAE,MAAM,CAAA;KACzB,CAAA;IACD,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@aicr/sdk",
3
+ "version": "0.1.0",
4
+ "description": "AICR platform SDK — AI observability and governance for your apps",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist"],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "typecheck": "tsc --noEmit",
18
+ "test": "vitest run"
19
+ },
20
+ "devDependencies": {
21
+ "typescript": "^5.7.0",
22
+ "vitest": "^3.2.0"
23
+ }
24
+ }