@kloddy/kloddy-js 0.1.0 → 0.1.1

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,178 @@
1
+ import { K as KloddyOptions, U as User, O as Organization, F as Feature, P as PromptListOptions, e as PromptTemplate, d as PromptOptions, b as ExecuteOptions, c as ExecuteResult, E as EvaluationOptions, a as EvaluationResult } from './types-BrCFkSyd.js';
2
+ import React from 'react';
3
+
4
+ /**
5
+ * Low-level client for interacting with the Kloddy API.
6
+ * Handles authentication, token management, and raw requests.
7
+ */
8
+ declare class KloddyClient {
9
+ private apiKey;
10
+ private apiSecret;
11
+ private host;
12
+ defaultOrgId: string | null;
13
+ defaultFeatureId: string | null;
14
+ private token;
15
+ private tokenExpires;
16
+ /**
17
+ * Initialize a new KloddyClient.
18
+ * If no credentials are provided, it will look for:
19
+ * - KLODDY_API_KEY / KLODDY_APP_ID
20
+ * - KLODDY_API_SECRET / KLODDY_SECRET_KEY
21
+ * in process.env.
22
+ */
23
+ constructor(apiKeyOrOptions?: string | KloddyOptions, options?: KloddyOptions);
24
+ /**
25
+ * Authenticate with the Kloddy API and retrieve a session token.
26
+ */
27
+ login(): Promise<string>;
28
+ /**
29
+ * Get the current active token, refreshing it if necessary.
30
+ */
31
+ getToken(): Promise<string>;
32
+ /**
33
+ * Make an authenticated request to the Kloddy API.
34
+ */
35
+ request<T>(path: string, options?: RequestInit): Promise<T>;
36
+ /**
37
+ * Get current user information.
38
+ */
39
+ whoAmI(): Promise<User>;
40
+ /**
41
+ * List organizations for the current user.
42
+ */
43
+ listOrganizations(): Promise<Organization[]>;
44
+ /**
45
+ * List features, optionally filtered by organization.
46
+ */
47
+ listFeatures(orgId?: string): Promise<Feature[]>;
48
+ }
49
+
50
+ /**
51
+ * Manager for Kloddy prompts.
52
+ *
53
+ * @template TPromptNames Union of strings representing available prompt names for type safety.
54
+ */
55
+ declare class Prompts<TPromptNames extends string = string> {
56
+ private client;
57
+ constructor(options: {
58
+ client?: KloddyClient;
59
+ } | KloddyOptions);
60
+ /**
61
+ * List prompts with filters.
62
+ */
63
+ list(options?: PromptListOptions): Promise<PromptTemplate[]>;
64
+ /**
65
+ * Fetch a prompt template.
66
+ *
67
+ * @param name The unique name of the prompt.
68
+ * @param options Fetching options (version, fallback, etc.)
69
+ */
70
+ get(name: TPromptNames, options?: PromptOptions): Promise<PromptTemplate>;
71
+ /**
72
+ * Execute a prompt via the Kloddy API.
73
+ *
74
+ * @param name The unique name of the prompt.
75
+ * @param options Execution variables and model overrides.
76
+ */
77
+ execute(name: TPromptNames, options?: ExecuteOptions): Promise<ExecuteResult>;
78
+ /**
79
+ * Play: Direct execution for a single model/version.
80
+ * Same as execute but follows specific naming/body requirements.
81
+ *
82
+ * @param name The unique name of the prompt.
83
+ * @param options Execution variables and model overrides.
84
+ */
85
+ play(name: TPromptNames, options?: Omit<ExecuteOptions, 'judge' | 'evaluate_id'>): Promise<ExecuteResult>;
86
+ /**
87
+ * Update: Download all prompts for the user/organization.
88
+ */
89
+ update(options?: PromptListOptions): Promise<PromptTemplate[]>;
90
+ /**
91
+ * Local compilation of a template string with variables.
92
+ *
93
+ * @param template The template string or PromptTemplate object.
94
+ * @param variables Dictionary of variables to inject (e.g., {{variable}}).
95
+ */
96
+ compile(template: string | PromptTemplate, variables: Record<string, any>): string;
97
+ }
98
+
99
+ /**
100
+ * Manager for Kloddy evaluations.
101
+ * Allows running and retrieving model comparisons.
102
+ */
103
+ declare class Evaluations {
104
+ private client;
105
+ constructor(options: {
106
+ client?: KloddyClient;
107
+ } | KloddyOptions);
108
+ /**
109
+ * Run or retrieve an evaluation.
110
+ *
111
+ * @param options Evaluation criteria including models, judge, and variables.
112
+ */
113
+ run(options: EvaluationOptions): Promise<EvaluationResult>;
114
+ /**
115
+ * Alias for run().
116
+ *
117
+ * @param options Evaluation criteria.
118
+ */
119
+ evaluate(options: EvaluationOptions): Promise<EvaluationResult>;
120
+ /**
121
+ * Simple one-step evaluation call.
122
+ *
123
+ * @param name The name of the evaluation to run.
124
+ * @param variables Variables to inject into the evaluation.
125
+ */
126
+ get(name: string, variables?: Record<string, any>): Promise<EvaluationResult>;
127
+ }
128
+
129
+ interface KloddyProviderProps {
130
+ children: React.ReactNode;
131
+ client?: KloddyClient;
132
+ options?: KloddyOptions;
133
+ apiKey?: string;
134
+ token?: string;
135
+ authEndpoint?: string;
136
+ }
137
+ /**
138
+ * KloddyProvider manages the Kloddy SDK state for React applications.
139
+ * It handles client initialization and optional automatic token fetching.
140
+ */
141
+ declare const KloddyProvider: React.FC<KloddyProviderProps>;
142
+ /**
143
+ * Hook to access Kloddy prompts and general SDK features.
144
+ *
145
+ * @template TPromptNames Union of strings for type-safe prompt names.
146
+ */
147
+ declare const usePrompt: <TPromptNames extends string = string>() => {
148
+ prompts: Prompts<TPromptNames>;
149
+ isLoading: boolean;
150
+ error: Error | null;
151
+ getPrompt: (id: TPromptNames, options?: PromptOptions) => Promise<PromptTemplate>;
152
+ getAwnser: (id: TPromptNames, options?: ExecuteOptions) => Promise<ExecuteResult>;
153
+ /** @deprecated Use useEvaluations instead */
154
+ getEvaluation: (id: string, variables?: {}) => Promise<EvaluationResult>;
155
+ compile: (template: any, variables: any) => string;
156
+ };
157
+ /**
158
+ * Hook to access Kloddy evaluations.
159
+ */
160
+ declare const useEvaluations: () => {
161
+ evaluations: Evaluations;
162
+ isLoading: boolean;
163
+ error: Error | null;
164
+ run: (options: EvaluationOptions) => Promise<EvaluationResult>;
165
+ evaluate: (options: EvaluationOptions) => Promise<EvaluationResult>;
166
+ get: (name: string, variables?: {}) => Promise<EvaluationResult>;
167
+ };
168
+ /**
169
+ * Hook for streaming prompt responses.
170
+ * (Placeholder implementation - requires backend streaming support)
171
+ */
172
+ declare const usePromptStream: <TPromptNames extends string = string>() => {
173
+ stream: string;
174
+ isStreaming: boolean;
175
+ executeStream: (name: TPromptNames, options?: ExecuteOptions) => Promise<ExecuteResult>;
176
+ };
177
+
178
+ export { Evaluations as E, KloddyClient as K, Prompts as P, KloddyProvider as a, type KloddyProviderProps as b, usePrompt as c, usePromptStream as d, useEvaluations as u };
@@ -0,0 +1,178 @@
1
+ import { K as KloddyOptions, U as User, O as Organization, F as Feature, P as PromptListOptions, e as PromptTemplate, d as PromptOptions, b as ExecuteOptions, c as ExecuteResult, E as EvaluationOptions, a as EvaluationResult } from './types-BrCFkSyd.mjs';
2
+ import React from 'react';
3
+
4
+ /**
5
+ * Low-level client for interacting with the Kloddy API.
6
+ * Handles authentication, token management, and raw requests.
7
+ */
8
+ declare class KloddyClient {
9
+ private apiKey;
10
+ private apiSecret;
11
+ private host;
12
+ defaultOrgId: string | null;
13
+ defaultFeatureId: string | null;
14
+ private token;
15
+ private tokenExpires;
16
+ /**
17
+ * Initialize a new KloddyClient.
18
+ * If no credentials are provided, it will look for:
19
+ * - KLODDY_API_KEY / KLODDY_APP_ID
20
+ * - KLODDY_API_SECRET / KLODDY_SECRET_KEY
21
+ * in process.env.
22
+ */
23
+ constructor(apiKeyOrOptions?: string | KloddyOptions, options?: KloddyOptions);
24
+ /**
25
+ * Authenticate with the Kloddy API and retrieve a session token.
26
+ */
27
+ login(): Promise<string>;
28
+ /**
29
+ * Get the current active token, refreshing it if necessary.
30
+ */
31
+ getToken(): Promise<string>;
32
+ /**
33
+ * Make an authenticated request to the Kloddy API.
34
+ */
35
+ request<T>(path: string, options?: RequestInit): Promise<T>;
36
+ /**
37
+ * Get current user information.
38
+ */
39
+ whoAmI(): Promise<User>;
40
+ /**
41
+ * List organizations for the current user.
42
+ */
43
+ listOrganizations(): Promise<Organization[]>;
44
+ /**
45
+ * List features, optionally filtered by organization.
46
+ */
47
+ listFeatures(orgId?: string): Promise<Feature[]>;
48
+ }
49
+
50
+ /**
51
+ * Manager for Kloddy prompts.
52
+ *
53
+ * @template TPromptNames Union of strings representing available prompt names for type safety.
54
+ */
55
+ declare class Prompts<TPromptNames extends string = string> {
56
+ private client;
57
+ constructor(options: {
58
+ client?: KloddyClient;
59
+ } | KloddyOptions);
60
+ /**
61
+ * List prompts with filters.
62
+ */
63
+ list(options?: PromptListOptions): Promise<PromptTemplate[]>;
64
+ /**
65
+ * Fetch a prompt template.
66
+ *
67
+ * @param name The unique name of the prompt.
68
+ * @param options Fetching options (version, fallback, etc.)
69
+ */
70
+ get(name: TPromptNames, options?: PromptOptions): Promise<PromptTemplate>;
71
+ /**
72
+ * Execute a prompt via the Kloddy API.
73
+ *
74
+ * @param name The unique name of the prompt.
75
+ * @param options Execution variables and model overrides.
76
+ */
77
+ execute(name: TPromptNames, options?: ExecuteOptions): Promise<ExecuteResult>;
78
+ /**
79
+ * Play: Direct execution for a single model/version.
80
+ * Same as execute but follows specific naming/body requirements.
81
+ *
82
+ * @param name The unique name of the prompt.
83
+ * @param options Execution variables and model overrides.
84
+ */
85
+ play(name: TPromptNames, options?: Omit<ExecuteOptions, 'judge' | 'evaluate_id'>): Promise<ExecuteResult>;
86
+ /**
87
+ * Update: Download all prompts for the user/organization.
88
+ */
89
+ update(options?: PromptListOptions): Promise<PromptTemplate[]>;
90
+ /**
91
+ * Local compilation of a template string with variables.
92
+ *
93
+ * @param template The template string or PromptTemplate object.
94
+ * @param variables Dictionary of variables to inject (e.g., {{variable}}).
95
+ */
96
+ compile(template: string | PromptTemplate, variables: Record<string, any>): string;
97
+ }
98
+
99
+ /**
100
+ * Manager for Kloddy evaluations.
101
+ * Allows running and retrieving model comparisons.
102
+ */
103
+ declare class Evaluations {
104
+ private client;
105
+ constructor(options: {
106
+ client?: KloddyClient;
107
+ } | KloddyOptions);
108
+ /**
109
+ * Run or retrieve an evaluation.
110
+ *
111
+ * @param options Evaluation criteria including models, judge, and variables.
112
+ */
113
+ run(options: EvaluationOptions): Promise<EvaluationResult>;
114
+ /**
115
+ * Alias for run().
116
+ *
117
+ * @param options Evaluation criteria.
118
+ */
119
+ evaluate(options: EvaluationOptions): Promise<EvaluationResult>;
120
+ /**
121
+ * Simple one-step evaluation call.
122
+ *
123
+ * @param name The name of the evaluation to run.
124
+ * @param variables Variables to inject into the evaluation.
125
+ */
126
+ get(name: string, variables?: Record<string, any>): Promise<EvaluationResult>;
127
+ }
128
+
129
+ interface KloddyProviderProps {
130
+ children: React.ReactNode;
131
+ client?: KloddyClient;
132
+ options?: KloddyOptions;
133
+ apiKey?: string;
134
+ token?: string;
135
+ authEndpoint?: string;
136
+ }
137
+ /**
138
+ * KloddyProvider manages the Kloddy SDK state for React applications.
139
+ * It handles client initialization and optional automatic token fetching.
140
+ */
141
+ declare const KloddyProvider: React.FC<KloddyProviderProps>;
142
+ /**
143
+ * Hook to access Kloddy prompts and general SDK features.
144
+ *
145
+ * @template TPromptNames Union of strings for type-safe prompt names.
146
+ */
147
+ declare const usePrompt: <TPromptNames extends string = string>() => {
148
+ prompts: Prompts<TPromptNames>;
149
+ isLoading: boolean;
150
+ error: Error | null;
151
+ getPrompt: (id: TPromptNames, options?: PromptOptions) => Promise<PromptTemplate>;
152
+ getAwnser: (id: TPromptNames, options?: ExecuteOptions) => Promise<ExecuteResult>;
153
+ /** @deprecated Use useEvaluations instead */
154
+ getEvaluation: (id: string, variables?: {}) => Promise<EvaluationResult>;
155
+ compile: (template: any, variables: any) => string;
156
+ };
157
+ /**
158
+ * Hook to access Kloddy evaluations.
159
+ */
160
+ declare const useEvaluations: () => {
161
+ evaluations: Evaluations;
162
+ isLoading: boolean;
163
+ error: Error | null;
164
+ run: (options: EvaluationOptions) => Promise<EvaluationResult>;
165
+ evaluate: (options: EvaluationOptions) => Promise<EvaluationResult>;
166
+ get: (name: string, variables?: {}) => Promise<EvaluationResult>;
167
+ };
168
+ /**
169
+ * Hook for streaming prompt responses.
170
+ * (Placeholder implementation - requires backend streaming support)
171
+ */
172
+ declare const usePromptStream: <TPromptNames extends string = string>() => {
173
+ stream: string;
174
+ isStreaming: boolean;
175
+ executeStream: (name: TPromptNames, options?: ExecuteOptions) => Promise<ExecuteResult>;
176
+ };
177
+
178
+ export { Evaluations as E, KloddyClient as K, Prompts as P, KloddyProvider as a, type KloddyProviderProps as b, usePrompt as c, usePromptStream as d, useEvaluations as u };
package/dist/index.d.mts CHANGED
@@ -1,113 +1,57 @@
1
- import React from 'react';
1
+ import { K as KloddyOptions, U as User, O as Organization, F as Feature } from './types-BrCFkSyd.mjs';
2
+ export { A as AuthResponse, E as EvaluationOptions, a as EvaluationResult, b as ExecuteOptions, c as ExecuteResult, P as PromptListOptions, d as PromptOptions, e as PromptTemplate } from './types-BrCFkSyd.mjs';
3
+ import { K as KloddyClient, P as Prompts, E as Evaluations } from './index-CqX8s53x.mjs';
4
+ export { a as KloddyProvider, b as KloddyProviderProps, u as useEvaluations, c as usePrompt, d as usePromptStream } from './index-CqX8s53x.mjs';
5
+ import 'react';
2
6
 
3
- interface KloddyOptions {
4
- apiKey?: string;
5
- apiSecret?: string;
6
- token?: string;
7
- personalApiKey?: string;
8
- projectApiKey?: string;
9
- applicationId?: string;
10
- secretKey?: string;
11
- host?: string;
12
- cacheTtlSeconds?: number;
13
- defaultOrgId?: string;
14
- defaultFeatureId?: string;
15
- }
16
- interface User {
17
- id: string;
18
- email: string;
19
- name: string;
20
- [key: string]: any;
21
- }
22
- interface Organization {
23
- id: string;
24
- name: string;
25
- [key: string]: any;
26
- }
27
- interface Feature {
28
- id: string;
29
- name: string;
30
- org_id: string;
31
- [key: string]: any;
32
- }
33
- interface PromptListOptions {
34
- page?: number;
35
- pageSize?: number;
36
- name?: string;
37
- org_id?: string;
38
- feature_id?: string;
39
- }
40
- interface PromptOptions {
41
- version?: number | string;
42
- fallback?: string;
43
- cacheTtlSeconds?: number;
44
- resolve?: boolean;
45
- }
46
- interface PromptTemplate {
47
- id: string;
48
- name: string;
49
- content: string;
50
- version: number;
51
- variables?: string[];
52
- [key: string]: any;
53
- }
54
- interface ExecuteOptions {
55
- variables?: Record<string, any>;
56
- model?: string;
57
- version?: string | number;
58
- resolve?: boolean;
59
- }
60
- interface ExecuteResult {
61
- result: string;
62
- model: string;
63
- version: string | number;
64
- usage?: {
65
- prompt_tokens: number;
66
- completion_tokens: number;
67
- total_tokens: number;
68
- };
69
- }
70
- interface EvaluationOptions {
71
- name: string;
72
- models?: string[];
73
- judge?: string;
74
- version?: (string | number)[];
75
- variables?: Record<string, any>;
76
- evaluate_id?: string;
77
- temperature?: number;
78
- }
79
- interface EvaluationResult {
80
- result: string;
81
- winner?: string;
82
- answers: {
83
- model: string;
84
- answer: string;
85
- score?: number;
86
- }[];
87
- }
88
- interface AuthResponse {
89
- token: string;
90
- expiresAt?: string;
7
+ /**
8
+ * Base class for all Kloddy-related errors.
9
+ */
10
+ declare class KloddyError extends Error {
11
+ status?: number | undefined;
12
+ code?: string | undefined;
13
+ constructor(message: string, status?: number | undefined, code?: string | undefined);
14
+ }
15
+ /**
16
+ * Thrown when authentication fails.
17
+ */
18
+ declare class KloddyAuthError extends KloddyError {
19
+ constructor(message: string);
20
+ }
21
+ /**
22
+ * Thrown when a resource (e.g., prompt, organization) is not found.
23
+ */
24
+ declare class KloddyNotFoundError extends KloddyError {
25
+ constructor(message: string);
26
+ }
27
+ /**
28
+ * Thrown when the API rate limit is exceeded.
29
+ */
30
+ declare class KloddyRateLimitError extends KloddyError {
31
+ constructor(message: string);
91
32
  }
92
33
 
93
- declare class KloddyClient {
94
- private apiKey;
95
- private apiSecret;
96
- private host;
97
- defaultOrgId: string | null;
98
- defaultFeatureId: string | null;
99
- private token;
100
- private tokenExpires;
101
- constructor(apiKeyOrOptions: string | KloddyOptions, options?: KloddyOptions);
102
- login(): Promise<string>;
103
- getToken(): Promise<string>;
104
- request<T>(path: string, options?: RequestInit): Promise<T>;
34
+ /**
35
+ * The main Kloddy SDK class.
36
+ * Provides access to prompts, evaluations, and account management.
37
+ *
38
+ * @template TPromptNames Union of strings representing available prompt names for type safety.
39
+ */
40
+ declare class Kloddy<TPromptNames extends string = string> {
41
+ client: KloddyClient;
42
+ prompts: Prompts<TPromptNames>;
43
+ evaluations: Evaluations;
44
+ /**
45
+ * Initialize the Kloddy SDK.
46
+ * If no arguments are provided, it will attempt to use KLODDY_API_KEY and KLODDY_API_SECRET from process.env.
47
+ */
48
+ constructor(apiKeyOrOptions?: string | KloddyOptions, options?: KloddyOptions);
105
49
  /**
106
- * Get current user information.
50
+ * Get information about the current authenticated user/application.
107
51
  */
108
52
  whoAmI(): Promise<User>;
109
53
  /**
110
- * List organizations for the current user.
54
+ * List organizations accessible by the current credentials.
111
55
  */
112
56
  listOrganizations(): Promise<Organization[]>;
113
57
  /**
@@ -116,80 +60,4 @@ declare class KloddyClient {
116
60
  listFeatures(orgId?: string): Promise<Feature[]>;
117
61
  }
118
62
 
119
- declare class Prompts {
120
- private client;
121
- constructor(options: {
122
- posthog?: KloddyClient;
123
- } | KloddyOptions);
124
- /**
125
- * List prompts with filters.
126
- */
127
- list(options?: PromptListOptions): Promise<PromptTemplate[]>;
128
- /**
129
- * Fetch a prompt template.
130
- */
131
- get(name: string, options?: PromptOptions): Promise<PromptTemplate>;
132
- /**
133
- * Execute a prompt via the Kloddy API.
134
- */
135
- execute(name: string, options?: ExecuteOptions): Promise<ExecuteResult>;
136
- /**
137
- * Play: Direct execution for a single model/version.
138
- * Same as execute but follows specific naming/body requirements.
139
- */
140
- play(name: string, options?: Omit<ExecuteOptions, 'judge' | 'evaluate_id'>): Promise<ExecuteResult>;
141
- /**
142
- * Update: Download all prompts for the user/organization.
143
- */
144
- update(options?: PromptListOptions): Promise<PromptTemplate[]>;
145
- /**
146
- * Local compilation of a template string with variables.
147
- */
148
- compile(template: string | PromptTemplate, variables: Record<string, any>): string;
149
- }
150
-
151
- declare class Evaluations {
152
- private client;
153
- constructor(options: {
154
- posthog?: KloddyClient;
155
- } | KloddyOptions);
156
- /**
157
- * Run or retrieve an evaluation.
158
- */
159
- run(options: EvaluationOptions): Promise<EvaluationResult>;
160
- /**
161
- * Alias for run() as requested.
162
- */
163
- evaluate(options: EvaluationOptions): Promise<EvaluationResult>;
164
- /**
165
- * Legacy alias for run(name) as requested in the hook example.
166
- */
167
- get(name: string, variables?: Record<string, any>): Promise<EvaluationResult>;
168
- }
169
-
170
- interface KloddyProviderProps {
171
- children: React.ReactNode;
172
- client?: KloddyClient;
173
- options?: KloddyOptions;
174
- apiKey?: string;
175
- token?: string;
176
- }
177
- declare const KloddyProvider: React.FC<KloddyProviderProps>;
178
- declare const usePrompt: () => {
179
- getPrompt: (id: string, options?: {}) => Promise<PromptTemplate>;
180
- getAwnser: (id: string, options?: {}) => Promise<ExecuteResult>;
181
- getEvaluation: (id: string, variables?: {}) => Promise<EvaluationResult>;
182
- compile: (template: any, variables: any) => string;
183
- };
184
-
185
- declare class Kloddy {
186
- client: KloddyClient;
187
- prompts: Prompts;
188
- evaluations: Evaluations;
189
- constructor(apiKeyOrOptions: string | KloddyOptions, options?: KloddyOptions);
190
- whoAmI(): Promise<User>;
191
- listOrganizations(): Promise<Organization[]>;
192
- listFeatures(orgId?: string): Promise<Feature[]>;
193
- }
194
-
195
- export { type AuthResponse, type EvaluationOptions, type EvaluationResult, Evaluations, type ExecuteOptions, type ExecuteResult, type Feature, Kloddy, KloddyClient, type KloddyOptions, KloddyProvider, type KloddyProviderProps, type Organization, type PromptListOptions, type PromptOptions, type PromptTemplate, Prompts, type User, Kloddy as default, usePrompt };
63
+ export { Evaluations, Feature, Kloddy, KloddyAuthError, KloddyClient, KloddyError, KloddyNotFoundError, KloddyOptions, KloddyRateLimitError, Organization, Prompts, User, Kloddy as default };