@cobbl-ai/sdk 0.1.0 → 0.1.2
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 +179 -55
- package/dist/admin.d.mts +90 -0
- package/dist/admin.d.ts +90 -0
- package/dist/admin.js +185 -0
- package/dist/admin.js.map +1 -0
- package/dist/admin.mjs +182 -0
- package/dist/admin.mjs.map +1 -0
- package/dist/cobbl-sdk.global.js +2 -0
- package/dist/cobbl-sdk.global.js.map +1 -0
- package/dist/errors-BaYZ2rGo.d.mts +208 -0
- package/dist/errors-BaYZ2rGo.d.ts +208 -0
- package/dist/index.d.mts +3 -348
- package/dist/index.d.ts +3 -348
- package/dist/index.js +222 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +221 -75
- package/dist/index.mjs.map +1 -1
- package/dist/public.d.mts +130 -0
- package/dist/public.d.ts +130 -0
- package/dist/public.js +271 -0
- package/dist/public.js.map +1 -0
- package/dist/public.mjs +268 -0
- package/dist/public.mjs.map +1 -0
- package/package.json +40 -11
- package/src/__tests__/client.test.ts +362 -107
- package/src/__tests__/integration.test.ts +129 -38
- package/src/admin.ts +184 -0
- package/src/browser.ts +12 -0
- package/src/errors.ts +49 -0
- package/src/index.ts +35 -10
- package/src/public.ts +270 -0
- package/src/types.ts +164 -58
- package/src/validation.ts +52 -0
- package/src/client.ts +0 -257
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Cobbl SDK
|
|
3
|
+
*
|
|
4
|
+
* All types are defined locally to keep the SDK self-contained.
|
|
5
|
+
* These match the API contract and are used as type hints for SDK consumers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for the CobblClient
|
|
9
|
+
*/
|
|
10
|
+
interface CobblConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Your Cobbl API key
|
|
13
|
+
* @required
|
|
14
|
+
*/
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* Base URL for the API
|
|
18
|
+
* @optional
|
|
19
|
+
* @default 'https://api.cobbl.ai'
|
|
20
|
+
* @internal
|
|
21
|
+
* @example 'http://localhost:5001/your-project/us-central1/externalApi' // For local development
|
|
22
|
+
*/
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether the AI output was helpful
|
|
27
|
+
*/
|
|
28
|
+
type Helpful = 'helpful' | 'not_helpful';
|
|
29
|
+
/**
|
|
30
|
+
* Request payload for creating feedback
|
|
31
|
+
* Supports segmented feedback submission - at least one of helpful or userFeedback required
|
|
32
|
+
*/
|
|
33
|
+
interface CreateFeedbackRequest {
|
|
34
|
+
runId: string;
|
|
35
|
+
helpful?: Helpful;
|
|
36
|
+
userFeedback?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Response from creating feedback
|
|
40
|
+
*/
|
|
41
|
+
interface CreateFeedbackResponse {
|
|
42
|
+
id: string;
|
|
43
|
+
message: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Request payload for updating feedback
|
|
47
|
+
* At least one of helpful or userFeedback required
|
|
48
|
+
*/
|
|
49
|
+
interface UpdateFeedbackRequest {
|
|
50
|
+
helpful?: Helpful;
|
|
51
|
+
userFeedback?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Response from updating feedback
|
|
55
|
+
*/
|
|
56
|
+
interface UpdateFeedbackResponse {
|
|
57
|
+
id: string;
|
|
58
|
+
message: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Supported LLM providers
|
|
62
|
+
*/
|
|
63
|
+
type Provider = 'openai' | 'anthropic' | 'google';
|
|
64
|
+
/**
|
|
65
|
+
* Configuration for a variable in the prompt
|
|
66
|
+
*/
|
|
67
|
+
interface VariableConfig {
|
|
68
|
+
key: string;
|
|
69
|
+
type: 'string' | 'number' | 'boolean' | 'list' | 'object';
|
|
70
|
+
required: boolean;
|
|
71
|
+
description?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Input values provided when executing a prompt
|
|
75
|
+
*/
|
|
76
|
+
type PromptInput = Record<string, string | number | boolean | unknown[] | Record<string, unknown>>;
|
|
77
|
+
/**
|
|
78
|
+
* Token usage breakdown for a completed prompt run
|
|
79
|
+
*/
|
|
80
|
+
interface TokenUsage {
|
|
81
|
+
inputTokens: number;
|
|
82
|
+
outputTokens: number;
|
|
83
|
+
totalTokens: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Aggregated analytics for a prompt or prompt version
|
|
87
|
+
*/
|
|
88
|
+
interface PromptAggregatedAnalytics {
|
|
89
|
+
runs: {
|
|
90
|
+
totalCount: number;
|
|
91
|
+
successCount: number;
|
|
92
|
+
errorCount: number;
|
|
93
|
+
totalProviderMs: number;
|
|
94
|
+
totalRequestMs: number;
|
|
95
|
+
successRate: number;
|
|
96
|
+
errorRate: number;
|
|
97
|
+
avgProviderMs: number;
|
|
98
|
+
avgRequestMs: number;
|
|
99
|
+
};
|
|
100
|
+
feedback: {
|
|
101
|
+
totalCount: number;
|
|
102
|
+
helpfulCount: number;
|
|
103
|
+
notHelpfulCount: number;
|
|
104
|
+
helpfulRate: number;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Base fields shared across all prompt version sources
|
|
109
|
+
*/
|
|
110
|
+
interface PromptVersionBase {
|
|
111
|
+
id: string;
|
|
112
|
+
schemaVersion: number;
|
|
113
|
+
createdAt: Date;
|
|
114
|
+
updatedAt: Date;
|
|
115
|
+
tenantId: string;
|
|
116
|
+
environmentId: string;
|
|
117
|
+
promptId: string;
|
|
118
|
+
versionNumber: number;
|
|
119
|
+
template: string;
|
|
120
|
+
variables: VariableConfig[];
|
|
121
|
+
provider: Provider;
|
|
122
|
+
model: string;
|
|
123
|
+
status: 'draft' | 'active' | 'inactive';
|
|
124
|
+
parentVersionId: string | null;
|
|
125
|
+
analytics: PromptAggregatedAnalytics;
|
|
126
|
+
publishedAt: Date | null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Manually created prompt version (by a user or from feedback edits)
|
|
130
|
+
*/
|
|
131
|
+
interface PromptVersionManual extends PromptVersionBase {
|
|
132
|
+
source: 'manual';
|
|
133
|
+
authorId: string;
|
|
134
|
+
authorName: string | null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* AI-generated prompt version suggestion from feedback issue assessment
|
|
138
|
+
*/
|
|
139
|
+
interface PromptVersionIssueLlmSuggestion extends PromptVersionBase {
|
|
140
|
+
source: 'issue_llm_suggestion';
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Prompt version - discriminated union by source
|
|
144
|
+
*/
|
|
145
|
+
type PromptVersionClient = PromptVersionManual | PromptVersionIssueLlmSuggestion;
|
|
146
|
+
/**
|
|
147
|
+
* Request payload for running a prompt
|
|
148
|
+
*/
|
|
149
|
+
interface RunPromptRequest {
|
|
150
|
+
promptSlug: string;
|
|
151
|
+
input: PromptInput;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Response from running a prompt
|
|
155
|
+
*/
|
|
156
|
+
interface RunPromptResponse {
|
|
157
|
+
runId: string;
|
|
158
|
+
output: string;
|
|
159
|
+
tokenUsage: TokenUsage;
|
|
160
|
+
renderedPrompt: string;
|
|
161
|
+
promptVersion: PromptVersionClient;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Error types that can be thrown by the Cobbl SDK
|
|
166
|
+
*/
|
|
167
|
+
type CobblErrorCode = 'INVALID_CONFIG' | 'INVALID_REQUEST' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'ARCHIVED' | 'RATE_LIMIT_EXCEEDED' | 'SERVER_ERROR' | 'NETWORK_ERROR' | 'API_ERROR';
|
|
168
|
+
/**
|
|
169
|
+
* Custom error class for Cobbl SDK errors
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* try {
|
|
174
|
+
* await client.runPrompt('my-prompt', { topic: 'test' })
|
|
175
|
+
* } catch (error) {
|
|
176
|
+
* if (error instanceof CobblError) {
|
|
177
|
+
* console.error(`Error [${error.code}]: ${error.message}`)
|
|
178
|
+
* console.error('Details:', error.details)
|
|
179
|
+
* }
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare class CobblError extends Error {
|
|
184
|
+
/**
|
|
185
|
+
* Error code indicating the type of error
|
|
186
|
+
*/
|
|
187
|
+
readonly code: CobblErrorCode;
|
|
188
|
+
/**
|
|
189
|
+
* Additional details about the error (e.g., missing variables, validation issues)
|
|
190
|
+
*/
|
|
191
|
+
readonly details?: unknown;
|
|
192
|
+
constructor(message: string, code: CobblErrorCode, details?: unknown);
|
|
193
|
+
/**
|
|
194
|
+
* Check if an error is a CobblError
|
|
195
|
+
*/
|
|
196
|
+
static isCobblError(error: unknown): error is CobblError;
|
|
197
|
+
/**
|
|
198
|
+
* Convert error to JSON-serializable object
|
|
199
|
+
*/
|
|
200
|
+
toJSON(): {
|
|
201
|
+
name: string;
|
|
202
|
+
message: string;
|
|
203
|
+
code: CobblErrorCode;
|
|
204
|
+
details: unknown;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { CobblError as C, type Helpful as H, type PromptInput as P, type RunPromptRequest as R, type TokenUsage as T, type UpdateFeedbackRequest as U, type VariableConfig as V, type CobblErrorCode as a, type CobblConfig as b, type RunPromptResponse as c, type CreateFeedbackRequest as d, type CreateFeedbackResponse as e, type UpdateFeedbackResponse as f, type PromptVersionClient as g, type Provider as h };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Cobbl SDK
|
|
3
|
+
*
|
|
4
|
+
* All types are defined locally to keep the SDK self-contained.
|
|
5
|
+
* These match the API contract and are used as type hints for SDK consumers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for the CobblClient
|
|
9
|
+
*/
|
|
10
|
+
interface CobblConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Your Cobbl API key
|
|
13
|
+
* @required
|
|
14
|
+
*/
|
|
15
|
+
apiKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* Base URL for the API
|
|
18
|
+
* @optional
|
|
19
|
+
* @default 'https://api.cobbl.ai'
|
|
20
|
+
* @internal
|
|
21
|
+
* @example 'http://localhost:5001/your-project/us-central1/externalApi' // For local development
|
|
22
|
+
*/
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether the AI output was helpful
|
|
27
|
+
*/
|
|
28
|
+
type Helpful = 'helpful' | 'not_helpful';
|
|
29
|
+
/**
|
|
30
|
+
* Request payload for creating feedback
|
|
31
|
+
* Supports segmented feedback submission - at least one of helpful or userFeedback required
|
|
32
|
+
*/
|
|
33
|
+
interface CreateFeedbackRequest {
|
|
34
|
+
runId: string;
|
|
35
|
+
helpful?: Helpful;
|
|
36
|
+
userFeedback?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Response from creating feedback
|
|
40
|
+
*/
|
|
41
|
+
interface CreateFeedbackResponse {
|
|
42
|
+
id: string;
|
|
43
|
+
message: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Request payload for updating feedback
|
|
47
|
+
* At least one of helpful or userFeedback required
|
|
48
|
+
*/
|
|
49
|
+
interface UpdateFeedbackRequest {
|
|
50
|
+
helpful?: Helpful;
|
|
51
|
+
userFeedback?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Response from updating feedback
|
|
55
|
+
*/
|
|
56
|
+
interface UpdateFeedbackResponse {
|
|
57
|
+
id: string;
|
|
58
|
+
message: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Supported LLM providers
|
|
62
|
+
*/
|
|
63
|
+
type Provider = 'openai' | 'anthropic' | 'google';
|
|
64
|
+
/**
|
|
65
|
+
* Configuration for a variable in the prompt
|
|
66
|
+
*/
|
|
67
|
+
interface VariableConfig {
|
|
68
|
+
key: string;
|
|
69
|
+
type: 'string' | 'number' | 'boolean' | 'list' | 'object';
|
|
70
|
+
required: boolean;
|
|
71
|
+
description?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Input values provided when executing a prompt
|
|
75
|
+
*/
|
|
76
|
+
type PromptInput = Record<string, string | number | boolean | unknown[] | Record<string, unknown>>;
|
|
77
|
+
/**
|
|
78
|
+
* Token usage breakdown for a completed prompt run
|
|
79
|
+
*/
|
|
80
|
+
interface TokenUsage {
|
|
81
|
+
inputTokens: number;
|
|
82
|
+
outputTokens: number;
|
|
83
|
+
totalTokens: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Aggregated analytics for a prompt or prompt version
|
|
87
|
+
*/
|
|
88
|
+
interface PromptAggregatedAnalytics {
|
|
89
|
+
runs: {
|
|
90
|
+
totalCount: number;
|
|
91
|
+
successCount: number;
|
|
92
|
+
errorCount: number;
|
|
93
|
+
totalProviderMs: number;
|
|
94
|
+
totalRequestMs: number;
|
|
95
|
+
successRate: number;
|
|
96
|
+
errorRate: number;
|
|
97
|
+
avgProviderMs: number;
|
|
98
|
+
avgRequestMs: number;
|
|
99
|
+
};
|
|
100
|
+
feedback: {
|
|
101
|
+
totalCount: number;
|
|
102
|
+
helpfulCount: number;
|
|
103
|
+
notHelpfulCount: number;
|
|
104
|
+
helpfulRate: number;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Base fields shared across all prompt version sources
|
|
109
|
+
*/
|
|
110
|
+
interface PromptVersionBase {
|
|
111
|
+
id: string;
|
|
112
|
+
schemaVersion: number;
|
|
113
|
+
createdAt: Date;
|
|
114
|
+
updatedAt: Date;
|
|
115
|
+
tenantId: string;
|
|
116
|
+
environmentId: string;
|
|
117
|
+
promptId: string;
|
|
118
|
+
versionNumber: number;
|
|
119
|
+
template: string;
|
|
120
|
+
variables: VariableConfig[];
|
|
121
|
+
provider: Provider;
|
|
122
|
+
model: string;
|
|
123
|
+
status: 'draft' | 'active' | 'inactive';
|
|
124
|
+
parentVersionId: string | null;
|
|
125
|
+
analytics: PromptAggregatedAnalytics;
|
|
126
|
+
publishedAt: Date | null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Manually created prompt version (by a user or from feedback edits)
|
|
130
|
+
*/
|
|
131
|
+
interface PromptVersionManual extends PromptVersionBase {
|
|
132
|
+
source: 'manual';
|
|
133
|
+
authorId: string;
|
|
134
|
+
authorName: string | null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* AI-generated prompt version suggestion from feedback issue assessment
|
|
138
|
+
*/
|
|
139
|
+
interface PromptVersionIssueLlmSuggestion extends PromptVersionBase {
|
|
140
|
+
source: 'issue_llm_suggestion';
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Prompt version - discriminated union by source
|
|
144
|
+
*/
|
|
145
|
+
type PromptVersionClient = PromptVersionManual | PromptVersionIssueLlmSuggestion;
|
|
146
|
+
/**
|
|
147
|
+
* Request payload for running a prompt
|
|
148
|
+
*/
|
|
149
|
+
interface RunPromptRequest {
|
|
150
|
+
promptSlug: string;
|
|
151
|
+
input: PromptInput;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Response from running a prompt
|
|
155
|
+
*/
|
|
156
|
+
interface RunPromptResponse {
|
|
157
|
+
runId: string;
|
|
158
|
+
output: string;
|
|
159
|
+
tokenUsage: TokenUsage;
|
|
160
|
+
renderedPrompt: string;
|
|
161
|
+
promptVersion: PromptVersionClient;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Error types that can be thrown by the Cobbl SDK
|
|
166
|
+
*/
|
|
167
|
+
type CobblErrorCode = 'INVALID_CONFIG' | 'INVALID_REQUEST' | 'UNAUTHORIZED' | 'FORBIDDEN' | 'NOT_FOUND' | 'ARCHIVED' | 'RATE_LIMIT_EXCEEDED' | 'SERVER_ERROR' | 'NETWORK_ERROR' | 'API_ERROR';
|
|
168
|
+
/**
|
|
169
|
+
* Custom error class for Cobbl SDK errors
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* try {
|
|
174
|
+
* await client.runPrompt('my-prompt', { topic: 'test' })
|
|
175
|
+
* } catch (error) {
|
|
176
|
+
* if (error instanceof CobblError) {
|
|
177
|
+
* console.error(`Error [${error.code}]: ${error.message}`)
|
|
178
|
+
* console.error('Details:', error.details)
|
|
179
|
+
* }
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare class CobblError extends Error {
|
|
184
|
+
/**
|
|
185
|
+
* Error code indicating the type of error
|
|
186
|
+
*/
|
|
187
|
+
readonly code: CobblErrorCode;
|
|
188
|
+
/**
|
|
189
|
+
* Additional details about the error (e.g., missing variables, validation issues)
|
|
190
|
+
*/
|
|
191
|
+
readonly details?: unknown;
|
|
192
|
+
constructor(message: string, code: CobblErrorCode, details?: unknown);
|
|
193
|
+
/**
|
|
194
|
+
* Check if an error is a CobblError
|
|
195
|
+
*/
|
|
196
|
+
static isCobblError(error: unknown): error is CobblError;
|
|
197
|
+
/**
|
|
198
|
+
* Convert error to JSON-serializable object
|
|
199
|
+
*/
|
|
200
|
+
toJSON(): {
|
|
201
|
+
name: string;
|
|
202
|
+
message: string;
|
|
203
|
+
code: CobblErrorCode;
|
|
204
|
+
details: unknown;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { CobblError as C, type Helpful as H, type PromptInput as P, type RunPromptRequest as R, type TokenUsage as T, type UpdateFeedbackRequest as U, type VariableConfig as V, type CobblErrorCode as a, type CobblConfig as b, type RunPromptResponse as c, type CreateFeedbackRequest as d, type CreateFeedbackResponse as e, type UpdateFeedbackResponse as f, type PromptVersionClient as g, type Provider as h };
|