@kloddy/kloddy-js 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.
- package/README.md +156 -0
- package/dist/client.d.ts +27 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +107 -0
- package/dist/client.js.map +1 -0
- package/dist/evaluations.d.ts +21 -0
- package/dist/evaluations.d.ts.map +1 -0
- package/dist/evaluations.js +38 -0
- package/dist/evaluations.js.map +1 -0
- package/dist/hooks/use-prompt.d.ts +18 -0
- package/dist/hooks/use-prompt.d.ts.map +1 -0
- package/dist/hooks/use-prompt.js +35 -0
- package/dist/hooks/use-prompt.js.map +1 -0
- package/dist/index.d.mts +195 -0
- package/dist/index.d.ts +195 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +327 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +285 -0
- package/dist/prompts.d.ts +34 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +108 -0
- package/dist/prompts.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import fetch from "cross-fetch";
|
|
3
|
+
var KloddyClient = class {
|
|
4
|
+
apiKey;
|
|
5
|
+
apiSecret;
|
|
6
|
+
host;
|
|
7
|
+
defaultOrgId = null;
|
|
8
|
+
defaultFeatureId = null;
|
|
9
|
+
token = null;
|
|
10
|
+
tokenExpires = null;
|
|
11
|
+
constructor(apiKeyOrOptions, options) {
|
|
12
|
+
if (typeof apiKeyOrOptions === "string") {
|
|
13
|
+
this.apiKey = apiKeyOrOptions;
|
|
14
|
+
this.apiSecret = options?.apiSecret || options?.personalApiKey || options?.secretKey || "";
|
|
15
|
+
this.token = options?.token || null;
|
|
16
|
+
this.host = options?.host || "https://api.kloddy.com";
|
|
17
|
+
this.defaultOrgId = options?.defaultOrgId || null;
|
|
18
|
+
this.defaultFeatureId = options?.defaultFeatureId || null;
|
|
19
|
+
} else {
|
|
20
|
+
this.apiKey = apiKeyOrOptions.apiKey || apiKeyOrOptions.projectApiKey || apiKeyOrOptions.applicationId || "";
|
|
21
|
+
this.apiSecret = apiKeyOrOptions.apiSecret || apiKeyOrOptions.personalApiKey || apiKeyOrOptions.secretKey || "";
|
|
22
|
+
this.token = apiKeyOrOptions.token || null;
|
|
23
|
+
this.host = apiKeyOrOptions.host || "https://api.kloddy.com";
|
|
24
|
+
this.defaultOrgId = apiKeyOrOptions.defaultOrgId || null;
|
|
25
|
+
this.defaultFeatureId = apiKeyOrOptions.defaultFeatureId || null;
|
|
26
|
+
}
|
|
27
|
+
if (!this.token && (!this.apiKey || !this.apiSecret)) {
|
|
28
|
+
console.warn("KloddyClient: token or credentials missing. API calls will fail.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async login() {
|
|
32
|
+
if (!this.apiKey || !this.apiSecret) {
|
|
33
|
+
throw new Error("KloddyClient: Cannot login without apiKey and apiSecret.");
|
|
34
|
+
}
|
|
35
|
+
const response = await fetch(`${this.host}/api/login`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: { "Content-Type": "application/json" },
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
applicationId: this.apiKey,
|
|
40
|
+
secretKey: this.apiSecret
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
const error = await response.text();
|
|
45
|
+
throw new Error(`Kloddy Auth failed: ${response.status} ${error}`);
|
|
46
|
+
}
|
|
47
|
+
const data = await response.json();
|
|
48
|
+
this.token = data.token;
|
|
49
|
+
this.tokenExpires = Date.now() + (data.expiresAt ? new Date(data.expiresAt).getTime() - Date.now() : 36e5);
|
|
50
|
+
return this.token;
|
|
51
|
+
}
|
|
52
|
+
async getToken() {
|
|
53
|
+
if (this.token && !this.apiSecret) {
|
|
54
|
+
return this.token;
|
|
55
|
+
}
|
|
56
|
+
if (!this.token || this.tokenExpires && Date.now() >= this.tokenExpires - 6e4) {
|
|
57
|
+
return this.login();
|
|
58
|
+
}
|
|
59
|
+
return this.token;
|
|
60
|
+
}
|
|
61
|
+
async request(path, options = {}) {
|
|
62
|
+
const token = await this.getToken();
|
|
63
|
+
const url = path.startsWith("http") ? path : `${this.host}${path}`;
|
|
64
|
+
const response = await fetch(url, {
|
|
65
|
+
...options,
|
|
66
|
+
headers: {
|
|
67
|
+
...options.headers,
|
|
68
|
+
Authorization: `Bearer ${token}`,
|
|
69
|
+
"Content-Type": "application/json"
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
const error = await response.text();
|
|
74
|
+
throw new Error(`Kloddy API error: ${response.status} ${error}`);
|
|
75
|
+
}
|
|
76
|
+
return await response.json();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get current user information.
|
|
80
|
+
*/
|
|
81
|
+
async whoAmI() {
|
|
82
|
+
return this.request("/api/whoiam");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* List organizations for the current user.
|
|
86
|
+
*/
|
|
87
|
+
async listOrganizations() {
|
|
88
|
+
return this.request("/api/organizations");
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* List features, optionally filtered by organization.
|
|
92
|
+
*/
|
|
93
|
+
async listFeatures(orgId) {
|
|
94
|
+
const path = orgId ? `/api/features?org_id=${orgId}` : "/api/features";
|
|
95
|
+
return this.request(path);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/prompts.ts
|
|
100
|
+
var Prompts = class {
|
|
101
|
+
client;
|
|
102
|
+
constructor(options) {
|
|
103
|
+
if ("posthog" in options && options.posthog) {
|
|
104
|
+
this.client = options.posthog;
|
|
105
|
+
} else {
|
|
106
|
+
this.client = new KloddyClient(options);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* List prompts with filters.
|
|
111
|
+
*/
|
|
112
|
+
async list(options = {}) {
|
|
113
|
+
const params = new URLSearchParams();
|
|
114
|
+
if (options.page) params.append("page", options.page.toString());
|
|
115
|
+
if (options.pageSize) params.append("pageSize", options.pageSize.toString());
|
|
116
|
+
if (options.name) params.append("name", options.name);
|
|
117
|
+
const orgId = options.org_id || this.client.defaultOrgId;
|
|
118
|
+
if (orgId) params.append("org_id", orgId);
|
|
119
|
+
const featureId = options.feature_id || this.client.defaultFeatureId;
|
|
120
|
+
if (featureId) params.append("feature_id", featureId);
|
|
121
|
+
const queryString = params.toString() ? `?${params.toString()}` : "";
|
|
122
|
+
return this.client.request(`/api/prompts${queryString}`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Fetch a prompt template.
|
|
126
|
+
*/
|
|
127
|
+
async get(name, options = {}) {
|
|
128
|
+
const params = new URLSearchParams();
|
|
129
|
+
if (options.version) params.append("version", options.version.toString());
|
|
130
|
+
const resolve = options.resolve !== void 0 ? options.resolve : true;
|
|
131
|
+
params.append("resolve", resolve.toString());
|
|
132
|
+
const queryString = params.toString() ? `?${params.toString()}` : "";
|
|
133
|
+
try {
|
|
134
|
+
return await this.client.request(`/api/prompt/${name}${queryString}`, {
|
|
135
|
+
method: "GET"
|
|
136
|
+
});
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (options.fallback) {
|
|
139
|
+
return {
|
|
140
|
+
id: "fallback",
|
|
141
|
+
name,
|
|
142
|
+
content: options.fallback,
|
|
143
|
+
version: 0
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Execute a prompt via the Kloddy API.
|
|
151
|
+
*/
|
|
152
|
+
async execute(name, options = {}) {
|
|
153
|
+
return this.client.request(`/api/prompt/${name}`, {
|
|
154
|
+
method: "POST",
|
|
155
|
+
body: JSON.stringify({
|
|
156
|
+
...options,
|
|
157
|
+
resolve: options.resolve !== void 0 ? options.resolve : true
|
|
158
|
+
})
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Play: Direct execution for a single model/version.
|
|
163
|
+
* Same as execute but follows specific naming/body requirements.
|
|
164
|
+
*/
|
|
165
|
+
async play(name, options = {}) {
|
|
166
|
+
return this.client.request("/api/play", {
|
|
167
|
+
method: "POST",
|
|
168
|
+
body: JSON.stringify({
|
|
169
|
+
name,
|
|
170
|
+
...options,
|
|
171
|
+
resolve: options.resolve !== void 0 ? options.resolve : true
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Update: Download all prompts for the user/organization.
|
|
177
|
+
*/
|
|
178
|
+
async update(options = {}) {
|
|
179
|
+
return this.list(options);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Local compilation of a template string with variables.
|
|
183
|
+
*/
|
|
184
|
+
compile(template, variables) {
|
|
185
|
+
let content = typeof template === "string" ? template : template.content;
|
|
186
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
187
|
+
const regex = new RegExp(`{{${key}}}|{${key}}`, "g");
|
|
188
|
+
content = content.replace(regex, String(value));
|
|
189
|
+
}
|
|
190
|
+
return content;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// src/evaluations.ts
|
|
195
|
+
var Evaluations = class {
|
|
196
|
+
client;
|
|
197
|
+
constructor(options) {
|
|
198
|
+
if ("posthog" in options && options.posthog) {
|
|
199
|
+
this.client = options.posthog;
|
|
200
|
+
} else {
|
|
201
|
+
this.client = new KloddyClient(options);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Run or retrieve an evaluation.
|
|
206
|
+
*/
|
|
207
|
+
async run(options) {
|
|
208
|
+
return this.client.request("/api/evaluate", {
|
|
209
|
+
method: "POST",
|
|
210
|
+
body: JSON.stringify(options)
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Alias for run() as requested.
|
|
215
|
+
*/
|
|
216
|
+
async evaluate(options) {
|
|
217
|
+
return this.run(options);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Legacy alias for run(name) as requested in the hook example.
|
|
221
|
+
*/
|
|
222
|
+
async get(name, variables = {}) {
|
|
223
|
+
return this.run({ name, variables });
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// src/hooks/use-prompt.tsx
|
|
228
|
+
import { createContext, useContext, useMemo } from "react";
|
|
229
|
+
import { jsx } from "react/jsx-runtime";
|
|
230
|
+
var KloddyContext = createContext(null);
|
|
231
|
+
var KloddyProvider = ({ children, client, options, apiKey, token }) => {
|
|
232
|
+
const value = useMemo(() => {
|
|
233
|
+
const activeClient = client || new KloddyClient({ ...options, apiKey, token });
|
|
234
|
+
return {
|
|
235
|
+
prompts: new Prompts({ posthog: activeClient }),
|
|
236
|
+
evaluations: new Evaluations({ posthog: activeClient })
|
|
237
|
+
};
|
|
238
|
+
}, [client, options, token]);
|
|
239
|
+
return /* @__PURE__ */ jsx(KloddyContext.Provider, { value, children });
|
|
240
|
+
};
|
|
241
|
+
var usePrompt = () => {
|
|
242
|
+
const context = useContext(KloddyContext);
|
|
243
|
+
if (!context) {
|
|
244
|
+
throw new Error("usePrompt must be used within a KloddyProvider");
|
|
245
|
+
}
|
|
246
|
+
const { prompts, evaluations } = context;
|
|
247
|
+
return {
|
|
248
|
+
getPrompt: (id, options = {}) => prompts.get(id, options),
|
|
249
|
+
getAwnser: (id, options = {}) => prompts.execute(id, options),
|
|
250
|
+
// Use user's spelling "getAwnser"
|
|
251
|
+
getEvaluation: (id, variables = {}) => evaluations.get(id, variables),
|
|
252
|
+
compile: (template, variables) => prompts.compile(template, variables)
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// src/index.ts
|
|
257
|
+
var Kloddy = class {
|
|
258
|
+
client;
|
|
259
|
+
prompts;
|
|
260
|
+
evaluations;
|
|
261
|
+
constructor(apiKeyOrOptions, options) {
|
|
262
|
+
this.client = new KloddyClient(apiKeyOrOptions, options);
|
|
263
|
+
this.prompts = new Prompts({ posthog: this.client });
|
|
264
|
+
this.evaluations = new Evaluations({ posthog: this.client });
|
|
265
|
+
}
|
|
266
|
+
async whoAmI() {
|
|
267
|
+
return this.client.whoAmI();
|
|
268
|
+
}
|
|
269
|
+
async listOrganizations() {
|
|
270
|
+
return this.client.listOrganizations();
|
|
271
|
+
}
|
|
272
|
+
async listFeatures(orgId) {
|
|
273
|
+
return this.client.listFeatures(orgId);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
var index_default = Kloddy;
|
|
277
|
+
export {
|
|
278
|
+
Evaluations,
|
|
279
|
+
Kloddy,
|
|
280
|
+
KloddyClient,
|
|
281
|
+
KloddyProvider,
|
|
282
|
+
Prompts,
|
|
283
|
+
index_default as default,
|
|
284
|
+
usePrompt
|
|
285
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { KloddyClient } from './client';
|
|
2
|
+
import { PromptOptions, PromptTemplate, ExecuteOptions, ExecuteResult, KloddyOptions, PromptListOptions } from './types';
|
|
3
|
+
export declare class Prompts {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(options: {
|
|
6
|
+
posthog?: KloddyClient;
|
|
7
|
+
} | KloddyOptions);
|
|
8
|
+
/**
|
|
9
|
+
* List prompts with filters.
|
|
10
|
+
*/
|
|
11
|
+
list(options?: PromptListOptions): Promise<PromptTemplate[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Fetch a prompt template.
|
|
14
|
+
*/
|
|
15
|
+
get(name: string, options?: PromptOptions): Promise<PromptTemplate>;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a prompt via the Kloddy API.
|
|
18
|
+
*/
|
|
19
|
+
execute(name: string, options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Play: Direct execution for a single model/version.
|
|
22
|
+
* Same as execute but follows specific naming/body requirements.
|
|
23
|
+
*/
|
|
24
|
+
play(name: string, options?: Omit<ExecuteOptions, 'judge' | 'evaluate_id'>): Promise<ExecuteResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Update: Download all prompts for the user/organization.
|
|
27
|
+
*/
|
|
28
|
+
update(options?: PromptListOptions): Promise<PromptTemplate[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Local compilation of a template string with variables.
|
|
31
|
+
*/
|
|
32
|
+
compile(template: string | PromptTemplate, variables: Record<string, any>): string;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEzH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAe;gBAEjB,OAAO,EAAE;QAAE,OAAO,CAAC,EAAE,YAAY,CAAA;KAAE,GAAG,aAAa;IAQ/D;;OAEG;IACG,IAAI,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAgBtE;;OAEG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IA2B7E;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAUjF;;;OAGG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,aAAa,CAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAW7G;;OAEG;IACG,MAAM,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAIxE;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;CAUnF"}
|
package/dist/prompts.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Prompts = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
class Prompts {
|
|
6
|
+
client;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if ('posthog' in options && options.posthog) {
|
|
9
|
+
this.client = options.posthog;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
this.client = new client_1.KloddyClient(options);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* List prompts with filters.
|
|
17
|
+
*/
|
|
18
|
+
async list(options = {}) {
|
|
19
|
+
const params = new URLSearchParams();
|
|
20
|
+
if (options.page)
|
|
21
|
+
params.append('page', options.page.toString());
|
|
22
|
+
if (options.pageSize)
|
|
23
|
+
params.append('pageSize', options.pageSize.toString());
|
|
24
|
+
if (options.name)
|
|
25
|
+
params.append('name', options.name);
|
|
26
|
+
const orgId = options.org_id || this.client.defaultOrgId;
|
|
27
|
+
if (orgId)
|
|
28
|
+
params.append('org_id', orgId);
|
|
29
|
+
const featureId = options.feature_id || this.client.defaultFeatureId;
|
|
30
|
+
if (featureId)
|
|
31
|
+
params.append('feature_id', featureId);
|
|
32
|
+
const queryString = params.toString() ? `?${params.toString()}` : '';
|
|
33
|
+
return this.client.request(`/api/prompts${queryString}`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fetch a prompt template.
|
|
37
|
+
*/
|
|
38
|
+
async get(name, options = {}) {
|
|
39
|
+
const params = new URLSearchParams();
|
|
40
|
+
if (options.version)
|
|
41
|
+
params.append('version', options.version.toString());
|
|
42
|
+
// Default resolve to true if not specified
|
|
43
|
+
const resolve = options.resolve !== undefined ? options.resolve : true;
|
|
44
|
+
params.append('resolve', resolve.toString());
|
|
45
|
+
const queryString = params.toString() ? `?${params.toString()}` : '';
|
|
46
|
+
try {
|
|
47
|
+
return await this.client.request(`/api/prompt/${name}${queryString}`, {
|
|
48
|
+
method: 'GET',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (options.fallback) {
|
|
53
|
+
return {
|
|
54
|
+
id: 'fallback',
|
|
55
|
+
name,
|
|
56
|
+
content: options.fallback,
|
|
57
|
+
version: 0,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Execute a prompt via the Kloddy API.
|
|
65
|
+
*/
|
|
66
|
+
async execute(name, options = {}) {
|
|
67
|
+
return this.client.request(`/api/prompt/${name}`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
body: JSON.stringify({
|
|
70
|
+
...options,
|
|
71
|
+
resolve: options.resolve !== undefined ? options.resolve : true,
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Play: Direct execution for a single model/version.
|
|
77
|
+
* Same as execute but follows specific naming/body requirements.
|
|
78
|
+
*/
|
|
79
|
+
async play(name, options = {}) {
|
|
80
|
+
return this.client.request('/api/play', {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
name,
|
|
84
|
+
...options,
|
|
85
|
+
resolve: options.resolve !== undefined ? options.resolve : true,
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Update: Download all prompts for the user/organization.
|
|
91
|
+
*/
|
|
92
|
+
async update(options = {}) {
|
|
93
|
+
return this.list(options);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Local compilation of a template string with variables.
|
|
97
|
+
*/
|
|
98
|
+
compile(template, variables) {
|
|
99
|
+
let content = typeof template === 'string' ? template : template.content;
|
|
100
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
101
|
+
const regex = new RegExp(`{{${key}}}|{${key}}`, 'g');
|
|
102
|
+
content = content.replace(regex, String(value));
|
|
103
|
+
}
|
|
104
|
+
return content;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.Prompts = Prompts;
|
|
108
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AAGxC,MAAa,OAAO;IACV,MAAM,CAAe;IAE7B,YAAY,OAAmD;QAC7D,IAAI,SAAS,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,OAAuB,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAY,CAAC,OAAwB,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,UAA6B,EAAE;QACxC,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,OAAO,CAAC,IAAI;YAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjE,IAAI,OAAO,CAAC,QAAQ;YAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7E,IAAI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AAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,QAAiC,EAAE,SAA8B;QACvE,IAAI,OAAO,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;QAEzE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACrD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,GAAG,OAAO,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;YACrD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AA5GD,0BA4GC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export interface KloddyOptions {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
apiSecret?: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
personalApiKey?: string;
|
|
6
|
+
projectApiKey?: string;
|
|
7
|
+
applicationId?: string;
|
|
8
|
+
secretKey?: string;
|
|
9
|
+
host?: string;
|
|
10
|
+
cacheTtlSeconds?: number;
|
|
11
|
+
defaultOrgId?: string;
|
|
12
|
+
defaultFeatureId?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface User {
|
|
15
|
+
id: string;
|
|
16
|
+
email: string;
|
|
17
|
+
name: string;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
export interface Organization {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
export interface Feature {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
org_id: string;
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
export interface PromptListOptions {
|
|
32
|
+
page?: number;
|
|
33
|
+
pageSize?: number;
|
|
34
|
+
name?: string;
|
|
35
|
+
org_id?: string;
|
|
36
|
+
feature_id?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface PromptOptions {
|
|
39
|
+
version?: number | string;
|
|
40
|
+
fallback?: string;
|
|
41
|
+
cacheTtlSeconds?: number;
|
|
42
|
+
resolve?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface PromptTemplate {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
content: string;
|
|
48
|
+
version: number;
|
|
49
|
+
variables?: string[];
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}
|
|
52
|
+
export interface ExecuteOptions {
|
|
53
|
+
variables?: Record<string, any>;
|
|
54
|
+
model?: string;
|
|
55
|
+
version?: string | number;
|
|
56
|
+
resolve?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface ExecuteResult {
|
|
59
|
+
result: string;
|
|
60
|
+
model: string;
|
|
61
|
+
version: string | number;
|
|
62
|
+
usage?: {
|
|
63
|
+
prompt_tokens: number;
|
|
64
|
+
completion_tokens: number;
|
|
65
|
+
total_tokens: number;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface EvaluationOptions {
|
|
69
|
+
name: string;
|
|
70
|
+
models?: string[];
|
|
71
|
+
judge?: string;
|
|
72
|
+
version?: (string | number)[];
|
|
73
|
+
variables?: Record<string, any>;
|
|
74
|
+
evaluate_id?: string;
|
|
75
|
+
temperature?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface EvaluationResult {
|
|
78
|
+
result: string;
|
|
79
|
+
winner?: string;
|
|
80
|
+
answers: {
|
|
81
|
+
model: string;
|
|
82
|
+
answer: string;
|
|
83
|
+
score?: number;
|
|
84
|
+
}[];
|
|
85
|
+
}
|
|
86
|
+
export interface AuthResponse {
|
|
87
|
+
token: string;
|
|
88
|
+
expiresAt?: string;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,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CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,EAAE,CAAC;CACL;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kloddy/kloddy-js",
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/kloddy-com/kloddy-js.git"
|
|
6
|
+
},
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"description": "Kloddy JS SDK",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.mjs",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
17
|
+
"dev": "tsup src/index.ts --format cjs,esm --watch --dts",
|
|
18
|
+
"lint": "tsc",
|
|
19
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"kloddy",
|
|
23
|
+
"ai",
|
|
24
|
+
"prompts",
|
|
25
|
+
"llm",
|
|
26
|
+
"analytics"
|
|
27
|
+
],
|
|
28
|
+
"author": "Kloddy",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"cross-fetch": "^4.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^20.0.0",
|
|
38
|
+
"@types/react": "^18.0.0",
|
|
39
|
+
"react": "^18.0.0",
|
|
40
|
+
"tsup": "^8.0.0",
|
|
41
|
+
"typescript": "^5.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|