@forprompt/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.
@@ -0,0 +1,308 @@
1
+ /**
2
+ * ForPrompt SDK Types
3
+ */
4
+ interface ForPromptConfig {
5
+ /** API key from ForPrompt dashboard (required) */
6
+ apiKey: string;
7
+ /** Custom base URL (optional, defaults to https://wooden-fox-811.convex.site) */
8
+ baseUrl?: string;
9
+ }
10
+ interface Prompt {
11
+ /** Unique key identifier for the prompt */
12
+ key: string;
13
+ /** Display name of the prompt */
14
+ name: string;
15
+ /** Optional description */
16
+ description?: string;
17
+ /** Version number */
18
+ versionNumber: number;
19
+ /** The system prompt content */
20
+ systemPrompt: string;
21
+ /** Last update timestamp */
22
+ updatedAt: number;
23
+ /** Prompt information fields */
24
+ purpose?: string;
25
+ expectedBehavior?: string;
26
+ inputFormat?: string;
27
+ outputFormat?: string;
28
+ constraints?: string;
29
+ useCases?: string;
30
+ additionalNotes?: string;
31
+ toolsNotes?: string;
32
+ }
33
+ interface GetPromptOptions {
34
+ /** Specific version number to fetch (optional, defaults to active version) */
35
+ version?: number;
36
+ }
37
+ declare class ForPromptError extends Error {
38
+ statusCode: number;
39
+ code: string;
40
+ constructor(message: string, statusCode: number, code: string);
41
+ }
42
+
43
+ /**
44
+ * ForPrompt Client
45
+ *
46
+ * Simple usage with auto-configuration:
47
+ * @example
48
+ * ```typescript
49
+ * import { forprompt } from "@forprompt/sdk";
50
+ *
51
+ * // Auto-loads from FORPROMPT_API_KEY env variable
52
+ * const prompt = await forprompt.getPrompt("userContextPrompt");
53
+ * ```
54
+ */
55
+
56
+ /**
57
+ * Extended client configuration with security options
58
+ */
59
+ interface ForPromptClientConfig {
60
+ /** Project API key (required) */
61
+ apiKey: string;
62
+ /** Base URL for API (default: https://wooden-fox-811.convex.site) */
63
+ baseUrl?: string;
64
+ /** Request timeout in milliseconds (default: 30000) */
65
+ timeout?: number;
66
+ /** Number of retry attempts for failed requests (default: 3) */
67
+ retries?: number;
68
+ }
69
+ declare class ForPrompt {
70
+ private baseUrl;
71
+ private apiKey;
72
+ private timeout;
73
+ private retries;
74
+ constructor(config: ForPromptClientConfig | ForPromptConfig | {
75
+ apiKey: string;
76
+ baseUrl?: string;
77
+ });
78
+ /**
79
+ * Fetch with timeout support using AbortController
80
+ */
81
+ private fetchWithTimeout;
82
+ /**
83
+ * Fetch with retry and exponential backoff
84
+ */
85
+ private fetchWithRetry;
86
+ /**
87
+ * Get a prompt by its key
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const prompt = await forprompt.getPrompt("userContextPrompt");
92
+ * console.log(prompt.systemPrompt);
93
+ * ```
94
+ *
95
+ * @example With specific version
96
+ * ```typescript
97
+ * const prompt = await forprompt.getPrompt("userContextPrompt", { version: 2 });
98
+ * ```
99
+ */
100
+ getPrompt(key: string, options?: GetPromptOptions): Promise<Prompt>;
101
+ /**
102
+ * Get multiple prompts by their keys
103
+ *
104
+ * Requests are made in parallel with concurrency limit to avoid overwhelming the server.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const prompts = await forprompt.getPrompts(["userContext", "chatDefault"]);
109
+ * ```
110
+ */
111
+ getPrompts(keys: string[], options?: GetPromptOptions): Promise<Map<string, Prompt>>;
112
+ }
113
+ /**
114
+ * Create a ForPrompt client instance
115
+ *
116
+ * @example With explicit config
117
+ * ```typescript
118
+ * import { createForPrompt } from "@forprompt/sdk";
119
+ *
120
+ * const client = createForPrompt({
121
+ * apiKey: "fp_xxx",
122
+ * });
123
+ *
124
+ * const prompt = await client.getPrompt("userContextPrompt");
125
+ * ```
126
+ *
127
+ * @example With timeout and retry config
128
+ * ```typescript
129
+ * const client = createForPrompt({
130
+ * apiKey: "fp_xxx",
131
+ * timeout: 10000, // 10 seconds
132
+ * retries: 5,
133
+ * });
134
+ * ```
135
+ *
136
+ * @example Auto-config from environment
137
+ * ```typescript
138
+ * import { forprompt } from "@forprompt/sdk";
139
+ *
140
+ * // Uses FORPROMPT_API_KEY from environment
141
+ * const prompt = await forprompt.getPrompt("userContextPrompt");
142
+ * ```
143
+ */
144
+ declare function createForPrompt(config?: Partial<ForPromptClientConfig>): ForPrompt;
145
+ /**
146
+ * Default ForPrompt client instance
147
+ *
148
+ * Auto-configured from environment variables:
149
+ * - FORPROMPT_API_KEY: Your project API key
150
+ * - FORPROMPT_BASE_URL: Custom base URL (optional)
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * import { forprompt } from "@forprompt/sdk";
155
+ *
156
+ * const prompt = await forprompt.getPrompt("userContextPrompt");
157
+ * console.log(prompt.systemPrompt);
158
+ * ```
159
+ */
160
+ declare const forprompt: ForPrompt;
161
+
162
+ /**
163
+ * ForPrompt Logger
164
+ *
165
+ * Implements trace/span model for logging AI conversations
166
+ *
167
+ * @example Basic usage
168
+ * ```typescript
169
+ * import { logger } from "@forprompt/sdk";
170
+ *
171
+ * // Start a trace
172
+ * logger.startTrace("onboardingprompt");
173
+ *
174
+ * // Log user message
175
+ * await logger.log({ role: "user", content: "Hello" });
176
+ *
177
+ * // Log AI response
178
+ * await logger.log({
179
+ * role: "assistant",
180
+ * content: "Hi! How can I help?",
181
+ * model: "gpt-4o",
182
+ * tokens: { output: 120 }
183
+ * });
184
+ *
185
+ * // End trace (optional)
186
+ * logger.endTrace();
187
+ * ```
188
+ */
189
+ interface LogOptions {
190
+ role: "user" | "assistant" | "system";
191
+ content: string;
192
+ model?: string;
193
+ tokens?: {
194
+ input?: number;
195
+ output?: number;
196
+ };
197
+ durationMs?: number;
198
+ metadata?: Record<string, any>;
199
+ }
200
+ /**
201
+ * Options for logging a single AI request/response
202
+ * Use this for one-shot interactions without conversation tracking
203
+ */
204
+ interface SingleRequestOptions {
205
+ /** The prompt identifier */
206
+ promptKey: string;
207
+ /** Prompt version number for analytics tracking */
208
+ versionNumber?: number;
209
+ /** Optional custom trace ID (auto-generated if not provided) */
210
+ traceId?: string;
211
+ /** The user's input/prompt */
212
+ input: string;
213
+ /** The AI's output/response */
214
+ output: string;
215
+ /** The model used (e.g., "gpt-4o", "claude-sonnet-4") */
216
+ model?: string;
217
+ /** Token counts */
218
+ tokens?: {
219
+ input?: number;
220
+ output?: number;
221
+ };
222
+ /** Total duration in milliseconds */
223
+ durationMs?: number;
224
+ /** Additional metadata */
225
+ metadata?: Record<string, any>;
226
+ }
227
+ declare class ForPromptLogger {
228
+ private baseUrl;
229
+ private apiKey;
230
+ private traceId;
231
+ private promptKey;
232
+ private versionNumber;
233
+ private source;
234
+ constructor(config?: {
235
+ apiKey?: string;
236
+ baseUrl?: string;
237
+ source?: string;
238
+ });
239
+ /**
240
+ * Start a new trace (conversation)
241
+ * Returns the generated traceId
242
+ *
243
+ * @param promptKey - The prompt identifier
244
+ * @param options.traceId - Optional custom trace ID (auto-generated if not provided)
245
+ * @param options.versionNumber - Prompt version number for analytics tracking
246
+ */
247
+ startTrace(promptKey: string, options?: {
248
+ traceId?: string;
249
+ versionNumber?: number;
250
+ }): string;
251
+ /**
252
+ * Log a span (message, LLM call, etc.)
253
+ * Automatically creates a trace if none exists
254
+ */
255
+ log(options: LogOptions): Promise<void>;
256
+ /**
257
+ * End the current trace
258
+ * This is optional - traces can be left open
259
+ */
260
+ endTrace(): Promise<void>;
261
+ /**
262
+ * Get the current version number
263
+ */
264
+ getVersionNumber(): number | null;
265
+ /**
266
+ * Get the current trace ID
267
+ */
268
+ getTraceId(): string | null;
269
+ /**
270
+ * Check if a trace is active
271
+ */
272
+ isTracing(): boolean;
273
+ /**
274
+ * Log a single AI request/response without conversation tracking
275
+ * Creates a new trace with input and output spans automatically
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * const { traceId } = await logger.logRequest({
280
+ * promptKey: "aicoaching",
281
+ * versionNumber: 2,
282
+ * input: "How do I learn Python?",
283
+ * output: "Here are 5 steps...",
284
+ * model: "gpt-4o",
285
+ * tokens: { input: 10, output: 150 },
286
+ * durationMs: 1200,
287
+ * });
288
+ * ```
289
+ */
290
+ logRequest(options: SingleRequestOptions): Promise<{
291
+ traceId: string;
292
+ }>;
293
+ }
294
+ /**
295
+ * Create a ForPrompt logger instance
296
+ */
297
+ declare function createLogger(config?: {
298
+ apiKey?: string;
299
+ baseUrl?: string;
300
+ source?: string;
301
+ }): ForPromptLogger;
302
+ /**
303
+ * Default logger instance
304
+ * Auto-configured from environment variables
305
+ */
306
+ declare const logger: ForPromptLogger;
307
+
308
+ export { ForPrompt, type ForPromptConfig, ForPromptError, ForPromptLogger, type GetPromptOptions, type LogOptions, type Prompt, type SingleRequestOptions, createForPrompt, createLogger, forprompt, logger };
@@ -0,0 +1,308 @@
1
+ /**
2
+ * ForPrompt SDK Types
3
+ */
4
+ interface ForPromptConfig {
5
+ /** API key from ForPrompt dashboard (required) */
6
+ apiKey: string;
7
+ /** Custom base URL (optional, defaults to https://wooden-fox-811.convex.site) */
8
+ baseUrl?: string;
9
+ }
10
+ interface Prompt {
11
+ /** Unique key identifier for the prompt */
12
+ key: string;
13
+ /** Display name of the prompt */
14
+ name: string;
15
+ /** Optional description */
16
+ description?: string;
17
+ /** Version number */
18
+ versionNumber: number;
19
+ /** The system prompt content */
20
+ systemPrompt: string;
21
+ /** Last update timestamp */
22
+ updatedAt: number;
23
+ /** Prompt information fields */
24
+ purpose?: string;
25
+ expectedBehavior?: string;
26
+ inputFormat?: string;
27
+ outputFormat?: string;
28
+ constraints?: string;
29
+ useCases?: string;
30
+ additionalNotes?: string;
31
+ toolsNotes?: string;
32
+ }
33
+ interface GetPromptOptions {
34
+ /** Specific version number to fetch (optional, defaults to active version) */
35
+ version?: number;
36
+ }
37
+ declare class ForPromptError extends Error {
38
+ statusCode: number;
39
+ code: string;
40
+ constructor(message: string, statusCode: number, code: string);
41
+ }
42
+
43
+ /**
44
+ * ForPrompt Client
45
+ *
46
+ * Simple usage with auto-configuration:
47
+ * @example
48
+ * ```typescript
49
+ * import { forprompt } from "@forprompt/sdk";
50
+ *
51
+ * // Auto-loads from FORPROMPT_API_KEY env variable
52
+ * const prompt = await forprompt.getPrompt("userContextPrompt");
53
+ * ```
54
+ */
55
+
56
+ /**
57
+ * Extended client configuration with security options
58
+ */
59
+ interface ForPromptClientConfig {
60
+ /** Project API key (required) */
61
+ apiKey: string;
62
+ /** Base URL for API (default: https://wooden-fox-811.convex.site) */
63
+ baseUrl?: string;
64
+ /** Request timeout in milliseconds (default: 30000) */
65
+ timeout?: number;
66
+ /** Number of retry attempts for failed requests (default: 3) */
67
+ retries?: number;
68
+ }
69
+ declare class ForPrompt {
70
+ private baseUrl;
71
+ private apiKey;
72
+ private timeout;
73
+ private retries;
74
+ constructor(config: ForPromptClientConfig | ForPromptConfig | {
75
+ apiKey: string;
76
+ baseUrl?: string;
77
+ });
78
+ /**
79
+ * Fetch with timeout support using AbortController
80
+ */
81
+ private fetchWithTimeout;
82
+ /**
83
+ * Fetch with retry and exponential backoff
84
+ */
85
+ private fetchWithRetry;
86
+ /**
87
+ * Get a prompt by its key
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const prompt = await forprompt.getPrompt("userContextPrompt");
92
+ * console.log(prompt.systemPrompt);
93
+ * ```
94
+ *
95
+ * @example With specific version
96
+ * ```typescript
97
+ * const prompt = await forprompt.getPrompt("userContextPrompt", { version: 2 });
98
+ * ```
99
+ */
100
+ getPrompt(key: string, options?: GetPromptOptions): Promise<Prompt>;
101
+ /**
102
+ * Get multiple prompts by their keys
103
+ *
104
+ * Requests are made in parallel with concurrency limit to avoid overwhelming the server.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const prompts = await forprompt.getPrompts(["userContext", "chatDefault"]);
109
+ * ```
110
+ */
111
+ getPrompts(keys: string[], options?: GetPromptOptions): Promise<Map<string, Prompt>>;
112
+ }
113
+ /**
114
+ * Create a ForPrompt client instance
115
+ *
116
+ * @example With explicit config
117
+ * ```typescript
118
+ * import { createForPrompt } from "@forprompt/sdk";
119
+ *
120
+ * const client = createForPrompt({
121
+ * apiKey: "fp_xxx",
122
+ * });
123
+ *
124
+ * const prompt = await client.getPrompt("userContextPrompt");
125
+ * ```
126
+ *
127
+ * @example With timeout and retry config
128
+ * ```typescript
129
+ * const client = createForPrompt({
130
+ * apiKey: "fp_xxx",
131
+ * timeout: 10000, // 10 seconds
132
+ * retries: 5,
133
+ * });
134
+ * ```
135
+ *
136
+ * @example Auto-config from environment
137
+ * ```typescript
138
+ * import { forprompt } from "@forprompt/sdk";
139
+ *
140
+ * // Uses FORPROMPT_API_KEY from environment
141
+ * const prompt = await forprompt.getPrompt("userContextPrompt");
142
+ * ```
143
+ */
144
+ declare function createForPrompt(config?: Partial<ForPromptClientConfig>): ForPrompt;
145
+ /**
146
+ * Default ForPrompt client instance
147
+ *
148
+ * Auto-configured from environment variables:
149
+ * - FORPROMPT_API_KEY: Your project API key
150
+ * - FORPROMPT_BASE_URL: Custom base URL (optional)
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * import { forprompt } from "@forprompt/sdk";
155
+ *
156
+ * const prompt = await forprompt.getPrompt("userContextPrompt");
157
+ * console.log(prompt.systemPrompt);
158
+ * ```
159
+ */
160
+ declare const forprompt: ForPrompt;
161
+
162
+ /**
163
+ * ForPrompt Logger
164
+ *
165
+ * Implements trace/span model for logging AI conversations
166
+ *
167
+ * @example Basic usage
168
+ * ```typescript
169
+ * import { logger } from "@forprompt/sdk";
170
+ *
171
+ * // Start a trace
172
+ * logger.startTrace("onboardingprompt");
173
+ *
174
+ * // Log user message
175
+ * await logger.log({ role: "user", content: "Hello" });
176
+ *
177
+ * // Log AI response
178
+ * await logger.log({
179
+ * role: "assistant",
180
+ * content: "Hi! How can I help?",
181
+ * model: "gpt-4o",
182
+ * tokens: { output: 120 }
183
+ * });
184
+ *
185
+ * // End trace (optional)
186
+ * logger.endTrace();
187
+ * ```
188
+ */
189
+ interface LogOptions {
190
+ role: "user" | "assistant" | "system";
191
+ content: string;
192
+ model?: string;
193
+ tokens?: {
194
+ input?: number;
195
+ output?: number;
196
+ };
197
+ durationMs?: number;
198
+ metadata?: Record<string, any>;
199
+ }
200
+ /**
201
+ * Options for logging a single AI request/response
202
+ * Use this for one-shot interactions without conversation tracking
203
+ */
204
+ interface SingleRequestOptions {
205
+ /** The prompt identifier */
206
+ promptKey: string;
207
+ /** Prompt version number for analytics tracking */
208
+ versionNumber?: number;
209
+ /** Optional custom trace ID (auto-generated if not provided) */
210
+ traceId?: string;
211
+ /** The user's input/prompt */
212
+ input: string;
213
+ /** The AI's output/response */
214
+ output: string;
215
+ /** The model used (e.g., "gpt-4o", "claude-sonnet-4") */
216
+ model?: string;
217
+ /** Token counts */
218
+ tokens?: {
219
+ input?: number;
220
+ output?: number;
221
+ };
222
+ /** Total duration in milliseconds */
223
+ durationMs?: number;
224
+ /** Additional metadata */
225
+ metadata?: Record<string, any>;
226
+ }
227
+ declare class ForPromptLogger {
228
+ private baseUrl;
229
+ private apiKey;
230
+ private traceId;
231
+ private promptKey;
232
+ private versionNumber;
233
+ private source;
234
+ constructor(config?: {
235
+ apiKey?: string;
236
+ baseUrl?: string;
237
+ source?: string;
238
+ });
239
+ /**
240
+ * Start a new trace (conversation)
241
+ * Returns the generated traceId
242
+ *
243
+ * @param promptKey - The prompt identifier
244
+ * @param options.traceId - Optional custom trace ID (auto-generated if not provided)
245
+ * @param options.versionNumber - Prompt version number for analytics tracking
246
+ */
247
+ startTrace(promptKey: string, options?: {
248
+ traceId?: string;
249
+ versionNumber?: number;
250
+ }): string;
251
+ /**
252
+ * Log a span (message, LLM call, etc.)
253
+ * Automatically creates a trace if none exists
254
+ */
255
+ log(options: LogOptions): Promise<void>;
256
+ /**
257
+ * End the current trace
258
+ * This is optional - traces can be left open
259
+ */
260
+ endTrace(): Promise<void>;
261
+ /**
262
+ * Get the current version number
263
+ */
264
+ getVersionNumber(): number | null;
265
+ /**
266
+ * Get the current trace ID
267
+ */
268
+ getTraceId(): string | null;
269
+ /**
270
+ * Check if a trace is active
271
+ */
272
+ isTracing(): boolean;
273
+ /**
274
+ * Log a single AI request/response without conversation tracking
275
+ * Creates a new trace with input and output spans automatically
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * const { traceId } = await logger.logRequest({
280
+ * promptKey: "aicoaching",
281
+ * versionNumber: 2,
282
+ * input: "How do I learn Python?",
283
+ * output: "Here are 5 steps...",
284
+ * model: "gpt-4o",
285
+ * tokens: { input: 10, output: 150 },
286
+ * durationMs: 1200,
287
+ * });
288
+ * ```
289
+ */
290
+ logRequest(options: SingleRequestOptions): Promise<{
291
+ traceId: string;
292
+ }>;
293
+ }
294
+ /**
295
+ * Create a ForPrompt logger instance
296
+ */
297
+ declare function createLogger(config?: {
298
+ apiKey?: string;
299
+ baseUrl?: string;
300
+ source?: string;
301
+ }): ForPromptLogger;
302
+ /**
303
+ * Default logger instance
304
+ * Auto-configured from environment variables
305
+ */
306
+ declare const logger: ForPromptLogger;
307
+
308
+ export { ForPrompt, type ForPromptConfig, ForPromptError, ForPromptLogger, type GetPromptOptions, type LogOptions, type Prompt, type SingleRequestOptions, createForPrompt, createLogger, forprompt, logger };