@cobbl-ai/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.
- package/README.md +516 -0
- package/dist/index.d.mts +348 -0
- package/dist/index.d.ts +348 -0
- package/dist/index.js +236 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +233 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +73 -0
- package/src/__tests__/client.test.ts +650 -0
- package/src/__tests__/errors.test.ts +100 -0
- package/src/__tests__/integration.test.ts +346 -0
- package/src/client.ts +257 -0
- package/src/errors.ts +70 -0
- package/src/index.ts +43 -0
- package/src/types.ts +94 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const ProviderSchema: z.ZodEnum<{
|
|
6
|
+
openai: "openai";
|
|
7
|
+
anthropic: "anthropic";
|
|
8
|
+
google: "google";
|
|
9
|
+
}>;
|
|
10
|
+
export type Provider = z.infer<typeof ProviderSchema>;
|
|
11
|
+
declare const VariableConfigSchema: z.ZodObject<{
|
|
12
|
+
key: z.ZodString;
|
|
13
|
+
type: z.ZodEnum<{
|
|
14
|
+
string: "string";
|
|
15
|
+
number: "number";
|
|
16
|
+
boolean: "boolean";
|
|
17
|
+
object: "object";
|
|
18
|
+
list: "list";
|
|
19
|
+
}>;
|
|
20
|
+
required: z.ZodBoolean;
|
|
21
|
+
description: z.ZodOptional<z.ZodString>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export type VariableConfig = z.infer<typeof VariableConfigSchema>;
|
|
24
|
+
declare const PromptInputSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [
|
|
25
|
+
z.ZodString,
|
|
26
|
+
z.ZodNumber,
|
|
27
|
+
z.ZodBoolean,
|
|
28
|
+
z.ZodArray<z.ZodAny>,
|
|
29
|
+
z.ZodRecord<z.ZodString, z.ZodAny>
|
|
30
|
+
]>>;
|
|
31
|
+
export type PromptInput = z.infer<typeof PromptInputSchema>;
|
|
32
|
+
declare const PromptVersionClientSchema: z.ZodDiscriminatedUnion<[
|
|
33
|
+
z.ZodObject<{
|
|
34
|
+
tenantId: z.ZodString;
|
|
35
|
+
environmentId: z.ZodString;
|
|
36
|
+
promptId: z.ZodString;
|
|
37
|
+
slug: z.ZodString;
|
|
38
|
+
versionNumber: z.ZodNumber;
|
|
39
|
+
template: z.ZodString;
|
|
40
|
+
variables: z.ZodArray<z.ZodObject<{
|
|
41
|
+
key: z.ZodString;
|
|
42
|
+
type: z.ZodEnum<{
|
|
43
|
+
string: "string";
|
|
44
|
+
number: "number";
|
|
45
|
+
boolean: "boolean";
|
|
46
|
+
object: "object";
|
|
47
|
+
list: "list";
|
|
48
|
+
}>;
|
|
49
|
+
required: z.ZodBoolean;
|
|
50
|
+
description: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
provider: z.ZodEnum<{
|
|
53
|
+
openai: "openai";
|
|
54
|
+
anthropic: "anthropic";
|
|
55
|
+
google: "google";
|
|
56
|
+
}>;
|
|
57
|
+
model: z.ZodString;
|
|
58
|
+
status: z.ZodEnum<{
|
|
59
|
+
draft: "draft";
|
|
60
|
+
active: "active";
|
|
61
|
+
inactive: "inactive";
|
|
62
|
+
}>;
|
|
63
|
+
parentVersionId: z.ZodOptional<z.ZodString>;
|
|
64
|
+
authorId: z.ZodString;
|
|
65
|
+
authorName: z.ZodString;
|
|
66
|
+
source: z.ZodLiteral<"manual">;
|
|
67
|
+
publishedAt: z.ZodOptional<z.ZodDate>;
|
|
68
|
+
id: z.ZodString;
|
|
69
|
+
schemaVersion: z.ZodNumber;
|
|
70
|
+
createdAt: z.ZodDate;
|
|
71
|
+
updatedAt: z.ZodDate;
|
|
72
|
+
}, z.core.$strip>,
|
|
73
|
+
z.ZodObject<{
|
|
74
|
+
tenantId: z.ZodString;
|
|
75
|
+
environmentId: z.ZodString;
|
|
76
|
+
promptId: z.ZodString;
|
|
77
|
+
slug: z.ZodString;
|
|
78
|
+
versionNumber: z.ZodNumber;
|
|
79
|
+
template: z.ZodString;
|
|
80
|
+
variables: z.ZodArray<z.ZodObject<{
|
|
81
|
+
key: z.ZodString;
|
|
82
|
+
type: z.ZodEnum<{
|
|
83
|
+
string: "string";
|
|
84
|
+
number: "number";
|
|
85
|
+
boolean: "boolean";
|
|
86
|
+
object: "object";
|
|
87
|
+
list: "list";
|
|
88
|
+
}>;
|
|
89
|
+
required: z.ZodBoolean;
|
|
90
|
+
description: z.ZodOptional<z.ZodString>;
|
|
91
|
+
}, z.core.$strip>>;
|
|
92
|
+
provider: z.ZodEnum<{
|
|
93
|
+
openai: "openai";
|
|
94
|
+
anthropic: "anthropic";
|
|
95
|
+
google: "google";
|
|
96
|
+
}>;
|
|
97
|
+
model: z.ZodString;
|
|
98
|
+
status: z.ZodEnum<{
|
|
99
|
+
draft: "draft";
|
|
100
|
+
active: "active";
|
|
101
|
+
inactive: "inactive";
|
|
102
|
+
}>;
|
|
103
|
+
parentVersionId: z.ZodOptional<z.ZodString>;
|
|
104
|
+
feedbackId: z.ZodString;
|
|
105
|
+
source: z.ZodLiteral<"feedback_llm_suggestion">;
|
|
106
|
+
publishedAt: z.ZodOptional<z.ZodDate>;
|
|
107
|
+
id: z.ZodString;
|
|
108
|
+
schemaVersion: z.ZodNumber;
|
|
109
|
+
createdAt: z.ZodDate;
|
|
110
|
+
updatedAt: z.ZodDate;
|
|
111
|
+
}, z.core.$strip>,
|
|
112
|
+
z.ZodObject<{
|
|
113
|
+
tenantId: z.ZodString;
|
|
114
|
+
environmentId: z.ZodString;
|
|
115
|
+
promptId: z.ZodString;
|
|
116
|
+
slug: z.ZodString;
|
|
117
|
+
versionNumber: z.ZodNumber;
|
|
118
|
+
template: z.ZodString;
|
|
119
|
+
variables: z.ZodArray<z.ZodObject<{
|
|
120
|
+
key: z.ZodString;
|
|
121
|
+
type: z.ZodEnum<{
|
|
122
|
+
string: "string";
|
|
123
|
+
number: "number";
|
|
124
|
+
boolean: "boolean";
|
|
125
|
+
object: "object";
|
|
126
|
+
list: "list";
|
|
127
|
+
}>;
|
|
128
|
+
required: z.ZodBoolean;
|
|
129
|
+
description: z.ZodOptional<z.ZodString>;
|
|
130
|
+
}, z.core.$strip>>;
|
|
131
|
+
provider: z.ZodEnum<{
|
|
132
|
+
openai: "openai";
|
|
133
|
+
anthropic: "anthropic";
|
|
134
|
+
google: "google";
|
|
135
|
+
}>;
|
|
136
|
+
model: z.ZodString;
|
|
137
|
+
status: z.ZodEnum<{
|
|
138
|
+
draft: "draft";
|
|
139
|
+
active: "active";
|
|
140
|
+
inactive: "inactive";
|
|
141
|
+
}>;
|
|
142
|
+
parentVersionId: z.ZodOptional<z.ZodString>;
|
|
143
|
+
authorId: z.ZodString;
|
|
144
|
+
authorName: z.ZodString;
|
|
145
|
+
feedbackId: z.ZodString;
|
|
146
|
+
source: z.ZodLiteral<"feedback_llm_override">;
|
|
147
|
+
publishedAt: z.ZodOptional<z.ZodDate>;
|
|
148
|
+
id: z.ZodString;
|
|
149
|
+
schemaVersion: z.ZodNumber;
|
|
150
|
+
createdAt: z.ZodDate;
|
|
151
|
+
updatedAt: z.ZodDate;
|
|
152
|
+
}, z.core.$strip>
|
|
153
|
+
], "source">;
|
|
154
|
+
export type PromptVersionClient = z.infer<typeof PromptVersionClientSchema>;
|
|
155
|
+
declare const helpfulSchema: z.ZodEnum<{
|
|
156
|
+
helpful: "helpful";
|
|
157
|
+
not_helpful: "not_helpful";
|
|
158
|
+
}>;
|
|
159
|
+
export type Helpful = z.infer<typeof helpfulSchema>;
|
|
160
|
+
declare const tokenUsageSchema: z.ZodObject<{
|
|
161
|
+
inputTokens: z.ZodNumber;
|
|
162
|
+
outputTokens: z.ZodNumber;
|
|
163
|
+
totalTokens: z.ZodNumber;
|
|
164
|
+
}, z.core.$strip>;
|
|
165
|
+
export type TokenUsage = z.infer<typeof tokenUsageSchema>;
|
|
166
|
+
/**
|
|
167
|
+
* Configuration options for the CobblClient
|
|
168
|
+
*/
|
|
169
|
+
export interface CobblConfig {
|
|
170
|
+
/**
|
|
171
|
+
* Your Cobbl API key
|
|
172
|
+
* @required
|
|
173
|
+
*/
|
|
174
|
+
apiKey: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Response from running a prompt
|
|
178
|
+
*/
|
|
179
|
+
export interface RunPromptResponse {
|
|
180
|
+
/**
|
|
181
|
+
* Unique ID for this prompt run - use this to link feedback
|
|
182
|
+
*/
|
|
183
|
+
runId: string;
|
|
184
|
+
/**
|
|
185
|
+
* The AI-generated output
|
|
186
|
+
*/
|
|
187
|
+
output: string;
|
|
188
|
+
/**
|
|
189
|
+
* Token usage statistics
|
|
190
|
+
*/
|
|
191
|
+
tokenUsage: TokenUsage;
|
|
192
|
+
/**
|
|
193
|
+
* The rendered prompt that was sent to the LLM (with variables substituted)
|
|
194
|
+
*/
|
|
195
|
+
renderedPrompt: string;
|
|
196
|
+
/**
|
|
197
|
+
* Information about the prompt version that was used
|
|
198
|
+
*/
|
|
199
|
+
promptVersion: PromptVersionClient;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Feedback submission data
|
|
203
|
+
*/
|
|
204
|
+
export interface FeedbackSubmission {
|
|
205
|
+
/**
|
|
206
|
+
* The run ID from a previous runPrompt call
|
|
207
|
+
* @required
|
|
208
|
+
*/
|
|
209
|
+
runId: string;
|
|
210
|
+
/**
|
|
211
|
+
* Whether the output was helpful
|
|
212
|
+
* @required
|
|
213
|
+
*/
|
|
214
|
+
helpful: Helpful;
|
|
215
|
+
/**
|
|
216
|
+
* Detailed feedback message from the user
|
|
217
|
+
* @required
|
|
218
|
+
*/
|
|
219
|
+
userFeedback: string;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Response from submitting feedback
|
|
223
|
+
*/
|
|
224
|
+
export interface SubmitFeedbackResponse {
|
|
225
|
+
/**
|
|
226
|
+
* Unique ID for the created feedback item
|
|
227
|
+
*/
|
|
228
|
+
feedbackId: string;
|
|
229
|
+
/**
|
|
230
|
+
* Success message
|
|
231
|
+
*/
|
|
232
|
+
message: string;
|
|
233
|
+
}
|
|
234
|
+
export declare class CobblClient {
|
|
235
|
+
private readonly apiKey;
|
|
236
|
+
/**
|
|
237
|
+
* Initialize the Cobbl SDK client
|
|
238
|
+
*
|
|
239
|
+
* @param config - Configuration object
|
|
240
|
+
* @param config.apiKey - Your Cobbl API key
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const client = new CobblClient({
|
|
245
|
+
* apiKey: process.env.COBBL_API_KEY
|
|
246
|
+
* })
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
constructor(config: CobblConfig);
|
|
250
|
+
/**
|
|
251
|
+
* Execute a prompt with the given input variables
|
|
252
|
+
*
|
|
253
|
+
* @param promptSlug - The unique slug identifier for the prompt
|
|
254
|
+
* @param input - Input variables to populate the prompt template
|
|
255
|
+
* @returns Promise containing the prompt execution results
|
|
256
|
+
*
|
|
257
|
+
* @throws {CobblError} When the request fails or API returns an error
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* const result = await client.runPrompt('sales_summary', {
|
|
262
|
+
* topic: 'Q4 Results',
|
|
263
|
+
* tone: 'friendly',
|
|
264
|
+
* audience: 'investors'
|
|
265
|
+
* })
|
|
266
|
+
*
|
|
267
|
+
* console.log(result.output) // AI-generated response
|
|
268
|
+
* console.log(result.runId) // Save this to link feedback later
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
runPrompt(promptSlug: string, input: PromptInput): Promise<RunPromptResponse>;
|
|
272
|
+
/**
|
|
273
|
+
* Submit user feedback for a prompt run
|
|
274
|
+
*
|
|
275
|
+
* @param feedback - Feedback submission data
|
|
276
|
+
* @param feedback.runId - The run ID from a previous runPrompt call
|
|
277
|
+
* @param feedback.helpful - Whether the output was helpful ('helpful' or 'not_helpful')
|
|
278
|
+
* @param feedback.userFeedback - Detailed feedback message from the user
|
|
279
|
+
* @returns Promise containing the created feedback ID
|
|
280
|
+
*
|
|
281
|
+
* @throws {CobblError} When the request fails or API returns an error
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* await client.submitFeedback({
|
|
286
|
+
* runId: result.runId,
|
|
287
|
+
* helpful: 'not_helpful',
|
|
288
|
+
* userFeedback: 'The response was too formal and lengthy'
|
|
289
|
+
* })
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
submitFeedback(feedback: FeedbackSubmission): Promise<SubmitFeedbackResponse>;
|
|
293
|
+
/**
|
|
294
|
+
* Make an HTTP request to the Cobbl API
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
private makeRequest;
|
|
298
|
+
/**
|
|
299
|
+
* Handle error responses from the API
|
|
300
|
+
* @private
|
|
301
|
+
*/
|
|
302
|
+
private handleErrorResponse;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Error types that can be thrown by the Cobbl SDK
|
|
306
|
+
*/
|
|
307
|
+
export type CobblErrorCode = "INVALID_CONFIG" | "INVALID_REQUEST" | "UNAUTHORIZED" | "NOT_FOUND" | "RATE_LIMIT_EXCEEDED" | "SERVER_ERROR" | "NETWORK_ERROR" | "API_ERROR";
|
|
308
|
+
/**
|
|
309
|
+
* Custom error class for Cobbl SDK errors
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* try {
|
|
314
|
+
* await client.runPrompt('my-prompt', { topic: 'test' })
|
|
315
|
+
* } catch (error) {
|
|
316
|
+
* if (error instanceof CobblError) {
|
|
317
|
+
* console.error(`Error [${error.code}]: ${error.message}`)
|
|
318
|
+
* console.error('Details:', error.details)
|
|
319
|
+
* }
|
|
320
|
+
* }
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
export declare class CobblError extends Error {
|
|
324
|
+
/**
|
|
325
|
+
* Error code indicating the type of error
|
|
326
|
+
*/
|
|
327
|
+
readonly code: CobblErrorCode;
|
|
328
|
+
/**
|
|
329
|
+
* Additional details about the error (e.g., missing variables, validation issues)
|
|
330
|
+
*/
|
|
331
|
+
readonly details?: unknown;
|
|
332
|
+
constructor(message: string, code: CobblErrorCode, details?: unknown);
|
|
333
|
+
/**
|
|
334
|
+
* Check if an error is a CobblError
|
|
335
|
+
*/
|
|
336
|
+
static isCobblError(error: unknown): error is CobblError;
|
|
337
|
+
/**
|
|
338
|
+
* Convert error to JSON-serializable object
|
|
339
|
+
*/
|
|
340
|
+
toJSON(): {
|
|
341
|
+
name: string;
|
|
342
|
+
message: string;
|
|
343
|
+
code: CobblErrorCode;
|
|
344
|
+
details: unknown;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const ProviderSchema: z.ZodEnum<{
|
|
6
|
+
openai: "openai";
|
|
7
|
+
anthropic: "anthropic";
|
|
8
|
+
google: "google";
|
|
9
|
+
}>;
|
|
10
|
+
export type Provider = z.infer<typeof ProviderSchema>;
|
|
11
|
+
declare const VariableConfigSchema: z.ZodObject<{
|
|
12
|
+
key: z.ZodString;
|
|
13
|
+
type: z.ZodEnum<{
|
|
14
|
+
string: "string";
|
|
15
|
+
number: "number";
|
|
16
|
+
boolean: "boolean";
|
|
17
|
+
object: "object";
|
|
18
|
+
list: "list";
|
|
19
|
+
}>;
|
|
20
|
+
required: z.ZodBoolean;
|
|
21
|
+
description: z.ZodOptional<z.ZodString>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export type VariableConfig = z.infer<typeof VariableConfigSchema>;
|
|
24
|
+
declare const PromptInputSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [
|
|
25
|
+
z.ZodString,
|
|
26
|
+
z.ZodNumber,
|
|
27
|
+
z.ZodBoolean,
|
|
28
|
+
z.ZodArray<z.ZodAny>,
|
|
29
|
+
z.ZodRecord<z.ZodString, z.ZodAny>
|
|
30
|
+
]>>;
|
|
31
|
+
export type PromptInput = z.infer<typeof PromptInputSchema>;
|
|
32
|
+
declare const PromptVersionClientSchema: z.ZodDiscriminatedUnion<[
|
|
33
|
+
z.ZodObject<{
|
|
34
|
+
tenantId: z.ZodString;
|
|
35
|
+
environmentId: z.ZodString;
|
|
36
|
+
promptId: z.ZodString;
|
|
37
|
+
slug: z.ZodString;
|
|
38
|
+
versionNumber: z.ZodNumber;
|
|
39
|
+
template: z.ZodString;
|
|
40
|
+
variables: z.ZodArray<z.ZodObject<{
|
|
41
|
+
key: z.ZodString;
|
|
42
|
+
type: z.ZodEnum<{
|
|
43
|
+
string: "string";
|
|
44
|
+
number: "number";
|
|
45
|
+
boolean: "boolean";
|
|
46
|
+
object: "object";
|
|
47
|
+
list: "list";
|
|
48
|
+
}>;
|
|
49
|
+
required: z.ZodBoolean;
|
|
50
|
+
description: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
provider: z.ZodEnum<{
|
|
53
|
+
openai: "openai";
|
|
54
|
+
anthropic: "anthropic";
|
|
55
|
+
google: "google";
|
|
56
|
+
}>;
|
|
57
|
+
model: z.ZodString;
|
|
58
|
+
status: z.ZodEnum<{
|
|
59
|
+
draft: "draft";
|
|
60
|
+
active: "active";
|
|
61
|
+
inactive: "inactive";
|
|
62
|
+
}>;
|
|
63
|
+
parentVersionId: z.ZodOptional<z.ZodString>;
|
|
64
|
+
authorId: z.ZodString;
|
|
65
|
+
authorName: z.ZodString;
|
|
66
|
+
source: z.ZodLiteral<"manual">;
|
|
67
|
+
publishedAt: z.ZodOptional<z.ZodDate>;
|
|
68
|
+
id: z.ZodString;
|
|
69
|
+
schemaVersion: z.ZodNumber;
|
|
70
|
+
createdAt: z.ZodDate;
|
|
71
|
+
updatedAt: z.ZodDate;
|
|
72
|
+
}, z.core.$strip>,
|
|
73
|
+
z.ZodObject<{
|
|
74
|
+
tenantId: z.ZodString;
|
|
75
|
+
environmentId: z.ZodString;
|
|
76
|
+
promptId: z.ZodString;
|
|
77
|
+
slug: z.ZodString;
|
|
78
|
+
versionNumber: z.ZodNumber;
|
|
79
|
+
template: z.ZodString;
|
|
80
|
+
variables: z.ZodArray<z.ZodObject<{
|
|
81
|
+
key: z.ZodString;
|
|
82
|
+
type: z.ZodEnum<{
|
|
83
|
+
string: "string";
|
|
84
|
+
number: "number";
|
|
85
|
+
boolean: "boolean";
|
|
86
|
+
object: "object";
|
|
87
|
+
list: "list";
|
|
88
|
+
}>;
|
|
89
|
+
required: z.ZodBoolean;
|
|
90
|
+
description: z.ZodOptional<z.ZodString>;
|
|
91
|
+
}, z.core.$strip>>;
|
|
92
|
+
provider: z.ZodEnum<{
|
|
93
|
+
openai: "openai";
|
|
94
|
+
anthropic: "anthropic";
|
|
95
|
+
google: "google";
|
|
96
|
+
}>;
|
|
97
|
+
model: z.ZodString;
|
|
98
|
+
status: z.ZodEnum<{
|
|
99
|
+
draft: "draft";
|
|
100
|
+
active: "active";
|
|
101
|
+
inactive: "inactive";
|
|
102
|
+
}>;
|
|
103
|
+
parentVersionId: z.ZodOptional<z.ZodString>;
|
|
104
|
+
feedbackId: z.ZodString;
|
|
105
|
+
source: z.ZodLiteral<"feedback_llm_suggestion">;
|
|
106
|
+
publishedAt: z.ZodOptional<z.ZodDate>;
|
|
107
|
+
id: z.ZodString;
|
|
108
|
+
schemaVersion: z.ZodNumber;
|
|
109
|
+
createdAt: z.ZodDate;
|
|
110
|
+
updatedAt: z.ZodDate;
|
|
111
|
+
}, z.core.$strip>,
|
|
112
|
+
z.ZodObject<{
|
|
113
|
+
tenantId: z.ZodString;
|
|
114
|
+
environmentId: z.ZodString;
|
|
115
|
+
promptId: z.ZodString;
|
|
116
|
+
slug: z.ZodString;
|
|
117
|
+
versionNumber: z.ZodNumber;
|
|
118
|
+
template: z.ZodString;
|
|
119
|
+
variables: z.ZodArray<z.ZodObject<{
|
|
120
|
+
key: z.ZodString;
|
|
121
|
+
type: z.ZodEnum<{
|
|
122
|
+
string: "string";
|
|
123
|
+
number: "number";
|
|
124
|
+
boolean: "boolean";
|
|
125
|
+
object: "object";
|
|
126
|
+
list: "list";
|
|
127
|
+
}>;
|
|
128
|
+
required: z.ZodBoolean;
|
|
129
|
+
description: z.ZodOptional<z.ZodString>;
|
|
130
|
+
}, z.core.$strip>>;
|
|
131
|
+
provider: z.ZodEnum<{
|
|
132
|
+
openai: "openai";
|
|
133
|
+
anthropic: "anthropic";
|
|
134
|
+
google: "google";
|
|
135
|
+
}>;
|
|
136
|
+
model: z.ZodString;
|
|
137
|
+
status: z.ZodEnum<{
|
|
138
|
+
draft: "draft";
|
|
139
|
+
active: "active";
|
|
140
|
+
inactive: "inactive";
|
|
141
|
+
}>;
|
|
142
|
+
parentVersionId: z.ZodOptional<z.ZodString>;
|
|
143
|
+
authorId: z.ZodString;
|
|
144
|
+
authorName: z.ZodString;
|
|
145
|
+
feedbackId: z.ZodString;
|
|
146
|
+
source: z.ZodLiteral<"feedback_llm_override">;
|
|
147
|
+
publishedAt: z.ZodOptional<z.ZodDate>;
|
|
148
|
+
id: z.ZodString;
|
|
149
|
+
schemaVersion: z.ZodNumber;
|
|
150
|
+
createdAt: z.ZodDate;
|
|
151
|
+
updatedAt: z.ZodDate;
|
|
152
|
+
}, z.core.$strip>
|
|
153
|
+
], "source">;
|
|
154
|
+
export type PromptVersionClient = z.infer<typeof PromptVersionClientSchema>;
|
|
155
|
+
declare const helpfulSchema: z.ZodEnum<{
|
|
156
|
+
helpful: "helpful";
|
|
157
|
+
not_helpful: "not_helpful";
|
|
158
|
+
}>;
|
|
159
|
+
export type Helpful = z.infer<typeof helpfulSchema>;
|
|
160
|
+
declare const tokenUsageSchema: z.ZodObject<{
|
|
161
|
+
inputTokens: z.ZodNumber;
|
|
162
|
+
outputTokens: z.ZodNumber;
|
|
163
|
+
totalTokens: z.ZodNumber;
|
|
164
|
+
}, z.core.$strip>;
|
|
165
|
+
export type TokenUsage = z.infer<typeof tokenUsageSchema>;
|
|
166
|
+
/**
|
|
167
|
+
* Configuration options for the CobblClient
|
|
168
|
+
*/
|
|
169
|
+
export interface CobblConfig {
|
|
170
|
+
/**
|
|
171
|
+
* Your Cobbl API key
|
|
172
|
+
* @required
|
|
173
|
+
*/
|
|
174
|
+
apiKey: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Response from running a prompt
|
|
178
|
+
*/
|
|
179
|
+
export interface RunPromptResponse {
|
|
180
|
+
/**
|
|
181
|
+
* Unique ID for this prompt run - use this to link feedback
|
|
182
|
+
*/
|
|
183
|
+
runId: string;
|
|
184
|
+
/**
|
|
185
|
+
* The AI-generated output
|
|
186
|
+
*/
|
|
187
|
+
output: string;
|
|
188
|
+
/**
|
|
189
|
+
* Token usage statistics
|
|
190
|
+
*/
|
|
191
|
+
tokenUsage: TokenUsage;
|
|
192
|
+
/**
|
|
193
|
+
* The rendered prompt that was sent to the LLM (with variables substituted)
|
|
194
|
+
*/
|
|
195
|
+
renderedPrompt: string;
|
|
196
|
+
/**
|
|
197
|
+
* Information about the prompt version that was used
|
|
198
|
+
*/
|
|
199
|
+
promptVersion: PromptVersionClient;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Feedback submission data
|
|
203
|
+
*/
|
|
204
|
+
export interface FeedbackSubmission {
|
|
205
|
+
/**
|
|
206
|
+
* The run ID from a previous runPrompt call
|
|
207
|
+
* @required
|
|
208
|
+
*/
|
|
209
|
+
runId: string;
|
|
210
|
+
/**
|
|
211
|
+
* Whether the output was helpful
|
|
212
|
+
* @required
|
|
213
|
+
*/
|
|
214
|
+
helpful: Helpful;
|
|
215
|
+
/**
|
|
216
|
+
* Detailed feedback message from the user
|
|
217
|
+
* @required
|
|
218
|
+
*/
|
|
219
|
+
userFeedback: string;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Response from submitting feedback
|
|
223
|
+
*/
|
|
224
|
+
export interface SubmitFeedbackResponse {
|
|
225
|
+
/**
|
|
226
|
+
* Unique ID for the created feedback item
|
|
227
|
+
*/
|
|
228
|
+
feedbackId: string;
|
|
229
|
+
/**
|
|
230
|
+
* Success message
|
|
231
|
+
*/
|
|
232
|
+
message: string;
|
|
233
|
+
}
|
|
234
|
+
export declare class CobblClient {
|
|
235
|
+
private readonly apiKey;
|
|
236
|
+
/**
|
|
237
|
+
* Initialize the Cobbl SDK client
|
|
238
|
+
*
|
|
239
|
+
* @param config - Configuration object
|
|
240
|
+
* @param config.apiKey - Your Cobbl API key
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const client = new CobblClient({
|
|
245
|
+
* apiKey: process.env.COBBL_API_KEY
|
|
246
|
+
* })
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
constructor(config: CobblConfig);
|
|
250
|
+
/**
|
|
251
|
+
* Execute a prompt with the given input variables
|
|
252
|
+
*
|
|
253
|
+
* @param promptSlug - The unique slug identifier for the prompt
|
|
254
|
+
* @param input - Input variables to populate the prompt template
|
|
255
|
+
* @returns Promise containing the prompt execution results
|
|
256
|
+
*
|
|
257
|
+
* @throws {CobblError} When the request fails or API returns an error
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* const result = await client.runPrompt('sales_summary', {
|
|
262
|
+
* topic: 'Q4 Results',
|
|
263
|
+
* tone: 'friendly',
|
|
264
|
+
* audience: 'investors'
|
|
265
|
+
* })
|
|
266
|
+
*
|
|
267
|
+
* console.log(result.output) // AI-generated response
|
|
268
|
+
* console.log(result.runId) // Save this to link feedback later
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
runPrompt(promptSlug: string, input: PromptInput): Promise<RunPromptResponse>;
|
|
272
|
+
/**
|
|
273
|
+
* Submit user feedback for a prompt run
|
|
274
|
+
*
|
|
275
|
+
* @param feedback - Feedback submission data
|
|
276
|
+
* @param feedback.runId - The run ID from a previous runPrompt call
|
|
277
|
+
* @param feedback.helpful - Whether the output was helpful ('helpful' or 'not_helpful')
|
|
278
|
+
* @param feedback.userFeedback - Detailed feedback message from the user
|
|
279
|
+
* @returns Promise containing the created feedback ID
|
|
280
|
+
*
|
|
281
|
+
* @throws {CobblError} When the request fails or API returns an error
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* await client.submitFeedback({
|
|
286
|
+
* runId: result.runId,
|
|
287
|
+
* helpful: 'not_helpful',
|
|
288
|
+
* userFeedback: 'The response was too formal and lengthy'
|
|
289
|
+
* })
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
submitFeedback(feedback: FeedbackSubmission): Promise<SubmitFeedbackResponse>;
|
|
293
|
+
/**
|
|
294
|
+
* Make an HTTP request to the Cobbl API
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
private makeRequest;
|
|
298
|
+
/**
|
|
299
|
+
* Handle error responses from the API
|
|
300
|
+
* @private
|
|
301
|
+
*/
|
|
302
|
+
private handleErrorResponse;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Error types that can be thrown by the Cobbl SDK
|
|
306
|
+
*/
|
|
307
|
+
export type CobblErrorCode = "INVALID_CONFIG" | "INVALID_REQUEST" | "UNAUTHORIZED" | "NOT_FOUND" | "RATE_LIMIT_EXCEEDED" | "SERVER_ERROR" | "NETWORK_ERROR" | "API_ERROR";
|
|
308
|
+
/**
|
|
309
|
+
* Custom error class for Cobbl SDK errors
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* try {
|
|
314
|
+
* await client.runPrompt('my-prompt', { topic: 'test' })
|
|
315
|
+
* } catch (error) {
|
|
316
|
+
* if (error instanceof CobblError) {
|
|
317
|
+
* console.error(`Error [${error.code}]: ${error.message}`)
|
|
318
|
+
* console.error('Details:', error.details)
|
|
319
|
+
* }
|
|
320
|
+
* }
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
export declare class CobblError extends Error {
|
|
324
|
+
/**
|
|
325
|
+
* Error code indicating the type of error
|
|
326
|
+
*/
|
|
327
|
+
readonly code: CobblErrorCode;
|
|
328
|
+
/**
|
|
329
|
+
* Additional details about the error (e.g., missing variables, validation issues)
|
|
330
|
+
*/
|
|
331
|
+
readonly details?: unknown;
|
|
332
|
+
constructor(message: string, code: CobblErrorCode, details?: unknown);
|
|
333
|
+
/**
|
|
334
|
+
* Check if an error is a CobblError
|
|
335
|
+
*/
|
|
336
|
+
static isCobblError(error: unknown): error is CobblError;
|
|
337
|
+
/**
|
|
338
|
+
* Convert error to JSON-serializable object
|
|
339
|
+
*/
|
|
340
|
+
toJSON(): {
|
|
341
|
+
name: string;
|
|
342
|
+
message: string;
|
|
343
|
+
code: CobblErrorCode;
|
|
344
|
+
details: unknown;
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export {};
|