playingpack 0.2.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 +90 -0
- package/README.md +500 -0
- package/dist/config-helper.d.ts +46 -0
- package/dist/config-helper.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +7 -0
- package/package.json +81 -0
- package/public/assets/index-D239zB28.css +1 -0
- package/public/assets/index-D6X1cCDc.js +86 -0
- package/public/favicon.svg +4 -0
- package/public/index.html +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Parameters
|
|
4
|
+
|
|
5
|
+
Licensor: Geoptly Intelligence Inc.
|
|
6
|
+
Licensed Work: playingpack
|
|
7
|
+
The Licensed Work is (c) 2025 Geoptly Intelligence Inc.
|
|
8
|
+
Additional Use Grant: None
|
|
9
|
+
Change Date: 2099-12-31
|
|
10
|
+
Change License: Apache License, Version 2.0
|
|
11
|
+
|
|
12
|
+
Notice
|
|
13
|
+
|
|
14
|
+
The Business Source License (this document, or the "License") is not an Open
|
|
15
|
+
Source license. However, the Licensed Work will eventually be made available
|
|
16
|
+
under an Open Source License, as stated in this License.
|
|
17
|
+
|
|
18
|
+
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
|
|
19
|
+
"Business Source License" is a trademark of MariaDB Corporation Ab.
|
|
20
|
+
|
|
21
|
+
-----------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
Business Source License 1.1
|
|
24
|
+
|
|
25
|
+
Terms
|
|
26
|
+
|
|
27
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
28
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
29
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
30
|
+
production use.
|
|
31
|
+
|
|
32
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
33
|
+
available distribution of a specific version of the Licensed Work under this
|
|
34
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
35
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
36
|
+
above terminate.
|
|
37
|
+
|
|
38
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
39
|
+
currently in effect as described in this License, you must purchase a
|
|
40
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
41
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
42
|
+
|
|
43
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
44
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
45
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
46
|
+
for each version of the Licensed Work released by Licensor.
|
|
47
|
+
|
|
48
|
+
You must conspicuously display this License on each original or modified copy
|
|
49
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
50
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
51
|
+
License apply to your use of that work.
|
|
52
|
+
|
|
53
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
54
|
+
terminate your rights under this License for the current and all other
|
|
55
|
+
versions of the Licensed Work.
|
|
56
|
+
|
|
57
|
+
This License does not grant you any right in any trademark or logo of
|
|
58
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
59
|
+
Licensor as expressly required by this License).
|
|
60
|
+
|
|
61
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
62
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
63
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
64
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
65
|
+
TITLE.
|
|
66
|
+
|
|
67
|
+
MariaDB hereby grants you permission to use this License's text to license
|
|
68
|
+
your works, and to refer to it using the trademark "Business Source License",
|
|
69
|
+
as long as you comply with the Covenants of Licensor below.
|
|
70
|
+
|
|
71
|
+
Covenants of Licensor
|
|
72
|
+
|
|
73
|
+
In consideration of the right to use this License's text and the "Business
|
|
74
|
+
Source License" name and trademark, Licensor covenants to MariaDB, and to all
|
|
75
|
+
other recipients of the licensed work to be provided by Licensor:
|
|
76
|
+
|
|
77
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
78
|
+
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
79
|
+
where "compatible" means that software provided under the Change License
|
|
80
|
+
can be included in a program with software provided under GPL Version 2.0
|
|
81
|
+
or a later version. Licensor may specify additional Change Licenses
|
|
82
|
+
without limitation.
|
|
83
|
+
|
|
84
|
+
2. To either: (a) specify an additional grant of rights to use that does not
|
|
85
|
+
impose any additional restriction on the right granted in this License, as
|
|
86
|
+
the Additional Use Grant; or (b) insert the text "None".
|
|
87
|
+
|
|
88
|
+
3. To specify a Change Date.
|
|
89
|
+
|
|
90
|
+
4. Not to modify this License in any other way.
|
package/README.md
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
# PlayingPack
|
|
2
|
+
|
|
3
|
+
[](https://github.com/geoptly/playingpack/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/playingpack)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
**Chrome DevTools for AI Agents** — A local reverse proxy and debugger for intercepting, recording, and replaying LLM API calls.
|
|
8
|
+
|
|
9
|
+
Point your AI agent at PlayingPack instead of your LLM provider, and get a real-time dashboard to watch requests, pause on tool calls, inject mock responses, and replay cached responses with zero latency and zero cost.
|
|
10
|
+
|
|
11
|
+
Works with any OpenAI API-compatible provider: OpenAI, Ollama, Azure OpenAI, LiteLLM, vLLM, and more.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Why PlayingPack?
|
|
16
|
+
|
|
17
|
+
Building AI agents is painful:
|
|
18
|
+
|
|
19
|
+
- **Expensive iteration** — Every test run burns API credits. Debugging a single edge case can cost dollars.
|
|
20
|
+
- **Non-deterministic behavior** — LLMs return different responses each time, making tests flaky and debugging a guessing game.
|
|
21
|
+
- **Blind debugging** — You can't see what tool calls the agent made or why it chose a particular action.
|
|
22
|
+
- **Slow feedback loops** — Waiting seconds for API responses on every iteration kills productivity.
|
|
23
|
+
- **CI/CD nightmares** — You can't run reliable automated tests against a non-deterministic, rate-limited API.
|
|
24
|
+
|
|
25
|
+
PlayingPack solves these problems:
|
|
26
|
+
|
|
27
|
+
| Problem | Solution |
|
|
28
|
+
|---------|----------|
|
|
29
|
+
| Expensive iteration | **VCR Mode** — Record once, replay forever. Zero API costs after first run. |
|
|
30
|
+
| Non-deterministic tests | **Tape playback** — Same request always returns same response. Deterministic by design. |
|
|
31
|
+
| Blind debugging | **Interceptor** — Pause on tool calls, inspect payloads, see exactly what the LLM decided. |
|
|
32
|
+
| Slow feedback | **Instant replay** — Cached responses return in milliseconds, not seconds. |
|
|
33
|
+
| CI/CD reliability | **Replay-only mode** — Run tests against recorded tapes. Fast, free, deterministic. |
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
### VCR Mode
|
|
40
|
+
Record API responses and replay them deterministically. First request hits the real API and saves a "tape." Subsequent identical requests replay from cache with original timing preserved.
|
|
41
|
+
|
|
42
|
+
### Real-time Dashboard
|
|
43
|
+
Browser-based UI showing live request streaming, status updates, request/response inspection with syntax highlighting, and full history.
|
|
44
|
+
|
|
45
|
+
### Interceptor
|
|
46
|
+
Pause requests when tool calls are detected. Inspect the exact function name and arguments. Decide whether to allow the request to continue or inject a mock response.
|
|
47
|
+
|
|
48
|
+
### Mock Editor
|
|
49
|
+
Monaco-powered JSON editor for crafting custom responses. Test error scenarios, edge cases, or specific tool call results without touching the real API.
|
|
50
|
+
|
|
51
|
+
### SSE Streaming
|
|
52
|
+
Full OpenAI-compatible streaming with proper chunk handling. Parses tool calls in real-time. Works exactly like the real API.
|
|
53
|
+
|
|
54
|
+
### Multi-Provider Support
|
|
55
|
+
Drop-in replacement for any OpenAI API-compatible endpoint:
|
|
56
|
+
- OpenAI
|
|
57
|
+
- Ollama (local LLMs)
|
|
58
|
+
- Azure OpenAI
|
|
59
|
+
- LiteLLM
|
|
60
|
+
- vLLM
|
|
61
|
+
- Any compatible endpoint
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Requirements
|
|
66
|
+
|
|
67
|
+
- **Node.js 20+**
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# npm
|
|
75
|
+
npm install -g playingpack
|
|
76
|
+
|
|
77
|
+
# pnpm
|
|
78
|
+
pnpm add -g playingpack
|
|
79
|
+
|
|
80
|
+
# yarn
|
|
81
|
+
yarn global add playingpack
|
|
82
|
+
|
|
83
|
+
# Or run directly with npx (no install)
|
|
84
|
+
npx playingpack start
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Quick Start
|
|
90
|
+
|
|
91
|
+
### 1. Start the proxy
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npx playingpack start
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 2. Point your agent at PlayingPack
|
|
98
|
+
|
|
99
|
+
**Python (OpenAI SDK)**
|
|
100
|
+
```python
|
|
101
|
+
from openai import OpenAI
|
|
102
|
+
|
|
103
|
+
client = OpenAI(
|
|
104
|
+
base_url="http://localhost:4747/v1",
|
|
105
|
+
api_key="your-api-key" # Still needed for upstream
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
response = client.chat.completions.create(
|
|
109
|
+
model="gpt-4",
|
|
110
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
111
|
+
)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**TypeScript/JavaScript**
|
|
115
|
+
```typescript
|
|
116
|
+
import OpenAI from 'openai';
|
|
117
|
+
|
|
118
|
+
const client = new OpenAI({
|
|
119
|
+
baseURL: 'http://localhost:4747/v1',
|
|
120
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const response = await client.chat.completions.create({
|
|
124
|
+
model: 'gpt-4',
|
|
125
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**cURL**
|
|
130
|
+
```bash
|
|
131
|
+
curl http://localhost:4747/v1/chat/completions \
|
|
132
|
+
-H "Content-Type: application/json" \
|
|
133
|
+
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
|
134
|
+
-d '{
|
|
135
|
+
"model": "gpt-4",
|
|
136
|
+
"messages": [{"role": "user", "content": "Hello!"}]
|
|
137
|
+
}'
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 3. Open the dashboard
|
|
141
|
+
|
|
142
|
+
Navigate to [http://localhost:4747](http://localhost:4747) in your browser.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Use Cases
|
|
147
|
+
|
|
148
|
+
### Deterministic Testing
|
|
149
|
+
|
|
150
|
+
Record your agent's API interactions once, then replay them in tests forever:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# First run: records responses to .playingpack/tapes/
|
|
154
|
+
npx playingpack start &
|
|
155
|
+
pytest tests/
|
|
156
|
+
|
|
157
|
+
# Subsequent runs: replays from cache (instant, free)
|
|
158
|
+
npx playingpack start --record replay-only &
|
|
159
|
+
pytest tests/
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Your tests become:
|
|
163
|
+
- **Fast** — Milliseconds instead of seconds per request
|
|
164
|
+
- **Free** — Zero API costs after initial recording
|
|
165
|
+
- **Deterministic** — Same input always produces same output
|
|
166
|
+
- **Offline-capable** — No network required
|
|
167
|
+
|
|
168
|
+
### Debugging Agent Behavior
|
|
169
|
+
|
|
170
|
+
Enable pause mode to stop on tool calls and inspect what your agent is doing:
|
|
171
|
+
|
|
172
|
+
1. Start PlayingPack and open the dashboard
|
|
173
|
+
2. Toggle "Pause on tool calls" in the UI
|
|
174
|
+
3. Run your agent
|
|
175
|
+
4. When a tool call is detected, the request pauses
|
|
176
|
+
5. Inspect the function name, arguments, and full context
|
|
177
|
+
6. Click "Allow" to continue or "Mock" to inject a custom response
|
|
178
|
+
|
|
179
|
+
### CI/CD Integration
|
|
180
|
+
|
|
181
|
+
Run your test suite against recorded tapes in CI:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
# In your CI pipeline
|
|
185
|
+
npx playingpack start --no-ui --record replay-only &
|
|
186
|
+
sleep 2 # Wait for server
|
|
187
|
+
npm test
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
If a tape is missing, the request fails immediately — no surprise API calls in CI.
|
|
191
|
+
|
|
192
|
+
```yaml
|
|
193
|
+
# Example GitHub Actions step
|
|
194
|
+
- name: Run tests with PlayingPack
|
|
195
|
+
run: |
|
|
196
|
+
npx playingpack start --no-ui --record replay-only &
|
|
197
|
+
sleep 2
|
|
198
|
+
npm test
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Local Development with Ollama
|
|
202
|
+
|
|
203
|
+
Proxy to a local LLM for free, fast development:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Start Ollama
|
|
207
|
+
ollama serve
|
|
208
|
+
|
|
209
|
+
# Point PlayingPack at Ollama
|
|
210
|
+
npx playingpack start --upstream http://localhost:11434/v1
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Now your agent talks to your local LLM through PlayingPack, and you still get recording, replay, and debugging.
|
|
214
|
+
|
|
215
|
+
### Cost Reduction
|
|
216
|
+
|
|
217
|
+
During development, avoid burning through API credits:
|
|
218
|
+
|
|
219
|
+
1. Record a representative set of interactions
|
|
220
|
+
2. Iterate on your agent logic using cached responses
|
|
221
|
+
3. Only hit the real API when you need fresh recordings
|
|
222
|
+
|
|
223
|
+
Typical savings: 90%+ reduction in API costs during development.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Configuration
|
|
228
|
+
|
|
229
|
+
Create `playingpack.config.ts` (or `.js`, `.mjs`) in your project root:
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { defineConfig } from 'playingpack';
|
|
233
|
+
|
|
234
|
+
export default defineConfig({
|
|
235
|
+
// Upstream API endpoint (default: https://api.openai.com)
|
|
236
|
+
upstream: process.env.LLM_API_URL ?? 'https://api.openai.com',
|
|
237
|
+
|
|
238
|
+
// Directory for tape storage (default: .playingpack/tapes)
|
|
239
|
+
tapesDir: '.playingpack/tapes',
|
|
240
|
+
|
|
241
|
+
// Directory for logs (default: .playingpack/logs)
|
|
242
|
+
logsDir: '.playingpack/logs',
|
|
243
|
+
|
|
244
|
+
// Recording mode: 'auto' | 'off' | 'replay-only' (default: auto)
|
|
245
|
+
// - auto: Record if no tape exists, replay if it does
|
|
246
|
+
// - off: Always hit upstream, never record
|
|
247
|
+
// - replay-only: Only replay from cache, fail if tape missing
|
|
248
|
+
record: process.env.CI ? 'replay-only' : 'auto',
|
|
249
|
+
|
|
250
|
+
// Server port (default: 4747)
|
|
251
|
+
port: 4747,
|
|
252
|
+
|
|
253
|
+
// Server host (default: 0.0.0.0)
|
|
254
|
+
host: '0.0.0.0',
|
|
255
|
+
|
|
256
|
+
// Run without UI in CI environments (default: false)
|
|
257
|
+
headless: !!process.env.CI,
|
|
258
|
+
|
|
259
|
+
// Pause mode: 'off' | 'tool-calls' | 'all' (default: off)
|
|
260
|
+
// - off: No interception, requests flow through normally
|
|
261
|
+
// - tool-calls: Pause when LLM makes a tool/function call
|
|
262
|
+
// - all: Pause on every request
|
|
263
|
+
pause: 'off',
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Environment-Aware Configuration
|
|
268
|
+
|
|
269
|
+
Using a JS/TS config file allows dynamic configuration based on environment:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { defineConfig } from 'playingpack';
|
|
273
|
+
|
|
274
|
+
export default defineConfig({
|
|
275
|
+
// Use different upstream for local vs CI
|
|
276
|
+
upstream: process.env.CI
|
|
277
|
+
? 'https://api.openai.com'
|
|
278
|
+
: 'http://localhost:11434/v1',
|
|
279
|
+
|
|
280
|
+
// CI: replay-only (fast, deterministic), Local: auto (record on miss)
|
|
281
|
+
record: process.env.CI ? 'replay-only' : 'auto',
|
|
282
|
+
|
|
283
|
+
// No UI needed in CI
|
|
284
|
+
headless: !!process.env.CI,
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Supported Config Files
|
|
289
|
+
|
|
290
|
+
Config files are loaded in this order (first found wins):
|
|
291
|
+
|
|
292
|
+
1. `playingpack.config.ts` (recommended)
|
|
293
|
+
2. `playingpack.config.mts`
|
|
294
|
+
3. `playingpack.config.js`
|
|
295
|
+
4. `playingpack.config.mjs`
|
|
296
|
+
5. `playingpack.config.jsonc` (legacy)
|
|
297
|
+
6. `playingpack.config.json` (legacy)
|
|
298
|
+
|
|
299
|
+
CLI flags override config file values.
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## CLI Reference
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
npx playingpack start [options]
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
| Option | Description | Default |
|
|
310
|
+
|--------|-------------|---------|
|
|
311
|
+
| `-p, --port <port>` | Port to listen on | `4747` |
|
|
312
|
+
| `-h, --host <host>` | Host to bind to | `0.0.0.0` |
|
|
313
|
+
| `--no-ui` | Run without UI (headless mode) | `false` |
|
|
314
|
+
| `--upstream <url>` | Upstream API URL | `https://api.openai.com` |
|
|
315
|
+
| `--tapes-dir <path>` | Directory for tape storage | `.playingpack/tapes` |
|
|
316
|
+
| `--record <mode>` | Recording mode (`auto`, `off`, `replay-only`) | `auto` |
|
|
317
|
+
|
|
318
|
+
### Examples
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
# Proxy to a local LLM (Ollama)
|
|
322
|
+
npx playingpack start --upstream http://localhost:11434/v1
|
|
323
|
+
|
|
324
|
+
# CI mode: replay only, no UI, fail if tape missing
|
|
325
|
+
npx playingpack start --no-ui --record replay-only
|
|
326
|
+
|
|
327
|
+
# Custom port and tapes directory
|
|
328
|
+
npx playingpack start --port 8080 --tapes-dir ./test/fixtures/tapes
|
|
329
|
+
|
|
330
|
+
# Production OpenAI with custom tapes location
|
|
331
|
+
npx playingpack start --tapes-dir ./recordings
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## How It Works
|
|
337
|
+
|
|
338
|
+
### Architecture
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
Your Agent → PlayingPack (localhost:4747) → Upstream API
|
|
342
|
+
↓
|
|
343
|
+
Dashboard UI
|
|
344
|
+
- View requests in real-time
|
|
345
|
+
- Pause & inspect tool calls
|
|
346
|
+
- Mock responses
|
|
347
|
+
- Replay from cache
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Request Flow
|
|
351
|
+
|
|
352
|
+
1. **Request arrives** at `POST /v1/chat/completions`
|
|
353
|
+
2. **Cache lookup** — Request body is normalized and hashed (SHA-256)
|
|
354
|
+
3. **Cache hit?** → Replay tape with original timing
|
|
355
|
+
4. **Cache miss?** → Forward to upstream, stream response, record tape
|
|
356
|
+
5. **Tool call detected?** → Optionally pause for inspection
|
|
357
|
+
6. **Response complete** → Save tape, notify dashboard
|
|
358
|
+
|
|
359
|
+
### State Machine
|
|
360
|
+
|
|
361
|
+
```
|
|
362
|
+
LOOKUP → (cache hit) → REPLAY → COMPLETE
|
|
363
|
+
↘ (cache miss) → CONNECT → STREAMING → COMPLETE
|
|
364
|
+
↓ (tool call + pause enabled)
|
|
365
|
+
INTERCEPT
|
|
366
|
+
↓
|
|
367
|
+
┌────────────┴────────────┐
|
|
368
|
+
↓ ↓
|
|
369
|
+
FLUSH (allow) INJECT (mock)
|
|
370
|
+
↓ ↓
|
|
371
|
+
COMPLETE COMPLETE
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
### Tape Format
|
|
375
|
+
|
|
376
|
+
Tapes are stored as JSON files named by request hash:
|
|
377
|
+
|
|
378
|
+
```json
|
|
379
|
+
{
|
|
380
|
+
"meta": {
|
|
381
|
+
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
382
|
+
"hash": "a1b2c3d4e5f6...",
|
|
383
|
+
"timestamp": "2025-01-13T10:30:00.000Z",
|
|
384
|
+
"model": "gpt-4",
|
|
385
|
+
"endpoint": "/v1/chat/completions"
|
|
386
|
+
},
|
|
387
|
+
"request": {
|
|
388
|
+
"body": { "model": "gpt-4", "messages": [...] }
|
|
389
|
+
},
|
|
390
|
+
"response": {
|
|
391
|
+
"status": 200,
|
|
392
|
+
"chunks": [
|
|
393
|
+
{ "c": "data: {\"id\":\"chatcmpl-...\"}\n\n", "d": 50 },
|
|
394
|
+
{ "c": "data: {\"id\":\"chatcmpl-...\"}\n\n", "d": 30 },
|
|
395
|
+
{ "c": "data: [DONE]\n\n", "d": 10 }
|
|
396
|
+
]
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
- `c` = chunk content (SSE data)
|
|
402
|
+
- `d` = delay in milliseconds since previous chunk
|
|
403
|
+
|
|
404
|
+
### Request Hashing
|
|
405
|
+
|
|
406
|
+
Requests are normalized before hashing to ensure deterministic matching:
|
|
407
|
+
- Keys are sorted alphabetically
|
|
408
|
+
- `stream` parameter is ignored (streaming and non-streaming match)
|
|
409
|
+
- Timestamps and request IDs are removed
|
|
410
|
+
- Result: SHA-256 hash used as tape filename
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
## API Endpoints
|
|
415
|
+
|
|
416
|
+
| Endpoint | Description |
|
|
417
|
+
|----------|-------------|
|
|
418
|
+
| `POST /v1/chat/completions` | OpenAI-compatible chat endpoint (proxied) |
|
|
419
|
+
| `GET /v1/*` | Other OpenAI endpoints (passthrough) |
|
|
420
|
+
| `GET /ws` | WebSocket for real-time dashboard updates |
|
|
421
|
+
| `ALL /api/trpc/*` | TRPC API for dashboard |
|
|
422
|
+
| `GET /health` | Health check |
|
|
423
|
+
| `GET /` | Dashboard UI |
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
## Development
|
|
428
|
+
|
|
429
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for full details.
|
|
430
|
+
|
|
431
|
+
```bash
|
|
432
|
+
# Clone and install
|
|
433
|
+
git clone https://github.com/geoptly/playingpack.git
|
|
434
|
+
cd playingpack
|
|
435
|
+
pnpm install
|
|
436
|
+
|
|
437
|
+
# Run in development mode (hot reload)
|
|
438
|
+
pnpm dev
|
|
439
|
+
|
|
440
|
+
# Run tests
|
|
441
|
+
pnpm test
|
|
442
|
+
|
|
443
|
+
# Type check
|
|
444
|
+
pnpm typecheck
|
|
445
|
+
|
|
446
|
+
# Lint and format
|
|
447
|
+
pnpm lint
|
|
448
|
+
pnpm format
|
|
449
|
+
|
|
450
|
+
# Build for production
|
|
451
|
+
pnpm run build:all
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Project Structure
|
|
455
|
+
|
|
456
|
+
```
|
|
457
|
+
playingpack/
|
|
458
|
+
├── packages/
|
|
459
|
+
│ ├── shared/ # TypeScript types & Zod schemas
|
|
460
|
+
│ ├── cli/ # Fastify proxy server + CLI
|
|
461
|
+
│ │ ├── proxy/ # HTTP routing, upstream client, SSE parsing
|
|
462
|
+
│ │ ├── tape/ # Recording & playback
|
|
463
|
+
│ │ ├── interceptor/ # Session state machine
|
|
464
|
+
│ │ ├── mock/ # Synthetic response generation
|
|
465
|
+
│ │ ├── trpc/ # API procedures
|
|
466
|
+
│ │ └── websocket/ # Real-time events
|
|
467
|
+
│ └── web/ # React dashboard
|
|
468
|
+
│ ├── components/
|
|
469
|
+
│ ├── stores/ # Zustand state
|
|
470
|
+
│ └── lib/ # TRPC & WebSocket clients
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
## FAQ
|
|
476
|
+
|
|
477
|
+
**Q: Does PlayingPack modify my requests?**
|
|
478
|
+
A: No. Requests are forwarded to upstream unchanged. The only modification is adding proxy headers for debugging.
|
|
479
|
+
|
|
480
|
+
**Q: Can I use this in production?**
|
|
481
|
+
A: PlayingPack is designed for development and testing. For production, point your agents directly at your LLM provider.
|
|
482
|
+
|
|
483
|
+
**Q: How do I update recordings when my prompts change?**
|
|
484
|
+
A: Delete the relevant tapes from `.playingpack/tapes/` and run your tests again. New tapes will be recorded automatically.
|
|
485
|
+
|
|
486
|
+
**Q: Does it work with function calling / tool use?**
|
|
487
|
+
A: Yes. PlayingPack fully supports OpenAI's function calling and tool use. The interceptor can pause specifically on tool calls for inspection.
|
|
488
|
+
|
|
489
|
+
**Q: Can I share tapes with my team?**
|
|
490
|
+
A: Yes. Commit your `.playingpack/tapes/` directory to version control. Everyone on the team gets the same deterministic behavior.
|
|
491
|
+
|
|
492
|
+
---
|
|
493
|
+
|
|
494
|
+
## License
|
|
495
|
+
|
|
496
|
+
[BUSL-1.1](LICENSE) (Business Source License)
|
|
497
|
+
|
|
498
|
+
Copyright 2025 Geoptly Intelligence Inc.
|
|
499
|
+
|
|
500
|
+
The Licensed Work is provided for non-production use. For production use, please contact us for a commercial license.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration helper for PlayingPack
|
|
3
|
+
* Users can import { defineConfig } from 'playingpack'
|
|
4
|
+
*/
|
|
5
|
+
/** Recording mode for VCR */
|
|
6
|
+
type RecordMode = 'auto' | 'off' | 'replay-only';
|
|
7
|
+
/** Pause mode for interceptor */
|
|
8
|
+
type PauseMode = 'off' | 'tool-calls' | 'all';
|
|
9
|
+
/** PlayingPack configuration options */
|
|
10
|
+
interface PlayingPackUserConfig {
|
|
11
|
+
/** Upstream API URL (default: https://api.openai.com) */
|
|
12
|
+
upstream?: string;
|
|
13
|
+
/** Directory for tape storage (default: .playingpack/tapes) */
|
|
14
|
+
tapesDir?: string;
|
|
15
|
+
/** Directory for log files (default: .playingpack/logs) */
|
|
16
|
+
logsDir?: string;
|
|
17
|
+
/** Recording mode (default: auto) */
|
|
18
|
+
record?: RecordMode;
|
|
19
|
+
/** Run without UI (default: false) */
|
|
20
|
+
headless?: boolean;
|
|
21
|
+
/** Port to listen on (default: 4747) */
|
|
22
|
+
port?: number;
|
|
23
|
+
/** Host to bind to (default: 0.0.0.0) */
|
|
24
|
+
host?: string;
|
|
25
|
+
/** Pause mode: "off" | "tool-calls" | "all" (default: off) */
|
|
26
|
+
pause?: PauseMode;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Helper function for creating type-safe configuration.
|
|
30
|
+
* Provides autocomplete and validation for config files.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* // playingpack.config.ts
|
|
35
|
+
* import { defineConfig } from 'playingpack';
|
|
36
|
+
*
|
|
37
|
+
* export default defineConfig({
|
|
38
|
+
* upstream: process.env.LLM_API_URL ?? 'https://api.openai.com',
|
|
39
|
+
* record: process.env.CI ? 'replay-only' : 'auto',
|
|
40
|
+
* headless: !!process.env.CI,
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function defineConfig(config: PlayingPackUserConfig): PlayingPackUserConfig;
|
|
45
|
+
|
|
46
|
+
export { type PauseMode, type PlayingPackUserConfig, type RecordMode, defineConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function o(e){return e}export{o as defineConfig};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|