@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.
- package/LICENSE +661 -0
- package/README.md +302 -0
- package/dist/cli/index.js +3143 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.cjs +439 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +308 -0
- package/dist/index.d.ts +308 -0
- package/dist/index.js +406 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/chunk-2ABKAGKB.js +2145 -0
- package/dist/mcp/chunk-2ABKAGKB.js.map +1 -0
- package/dist/mcp/index.d.ts +36 -0
- package/dist/mcp/index.js +241 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +39 -0
- package/dist/mcp/server.js +10 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/version.cjs +118 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.cts +12 -0
- package/dist/version.d.ts +12 -0
- package/dist/version.js +91 -0
- package/dist/version.js.map +1 -0
- package/package.json +83 -0
package/README.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# @forprompt/sdk
|
|
2
|
+
|
|
3
|
+
Sync and manage AI prompts from your [ForPrompt](https://forprompt.dev) projects.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Simple CLI** - `init`, `deploy`, and `mcp` commands for easy setup
|
|
8
|
+
- **MCP Server** - Integrate with Claude Desktop, Cursor, Continue.dev, and more
|
|
9
|
+
- **Local files** - Prompts synced to TypeScript files for fast imports
|
|
10
|
+
- **Version history** - Track all prompt versions locally
|
|
11
|
+
- **Type-safe** - Full TypeScript support
|
|
12
|
+
- **Zero config** - Just API key in `.env`
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @forprompt/sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### 1. Initialize your project
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx forprompt init
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This will:
|
|
29
|
+
- Ask for your API key (get it from your ForPrompt Dashboard)
|
|
30
|
+
- Save it to `.env` file
|
|
31
|
+
- Create `forprompt/` directory
|
|
32
|
+
|
|
33
|
+
### 2. Deploy prompts
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx forprompt deploy
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Syncs all prompts from your ForPrompt project to local files.
|
|
40
|
+
|
|
41
|
+
### 3. Use in your code
|
|
42
|
+
|
|
43
|
+
**Option A: Import from local files (recommended)**
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { userContextPrompt } from "./forprompt";
|
|
47
|
+
|
|
48
|
+
// Or use the helper
|
|
49
|
+
import { getPrompt } from "./forprompt";
|
|
50
|
+
const prompt = getPrompt("userContextPrompt");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Option B: Fetch from API at runtime**
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { forprompt } from "@forprompt/sdk";
|
|
57
|
+
|
|
58
|
+
// Auto-loads from FORPROMPT_API_KEY environment variable
|
|
59
|
+
const prompt = await forprompt.getPrompt("userContextPrompt");
|
|
60
|
+
console.log(prompt.systemPrompt);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## CLI Commands
|
|
64
|
+
|
|
65
|
+
### `forprompt init`
|
|
66
|
+
|
|
67
|
+
Initialize ForPrompt in your project.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npx forprompt init
|
|
71
|
+
npx forprompt init --api-key=fp_xxx # Provide key directly
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### `forprompt deploy`
|
|
75
|
+
|
|
76
|
+
Sync prompts from server to local files.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx forprompt deploy
|
|
80
|
+
npx forprompt deploy --clean # Remove deleted prompts locally
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### `forprompt mcp`
|
|
84
|
+
|
|
85
|
+
MCP (Model Context Protocol) server for AI editor integration.
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npx forprompt mcp start # Start MCP server
|
|
89
|
+
npx forprompt mcp config --editor=claude-desktop # Generate Claude Desktop config
|
|
90
|
+
npx forprompt mcp config --editor=cursor # Generate Cursor config
|
|
91
|
+
npx forprompt mcp config --all # Generate all editor configs
|
|
92
|
+
npx forprompt mcp info # Show MCP server info
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Project Structure
|
|
96
|
+
|
|
97
|
+
After `forprompt deploy`:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
my-app/
|
|
101
|
+
├── .env # FORPROMPT_API_KEY=fp_xxx
|
|
102
|
+
├── forprompt/
|
|
103
|
+
│ ├── .forpromptrc # Project config
|
|
104
|
+
│ ├── index.ts # Exports all prompts
|
|
105
|
+
│ ├── userContextPrompt/
|
|
106
|
+
│ │ ├── prompt.ts # export const userContextPrompt = "..."
|
|
107
|
+
│ │ ├── metadata.json # Version info
|
|
108
|
+
│ │ └── versions/
|
|
109
|
+
│ │ ├── v1.txt
|
|
110
|
+
│ │ └── v2.txt
|
|
111
|
+
│ └── chatDefaultPrompt/
|
|
112
|
+
│ └── ...
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## SDK API
|
|
116
|
+
|
|
117
|
+
### Auto-configured client
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { forprompt } from "@forprompt/sdk";
|
|
121
|
+
|
|
122
|
+
// Uses FORPROMPT_API_KEY from environment
|
|
123
|
+
const prompt = await forprompt.getPrompt("userContextPrompt");
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Custom client
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { createForPrompt } from "@forprompt/sdk";
|
|
130
|
+
|
|
131
|
+
const client = createForPrompt({
|
|
132
|
+
apiKey: "fp_xxx",
|
|
133
|
+
baseUrl: "https://wooden-fox-811.convex.site", // Optional: Custom backend URL
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const prompt = await client.getPrompt("userContextPrompt");
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Get specific version
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const promptV2 = await forprompt.getPrompt("userContextPrompt", { version: 2 });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Environment Variables
|
|
146
|
+
|
|
147
|
+
| Variable | Description |
|
|
148
|
+
|----------|-------------|
|
|
149
|
+
| `FORPROMPT_API_KEY` | Your project API key (required) |
|
|
150
|
+
| `FORPROMPT_BASE_URL` | Custom API URL (optional) |
|
|
151
|
+
|
|
152
|
+
## Logging
|
|
153
|
+
|
|
154
|
+
Track AI conversations with automatic tracing.
|
|
155
|
+
|
|
156
|
+
### Conversation Logging (Multi-turn)
|
|
157
|
+
|
|
158
|
+
For multi-turn conversations where messages share the same trace:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { logger } from "@forprompt/sdk";
|
|
162
|
+
|
|
163
|
+
// Start a trace
|
|
164
|
+
const traceId = logger.startTrace("onboarding", {
|
|
165
|
+
versionNumber: 2 // Track prompt version
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Log user message
|
|
169
|
+
await logger.log({ role: "user", content: "Hello" });
|
|
170
|
+
|
|
171
|
+
// Log AI response
|
|
172
|
+
await logger.log({
|
|
173
|
+
role: "assistant",
|
|
174
|
+
content: "Hi! How can I help?",
|
|
175
|
+
model: "gpt-4o",
|
|
176
|
+
tokens: { input: 10, output: 50 },
|
|
177
|
+
durationMs: 1200
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// End trace (optional)
|
|
181
|
+
await logger.endTrace();
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Single Request Logging
|
|
185
|
+
|
|
186
|
+
For one-shot AI requests without conversation tracking:
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { createLogger } from "@forprompt/sdk";
|
|
190
|
+
|
|
191
|
+
const logger = createLogger({ apiKey: "fp_proj_xxx" });
|
|
192
|
+
|
|
193
|
+
// Log a single request/response pair
|
|
194
|
+
const { traceId } = await logger.logRequest({
|
|
195
|
+
promptKey: "aicoaching",
|
|
196
|
+
versionNumber: 2,
|
|
197
|
+
input: "How do I learn Python?",
|
|
198
|
+
output: "Here are 5 steps...",
|
|
199
|
+
model: "gpt-4o",
|
|
200
|
+
tokens: { input: 10, output: 150 },
|
|
201
|
+
durationMs: 1200
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### When to Use Each Mode
|
|
206
|
+
|
|
207
|
+
| Mode | Method | Use Case |
|
|
208
|
+
|------|--------|----------|
|
|
209
|
+
| **Conversation** | `startTrace()` + `log()` | Multi-turn chats, chatbots, context-dependent conversations |
|
|
210
|
+
| **Single Request** | `logRequest()` | One-shot API calls, batch processing, simple Q&A |
|
|
211
|
+
|
|
212
|
+
## TypeScript
|
|
213
|
+
|
|
214
|
+
Full type definitions included:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import type { Prompt, ForPromptConfig, LogOptions, SingleRequestOptions } from "@forprompt/sdk";
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Workflow
|
|
221
|
+
|
|
222
|
+
1. Create/edit prompts in [ForPrompt Dashboard](https://forprompt.dev)
|
|
223
|
+
2. Run `npx forprompt deploy` to sync locally
|
|
224
|
+
3. Commit the `forprompt/` folder to version control
|
|
225
|
+
4. Import prompts directly in your code
|
|
226
|
+
|
|
227
|
+
## MCP Server Integration
|
|
228
|
+
|
|
229
|
+
ForPrompt includes an MCP (Model Context Protocol) server that exposes your prompts to AI assistants like Claude Desktop, Cursor, Continue.dev, and other MCP-compatible tools.
|
|
230
|
+
|
|
231
|
+
### Quick Setup for Claude Desktop
|
|
232
|
+
|
|
233
|
+
1. Run the config generator:
|
|
234
|
+
```bash
|
|
235
|
+
npx forprompt mcp config --editor=claude-desktop
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
2. Follow the instructions to add the config to your Claude Desktop settings
|
|
239
|
+
|
|
240
|
+
3. Restart Claude Desktop
|
|
241
|
+
|
|
242
|
+
4. Your prompts are now available! Ask Claude to "list my ForPrompt prompts"
|
|
243
|
+
|
|
244
|
+
### Quick Setup for Cursor
|
|
245
|
+
|
|
246
|
+
1. Run the config generator:
|
|
247
|
+
```bash
|
|
248
|
+
npx forprompt mcp config --editor=cursor
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
2. The config will be saved to `.cursor/mcp.json` in your project
|
|
252
|
+
|
|
253
|
+
3. Restart Cursor
|
|
254
|
+
|
|
255
|
+
### Manual Configuration
|
|
256
|
+
|
|
257
|
+
Add to your editor's MCP config file:
|
|
258
|
+
|
|
259
|
+
```json
|
|
260
|
+
{
|
|
261
|
+
"mcpServers": {
|
|
262
|
+
"forprompt": {
|
|
263
|
+
"command": "npx",
|
|
264
|
+
"args": ["-y", "@forprompt/sdk", "mcp", "start"],
|
|
265
|
+
"env": {
|
|
266
|
+
"FORPROMPT_API_KEY": "your-api-key"
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Available MCP Tools
|
|
274
|
+
|
|
275
|
+
| Tool | Description |
|
|
276
|
+
|------|-------------|
|
|
277
|
+
| `forprompt_get_prompt` | Fetch a prompt by its key |
|
|
278
|
+
| `forprompt_list_prompts` | List all available prompts |
|
|
279
|
+
| `forprompt_search_prompts` | Search prompts by text |
|
|
280
|
+
| `forprompt_get_prompt_metadata` | Get prompt metadata only |
|
|
281
|
+
| `forprompt_get_system_prompt` | Get raw system prompt text |
|
|
282
|
+
|
|
283
|
+
### Available MCP Resources
|
|
284
|
+
|
|
285
|
+
| URI | Description |
|
|
286
|
+
|-----|-------------|
|
|
287
|
+
| `forprompt://prompts` | List all prompts |
|
|
288
|
+
| `forprompt://prompts/{key}` | Get a specific prompt |
|
|
289
|
+
| `forprompt://prompts/{key}/v{n}` | Get a specific version |
|
|
290
|
+
| `forprompt://prompts/{key}/metadata` | Get metadata only |
|
|
291
|
+
|
|
292
|
+
### Supported Editors
|
|
293
|
+
|
|
294
|
+
- **Claude Desktop** - Anthropic's Claude desktop application
|
|
295
|
+
- **Cursor** - AI-powered code editor
|
|
296
|
+
- **Continue.dev** - Open-source AI code assistant
|
|
297
|
+
- **Windsurf** - AI-powered IDE
|
|
298
|
+
- **VS Code** - With MCP-compatible extensions
|
|
299
|
+
|
|
300
|
+
## License
|
|
301
|
+
|
|
302
|
+
MIT
|