@castari/sdk 0.1.5 → 0.2.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,52 @@
1
+ /**
2
+ * Base error class for all Castari SDK errors
3
+ */
4
+ export declare class CastariError extends Error {
5
+ /** Error code from the API */
6
+ code?: string;
7
+ /** HTTP status code */
8
+ statusCode?: number;
9
+ constructor(message: string, options?: {
10
+ code?: string;
11
+ statusCode?: number;
12
+ });
13
+ }
14
+ /**
15
+ * Error thrown when authentication fails or is missing
16
+ */
17
+ export declare class AuthenticationError extends CastariError {
18
+ constructor(message?: string);
19
+ }
20
+ /**
21
+ * Error thrown when a resource is not found
22
+ */
23
+ export declare class NotFoundError extends CastariError {
24
+ constructor(message?: string);
25
+ }
26
+ /**
27
+ * Error thrown when request validation fails
28
+ */
29
+ export declare class ValidationError extends CastariError {
30
+ constructor(message?: string);
31
+ }
32
+ /**
33
+ * Error thrown when rate limit is exceeded
34
+ */
35
+ export declare class RateLimitError extends CastariError {
36
+ /** Seconds to wait before retrying */
37
+ retryAfter?: number;
38
+ constructor(message?: string, retryAfter?: number);
39
+ }
40
+ /**
41
+ * Error thrown when the API returns a bad request
42
+ */
43
+ export declare class BadRequestError extends CastariError {
44
+ constructor(message?: string);
45
+ }
46
+ /**
47
+ * Error thrown for server-side errors
48
+ */
49
+ export declare class ServerError extends CastariError {
50
+ constructor(message?: string);
51
+ }
52
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAER,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;CAM9E;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,OAAO,SAA+D;CAInF;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;gBACjC,OAAO,SAAwB;CAI5C;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;gBACnC,OAAO,SAAsB;CAI1C;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,sCAAsC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;gBAER,OAAO,SAAyB,EAAE,UAAU,CAAC,EAAE,MAAM;CAKlE;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;gBACnC,OAAO,SAAiB;CAIrC;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY;gBAC/B,OAAO,SAA0C;CAI9D"}
package/dist/errors.js ADDED
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Base error class for all Castari SDK errors
3
+ */
4
+ export class CastariError extends Error {
5
+ /** Error code from the API */
6
+ code;
7
+ /** HTTP status code */
8
+ statusCode;
9
+ constructor(message, options) {
10
+ super(message);
11
+ this.name = 'CastariError';
12
+ this.code = options?.code;
13
+ this.statusCode = options?.statusCode;
14
+ }
15
+ }
16
+ /**
17
+ * Error thrown when authentication fails or is missing
18
+ */
19
+ export class AuthenticationError extends CastariError {
20
+ constructor(message = 'Authentication failed. Run \'cast login\' to authenticate.') {
21
+ super(message, { statusCode: 401 });
22
+ this.name = 'AuthenticationError';
23
+ }
24
+ }
25
+ /**
26
+ * Error thrown when a resource is not found
27
+ */
28
+ export class NotFoundError extends CastariError {
29
+ constructor(message = 'Resource not found.') {
30
+ super(message, { statusCode: 404 });
31
+ this.name = 'NotFoundError';
32
+ }
33
+ }
34
+ /**
35
+ * Error thrown when request validation fails
36
+ */
37
+ export class ValidationError extends CastariError {
38
+ constructor(message = 'Validation error.') {
39
+ super(message, { statusCode: 422 });
40
+ this.name = 'ValidationError';
41
+ }
42
+ }
43
+ /**
44
+ * Error thrown when rate limit is exceeded
45
+ */
46
+ export class RateLimitError extends CastariError {
47
+ /** Seconds to wait before retrying */
48
+ retryAfter;
49
+ constructor(message = 'Rate limit exceeded.', retryAfter) {
50
+ super(message, { statusCode: 429 });
51
+ this.name = 'RateLimitError';
52
+ this.retryAfter = retryAfter;
53
+ }
54
+ }
55
+ /**
56
+ * Error thrown when the API returns a bad request
57
+ */
58
+ export class BadRequestError extends CastariError {
59
+ constructor(message = 'Bad request.') {
60
+ super(message, { statusCode: 400 });
61
+ this.name = 'BadRequestError';
62
+ }
63
+ }
64
+ /**
65
+ * Error thrown for server-side errors
66
+ */
67
+ export class ServerError extends CastariError {
68
+ constructor(message = 'Server error. Please try again later.') {
69
+ super(message, { statusCode: 500 });
70
+ this.name = 'ServerError';
71
+ }
72
+ }
73
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,8BAA8B;IAC9B,IAAI,CAAU;IACd,uBAAuB;IACvB,UAAU,CAAU;IAEpB,YAAY,OAAe,EAAE,OAAgD;QAC3E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,CAAC;IACxC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IACnD,YAAY,OAAO,GAAG,4DAA4D;QAChF,KAAK,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;C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ET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
2
+ export interface HttpClientOptions {
3
+ baseUrl: string;
4
+ authType?: 'api_key' | 'token';
5
+ authValue?: string;
6
+ }
7
+ /**
8
+ * HTTP client for making API requests
9
+ */
10
+ export declare class HttpClient {
11
+ private baseUrl;
12
+ private authType?;
13
+ private authValue?;
14
+ constructor(options: HttpClientOptions);
15
+ /**
16
+ * Set authentication credentials
17
+ */
18
+ setAuth(type: 'api_key' | 'token', value: string): void;
19
+ /**
20
+ * Make an HTTP request to the API
21
+ */
22
+ request<T>(method: HttpMethod, path: string, options?: {
23
+ body?: unknown;
24
+ query?: Record<string, string | number | undefined>;
25
+ timeout?: number;
26
+ }): Promise<T>;
27
+ /**
28
+ * Handle HTTP error responses
29
+ */
30
+ private handleError;
31
+ }
32
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;AAErE,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,CAAsB;IACvC,OAAO,CAAC,SAAS,CAAC,CAAS;gBAEf,OAAO,EAAE,iBAAiB;IAMtC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAKvD;;OAEG;IACG,OAAO,CAAC,CAAC,EACb,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;QACpD,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GACA,OAAO,CAAC,CAAC,CAAC;IA4Eb;;OAEG;IACH,OAAO,CAAC,WAAW;CA6BpB"}
package/dist/http.js ADDED
@@ -0,0 +1,117 @@
1
+ import { CastariError, AuthenticationError, NotFoundError, ValidationError, RateLimitError, BadRequestError, ServerError, } from './errors.js';
2
+ /**
3
+ * HTTP client for making API requests
4
+ */
5
+ export class HttpClient {
6
+ baseUrl;
7
+ authType;
8
+ authValue;
9
+ constructor(options) {
10
+ this.baseUrl = options.baseUrl.replace(/\/$/, ''); // Remove trailing slash
11
+ this.authType = options.authType;
12
+ this.authValue = options.authValue;
13
+ }
14
+ /**
15
+ * Set authentication credentials
16
+ */
17
+ setAuth(type, value) {
18
+ this.authType = type;
19
+ this.authValue = value;
20
+ }
21
+ /**
22
+ * Make an HTTP request to the API
23
+ */
24
+ async request(method, path, options) {
25
+ const url = new URL(`/api/v1${path}`, this.baseUrl);
26
+ // Add query parameters
27
+ if (options?.query) {
28
+ for (const [key, value] of Object.entries(options.query)) {
29
+ if (value !== undefined) {
30
+ url.searchParams.set(key, String(value));
31
+ }
32
+ }
33
+ }
34
+ // Build headers
35
+ const headers = {
36
+ 'Content-Type': 'application/json',
37
+ Accept: 'application/json',
38
+ };
39
+ // Add auth header (both token and api_key use Bearer format)
40
+ if (this.authValue) {
41
+ headers['Authorization'] = `Bearer ${this.authValue}`;
42
+ }
43
+ // Create abort controller for timeout
44
+ const controller = new AbortController();
45
+ const timeout = options?.timeout ?? 120000; // Default 2 minutes
46
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
47
+ try {
48
+ const response = await fetch(url.toString(), {
49
+ method,
50
+ headers,
51
+ body: options?.body ? JSON.stringify(options.body) : undefined,
52
+ signal: controller.signal,
53
+ });
54
+ clearTimeout(timeoutId);
55
+ // Handle no-content responses
56
+ if (response.status === 204) {
57
+ return undefined;
58
+ }
59
+ // Parse response body
60
+ const contentType = response.headers.get('content-type');
61
+ let data;
62
+ if (contentType?.includes('application/json')) {
63
+ data = await response.json();
64
+ }
65
+ else {
66
+ data = await response.text();
67
+ }
68
+ // Handle errors
69
+ if (!response.ok) {
70
+ this.handleError(response.status, data, response.headers);
71
+ }
72
+ return data;
73
+ }
74
+ catch (error) {
75
+ clearTimeout(timeoutId);
76
+ if (error instanceof CastariError) {
77
+ throw error;
78
+ }
79
+ if (error instanceof Error) {
80
+ if (error.name === 'AbortError') {
81
+ throw new CastariError('Request timed out');
82
+ }
83
+ throw new CastariError(`Request failed: ${error.message}`);
84
+ }
85
+ throw new CastariError('An unexpected error occurred');
86
+ }
87
+ }
88
+ /**
89
+ * Handle HTTP error responses
90
+ */
91
+ handleError(status, data, headers) {
92
+ const errorResponse = data;
93
+ const message = errorResponse?.detail || 'An error occurred';
94
+ switch (status) {
95
+ case 400:
96
+ throw new BadRequestError(message);
97
+ case 401:
98
+ throw new AuthenticationError(message);
99
+ case 404:
100
+ throw new NotFoundError(message);
101
+ case 422:
102
+ throw new ValidationError(message);
103
+ case 429: {
104
+ const retryAfter = headers.get('Retry-After');
105
+ throw new RateLimitError(message, retryAfter ? parseInt(retryAfter, 10) : undefined);
106
+ }
107
+ case 500:
108
+ case 502:
109
+ case 503:
110
+ case 504:
111
+ throw new ServerError(message);
112
+ default:
113
+ throw new CastariError(message, { statusCode: status });
114
+ }
115
+ }
116
+ }
117
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,WAAW,GACZ,MAAM,aAAa,CAAC;AAWrB;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,OAAO,CA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G;gBACN,MAAM,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;YACjC;gBACE,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
- export * from './types';
2
- export * from './server';
3
- export * from './client';
4
- export { tool } from '@anthropic-ai/claude-agent-sdk';
1
+ export { CastariClient } from './client.js';
2
+ export { AgentsAPI } from './agents.js';
3
+ export { UsageAPI } from './usage.js';
4
+ export { AuthAPI } from './auth.js';
5
+ export { CastariError, AuthenticationError, NotFoundError, ValidationError, RateLimitError, BadRequestError, ServerError, } from './errors.js';
6
+ export { loadCredentials, saveCredentials, clearCredentials, loadConfig, saveConfig, getApiUrl, getAuth, type Credentials, type Config, } from './config.js';
7
+ export type { Agent, AgentConfig, AgentsListResponse, AgentStatus, ApiKeyResponse, CreateAgentOptions, InvocationResponse, InvokeOptions, Secret, User, UsageSummary, UsageSummaryResponse, DailyUsage, DailyUsageResponse, CastariClientOptions, ApiErrorResponse, } from './types.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,SAAS,EACT,OAAO,EACP,KAAK,WAAW,EAChB,KAAK,MAAM,GACZ,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,KAAK,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,MAAM,EACN,IAAI,EACJ,YAAY,EACZ,oBAAoB,EACpB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,11 @@
1
- export * from './types';
2
- export * from './server';
3
- export * from './client';
4
- export { tool } from '@anthropic-ai/claude-agent-sdk';
1
+ // Main client
2
+ export { CastariClient } from './client.js';
3
+ // API classes
4
+ export { AgentsAPI } from './agents.js';
5
+ export { UsageAPI } from './usage.js';
6
+ export { AuthAPI } from './auth.js';
7
+ // Errors
8
+ export { CastariError, AuthenticationError, NotFoundError, ValidationError, RateLimitError, BadRequestError, ServerError, } from './errors.js';
9
+ // Config utilities
10
+ export { loadCredentials, saveCredentials, clearCredentials, loadConfig, saveConfig, getApiUrl, getAuth, } from './config.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,cAAc;AACd,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,SAAS;AACT,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,mBAAmB;AACnB,OAAO,EACL,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,SAAS,EACT,OAAO,GAGR,MAAM,aAAa,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,59 +1,158 @@
1
- import { type AgentDefinition, type SDKMessage, type SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
2
- export type WSInputMessage = {
3
- type: 'user_message';
4
- data: SDKUserMessage;
5
- } | {
6
- type: 'interrupt';
7
- } | {
8
- type: 'create_file';
9
- path: string;
10
- content: string;
11
- encoding?: 'utf-8' | 'base64';
12
- } | {
13
- type: 'read_file';
14
- path: string;
15
- encoding?: 'utf-8' | 'base64';
16
- } | {
17
- type: 'delete_file';
18
- path: string;
19
- } | {
20
- type: 'list_files';
21
- path?: string;
22
- };
23
- export type WSOutputMessage = {
24
- type: 'connected';
25
- } | {
26
- type: 'sdk_message';
27
- data: SDKMessage;
28
- } | {
29
- type: 'error';
30
- error: string;
31
- } | {
32
- type: 'info';
33
- data: string;
34
- } | {
35
- type: 'file_result';
36
- operation: 'create_file' | 'delete_file';
37
- result: 'success';
38
- } | {
39
- type: 'file_result';
40
- operation: 'read_file';
41
- result: string;
42
- encoding: 'utf-8' | 'base64';
43
- } | {
44
- type: 'file_result';
45
- operation: 'list_files';
46
- result: string[];
47
- };
48
- export type QueryConfig = {
49
- agents?: Record<string, AgentDefinition>;
50
- allowedTools?: string[];
51
- systemPrompt?: string | {
52
- type: 'preset';
53
- preset: 'claude_code';
54
- append?: string;
55
- };
1
+ /**
2
+ * Agent status values
3
+ */
4
+ export type AgentStatus = 'draft' | 'pending' | 'deploying' | 'active' | 'stopped' | 'failed';
5
+ /**
6
+ * Agent configuration
7
+ */
8
+ export interface AgentConfig {
56
9
  model?: string;
57
- anthropicApiKey?: string;
58
- resume?: string;
59
- };
10
+ max_turns?: number;
11
+ system_prompt?: string;
12
+ }
13
+ /**
14
+ * An AI agent on the Castari platform
15
+ */
16
+ export interface Agent {
17
+ id: string;
18
+ user_id: string;
19
+ name: string;
20
+ slug: string;
21
+ description?: string | null;
22
+ git_repo_url: string;
23
+ git_branch: string;
24
+ agent_config?: AgentConfig;
25
+ default_model: string;
26
+ max_turns: number;
27
+ timeout_seconds: number;
28
+ status: AgentStatus;
29
+ status_message?: string | null;
30
+ sandbox_id?: string | null;
31
+ created_at: string;
32
+ updated_at: string;
33
+ }
34
+ /**
35
+ * Response from listing agents
36
+ */
37
+ export interface AgentsListResponse {
38
+ agents: Agent[];
39
+ meta: {
40
+ total: number;
41
+ limit: number;
42
+ offset: number;
43
+ has_more: boolean;
44
+ };
45
+ }
46
+ /**
47
+ * Options for creating an agent
48
+ */
49
+ export interface CreateAgentOptions {
50
+ name: string;
51
+ gitRepoUrl: string;
52
+ slug?: string;
53
+ description?: string;
54
+ }
55
+ /**
56
+ * Response from invoking an agent
57
+ */
58
+ export interface InvocationResponse {
59
+ invocation_id: string;
60
+ response_content: string;
61
+ input_tokens: number;
62
+ output_tokens: number;
63
+ total_cost_usd: number | string;
64
+ duration_ms: number;
65
+ status: 'completed' | 'failed';
66
+ }
67
+ /**
68
+ * Options for invoking an agent
69
+ */
70
+ export interface InvokeOptions {
71
+ prompt: string;
72
+ }
73
+ /**
74
+ * A secret key (values are never returned by the API)
75
+ */
76
+ export interface Secret {
77
+ key: string;
78
+ }
79
+ /**
80
+ * The current authenticated user
81
+ */
82
+ export interface User {
83
+ id: string;
84
+ email: string;
85
+ api_key_prefix?: string;
86
+ created_at: string;
87
+ }
88
+ /**
89
+ * Response from creating an API key
90
+ */
91
+ export interface ApiKeyResponse {
92
+ api_key: string;
93
+ prefix: string;
94
+ }
95
+ /**
96
+ * Raw usage summary from API
97
+ */
98
+ export interface UsageSummaryResponse {
99
+ total_invocations: number;
100
+ total_input_tokens: number;
101
+ total_output_tokens: number;
102
+ total_cost_usd: string;
103
+ period_start: string;
104
+ period_end: string;
105
+ }
106
+ /**
107
+ * Usage summary for a period
108
+ */
109
+ export interface UsageSummary {
110
+ total_invocations: number;
111
+ total_input_tokens: number;
112
+ total_output_tokens: number;
113
+ total_cost_usd: number;
114
+ period_start: string;
115
+ period_end: string;
116
+ }
117
+ /**
118
+ * Raw daily usage from API
119
+ */
120
+ export interface DailyUsageResponse {
121
+ daily_usage: Array<{
122
+ date: string;
123
+ invocation_count: number;
124
+ input_tokens: number;
125
+ output_tokens: number;
126
+ cost_usd: string;
127
+ }>;
128
+ total_days: number;
129
+ }
130
+ /**
131
+ * Daily usage breakdown
132
+ */
133
+ export interface DailyUsage {
134
+ date: string;
135
+ invocation_count: number;
136
+ input_tokens: number;
137
+ output_tokens: number;
138
+ cost_usd: number;
139
+ }
140
+ /**
141
+ * Client configuration options
142
+ */
143
+ export interface CastariClientOptions {
144
+ /** API key (starts with cap_) */
145
+ apiKey?: string;
146
+ /** OAuth token */
147
+ token?: string;
148
+ /** Base API URL (default: https://api.castari.dev) */
149
+ baseUrl?: string;
150
+ }
151
+ /**
152
+ * API error response format
153
+ */
154
+ export interface ApiErrorResponse {
155
+ detail: string;
156
+ code?: string;
157
+ }
158
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE9F;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC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AAC;IACf,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
package/dist/types.js CHANGED
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import type { HttpClient } from './http.js';
2
+ import type { UsageSummary, DailyUsage } from './types.js';
3
+ /**
4
+ * API for accessing usage statistics
5
+ */
6
+ export declare class UsageAPI {
7
+ private client;
8
+ constructor(client: HttpClient);
9
+ /**
10
+ * Get usage summary for a period
11
+ * @param options - Options including number of days (default: 30)
12
+ * @returns Usage summary with totals
13
+ */
14
+ summary(options?: {
15
+ days?: number;
16
+ }): Promise<UsageSummary>;
17
+ /**
18
+ * Get daily usage breakdown
19
+ * @param options - Options including number of days (default: 7)
20
+ * @returns Array of daily usage stats
21
+ */
22
+ daily(options?: {
23
+ days?: number;
24
+ }): Promise<DailyUsage[]>;
25
+ }
26
+ //# sourceMappingURL=usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAwB,UAAU,EAAsB,MAAM,YAAY,CAAC;AAErG;;GAEG;AACH,qBAAa,QAAQ;IACP,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;;OAIG;IACG,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAejE;;;;OAIG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAahE"}
package/dist/usage.js ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * API for accessing usage statistics
3
+ */
4
+ export class UsageAPI {
5
+ client;
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ /**
10
+ * Get usage summary for a period
11
+ * @param options - Options including number of days (default: 30)
12
+ * @returns Usage summary with totals
13
+ */
14
+ async summary(options) {
15
+ const response = await this.client.request('GET', '/usage', {
16
+ query: { days: options?.days },
17
+ });
18
+ return {
19
+ total_invocations: response.total_invocations,
20
+ total_input_tokens: response.total_input_tokens,
21
+ total_output_tokens: response.total_output_tokens,
22
+ total_cost_usd: parseFloat(response.total_cost_usd),
23
+ period_start: response.period_start,
24
+ period_end: response.period_end,
25
+ };
26
+ }
27
+ /**
28
+ * Get daily usage breakdown
29
+ * @param options - Options including number of days (default: 7)
30
+ * @returns Array of daily usage stats
31
+ */
32
+ async daily(options) {
33
+ const response = await this.client.request('GET', '/usage/daily', {
34
+ query: { days: options?.days },
35
+ });
36
+ return response.daily_usage.map((day) => ({
37
+ date: day.date,
38
+ invocation_count: day.invocation_count,
39
+ input_tokens: day.input_tokens,
40
+ output_tokens: day.output_tokens,
41
+ cost_usd: parseFloat(day.cost_usd),
42
+ }));
43
+ }
44
+ }
45
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,QAAQ;IACC;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,OAA2B;QACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAuB,KAAK,EAAE,QAAQ,EAAE;YA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