@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/src/errors.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types that can be thrown by the Cobbl SDK
|
|
3
|
+
*/
|
|
4
|
+
export type CobblErrorCode =
|
|
5
|
+
| 'INVALID_CONFIG'
|
|
6
|
+
| 'INVALID_REQUEST'
|
|
7
|
+
| 'UNAUTHORIZED'
|
|
8
|
+
| 'NOT_FOUND'
|
|
9
|
+
| 'RATE_LIMIT_EXCEEDED'
|
|
10
|
+
| 'SERVER_ERROR'
|
|
11
|
+
| 'NETWORK_ERROR'
|
|
12
|
+
| 'API_ERROR'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Custom error class for Cobbl SDK errors
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* try {
|
|
20
|
+
* await client.runPrompt('my-prompt', { topic: 'test' })
|
|
21
|
+
* } catch (error) {
|
|
22
|
+
* if (error instanceof CobblError) {
|
|
23
|
+
* console.error(`Error [${error.code}]: ${error.message}`)
|
|
24
|
+
* console.error('Details:', error.details)
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class CobblError extends Error {
|
|
30
|
+
/**
|
|
31
|
+
* Error code indicating the type of error
|
|
32
|
+
*/
|
|
33
|
+
public readonly code: CobblErrorCode
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Additional details about the error (e.g., missing variables, validation issues)
|
|
37
|
+
*/
|
|
38
|
+
public readonly details?: unknown
|
|
39
|
+
|
|
40
|
+
constructor(message: string, code: CobblErrorCode, details?: unknown) {
|
|
41
|
+
super(message)
|
|
42
|
+
this.name = 'CobblError'
|
|
43
|
+
this.code = code
|
|
44
|
+
this.details = details
|
|
45
|
+
|
|
46
|
+
// Maintains proper stack trace for where error was thrown (V8 only)
|
|
47
|
+
if (Error.captureStackTrace) {
|
|
48
|
+
Error.captureStackTrace(this, CobblError)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Check if an error is a CobblError
|
|
54
|
+
*/
|
|
55
|
+
static isCobblError(error: unknown): error is CobblError {
|
|
56
|
+
return error instanceof CobblError
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Convert error to JSON-serializable object
|
|
61
|
+
*/
|
|
62
|
+
toJSON() {
|
|
63
|
+
return {
|
|
64
|
+
name: this.name,
|
|
65
|
+
message: this.message,
|
|
66
|
+
code: this.code,
|
|
67
|
+
details: this.details,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cobbl SDK
|
|
3
|
+
*
|
|
4
|
+
* A lightweight SDK for interacting with the Cobbl platform.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { CobblClient } from '@cobbl-ai/sdk'
|
|
9
|
+
*
|
|
10
|
+
* const client = new CobblClient({
|
|
11
|
+
* apiKey: process.env.COBBL_API_KEY
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* // Run a prompt
|
|
15
|
+
* const result = await client.runPrompt('sales_summary', {
|
|
16
|
+
* topic: 'Q4 Results',
|
|
17
|
+
* tone: 'friendly'
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* // Submit feedback
|
|
21
|
+
* await client.submitFeedback({
|
|
22
|
+
* runId: result.runId,
|
|
23
|
+
* helpful: 'not_helpful',
|
|
24
|
+
* userFeedback: 'Too formal'
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export { CobblClient } from './client'
|
|
30
|
+
export { CobblError } from './errors'
|
|
31
|
+
export type { CobblErrorCode } from './errors'
|
|
32
|
+
export type {
|
|
33
|
+
CobblConfig,
|
|
34
|
+
TokenUsage,
|
|
35
|
+
RunPromptResponse,
|
|
36
|
+
Helpful,
|
|
37
|
+
FeedbackSubmission,
|
|
38
|
+
SubmitFeedbackResponse,
|
|
39
|
+
PromptInput,
|
|
40
|
+
PromptVersionClient,
|
|
41
|
+
Provider,
|
|
42
|
+
VariableConfig,
|
|
43
|
+
} from './types'
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Cobbl SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { PromptVersionClient, TokenUsage, Helpful } from '@prompti/shared'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for the CobblClient
|
|
9
|
+
*/
|
|
10
|
+
export interface CobblConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Your Cobbl API key
|
|
13
|
+
* @required
|
|
14
|
+
*/
|
|
15
|
+
apiKey: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Response from running a prompt
|
|
20
|
+
*/
|
|
21
|
+
export interface RunPromptResponse {
|
|
22
|
+
/**
|
|
23
|
+
* Unique ID for this prompt run - use this to link feedback
|
|
24
|
+
*/
|
|
25
|
+
runId: string
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The AI-generated output
|
|
29
|
+
*/
|
|
30
|
+
output: string
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Token usage statistics
|
|
34
|
+
*/
|
|
35
|
+
tokenUsage: TokenUsage
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The rendered prompt that was sent to the LLM (with variables substituted)
|
|
39
|
+
*/
|
|
40
|
+
renderedPrompt: string
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Information about the prompt version that was used
|
|
44
|
+
*/
|
|
45
|
+
promptVersion: PromptVersionClient
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Feedback submission data
|
|
50
|
+
*/
|
|
51
|
+
export interface FeedbackSubmission {
|
|
52
|
+
/**
|
|
53
|
+
* The run ID from a previous runPrompt call
|
|
54
|
+
* @required
|
|
55
|
+
*/
|
|
56
|
+
runId: string
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether the output was helpful
|
|
60
|
+
* @required
|
|
61
|
+
*/
|
|
62
|
+
helpful: Helpful
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Detailed feedback message from the user
|
|
66
|
+
* @required
|
|
67
|
+
*/
|
|
68
|
+
userFeedback: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Response from submitting feedback
|
|
73
|
+
*/
|
|
74
|
+
export interface SubmitFeedbackResponse {
|
|
75
|
+
/**
|
|
76
|
+
* Unique ID for the created feedback item
|
|
77
|
+
*/
|
|
78
|
+
feedbackId: string
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Success message
|
|
82
|
+
*/
|
|
83
|
+
message: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Re-export commonly used types from shared
|
|
87
|
+
export type {
|
|
88
|
+
PromptInput,
|
|
89
|
+
PromptVersionClient,
|
|
90
|
+
Provider,
|
|
91
|
+
VariableConfig,
|
|
92
|
+
TokenUsage,
|
|
93
|
+
Helpful,
|
|
94
|
+
} from '@prompti/shared'
|