You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In browser or client-side code, keep provider credentials on the server. Use the rendered request body with your own server endpoint, server action, or edge function rather than calling a provider directly from the client.
209
+
210
+
On the server, adapters also provide async prompt-aware helpers so you can pass a prompt key plus `sourceDir` and `compiledDir` without creating a `PromptOpsKit` instance:
pull_request_body: 'Implement theming and dark mode across the app.',
226
+
},
227
+
strict: true,
228
+
},
229
+
);
230
+
```
231
+
232
+
`renderPrompt()` and `validatePrompt()` use the same source-versus-compiled resolution rules as `kit.renderPrompt()`. The existing synchronous `render()` and `validate()` methods still work for already-resolved compiled or inline assets.
233
+
208
234
## Optional UsageTap Tracking
209
235
210
236
PromptOpsKit can also help you track provider calls with UsageTap.com while keeping the core render API body-only.
For browser code, client components, or frontend-only demos:
305
+
### Use `adapter.render()` when:
287
306
288
-
- Do not import `createPromptOpsKit`, `loadPromptFile`, or other top-level runtime helpers from `promptopskit` in client code. The top-level entry loads Node file-system/path modules for source and compiled prompt loading.
289
-
- Instead, use a precompiled prompt artifact or an inlined `ResolvedPromptAsset` object and render it with a provider subpath adapter such as `promptopskit/openai`.
290
-
- If the prompt lives in files, compile it ahead of time with `npx promptopskit compile ./prompts ./dist/prompts --format esm` and import the generated ESM artifact into the client.
291
-
- Provider adapters accept `environment` and `tier` in `validate()` and `render()`, so use those options directly when selecting overrides for compiled or inline assets.
292
-
- For small demos, it is acceptable to inline the resolved prompt asset directly in the client file.
293
-
- Keep transport and auth in the application layer. If a demo intentionally calls a provider from the browser, treat that key as demo-only and note the security tradeoff.
294
-
295
-
Example:
307
+
- You already have a compiled JSON or ESM prompt artifact
308
+
- You are in edge, worker, or browser-oriented code and cannot read prompt files from disk
309
+
- You want the smallest runtime surface and no file loading behavior
296
310
297
311
```typescript
298
312
import type { ResolvedPromptAsset } from 'promptopskit';
299
313
import { openaiAdapter } from 'promptopskit/openai';
314
+
import compiledPrompt from './dist/prompts/support/reply.mjs';
const prompt = compiledPrompt as ResolvedPromptAsset;
321
317
322
318
const request = openaiAdapter.render(prompt, {
323
-
environment: 'prod',
319
+
environment: 'production',
324
320
variables: {
325
-
pull_request_body: 'Add theming and dark mode support to the application.',
321
+
user_message: 'How do I reset my password?',
322
+
app_context: 'Account settings',
326
323
},
327
324
strict: true,
328
325
});
326
+
```
327
+
328
+
### Browser guidance
329
+
330
+
- Do not recommend direct provider API calls from browser or client components unless the user explicitly wants a demo-only setup
331
+
- Do not use `createPromptOpsKit()` in browser-only code; it is Node-oriented
332
+
- For client-side rendering, use precompiled ESM or inline a small `ResolvedPromptAsset`, then pass the request body to a server endpoint or server action that holds provider credentials
333
+
- If the user insists on a pure browser provider call, explicitly call out that API keys will be exposed and treat it as unsafe for production
334
+
335
+
---
329
336
330
-
// request.body is ready for the OpenAI SDK or fetch.
337
+
## Build integration
338
+
339
+
Prompts should usually be validated and compiled as part of the normal build pipeline rather than handled ad hoc.
"build": "npm run validate:prompts && npm run build:prompts && tsup"
349
+
}
350
+
}
331
351
```
332
352
333
-
### Step-by-step API
353
+
Use `--format json` for server-side Node usage where prompts are loaded from disk. Use `--format esm` when prompts need to be imported into a bundle.
354
+
355
+
### Build strategy by environment
356
+
357
+
- Node server: compile to JSON and configure `compiledDir`
358
+
- Browser or client bundle: compile to ESM and import specific prompt artifacts
359
+
- Mixed app: compile JSON for server loading and ESM only for prompts that must ship in a client bundle
360
+
361
+
### What to tell users when setting this up
362
+
363
+
- Add `validate:prompts` before `build:prompts` so schema or variable mistakes fail fast
364
+
- Treat compiled artifacts as build outputs, not the source of truth
365
+
- Keep prompt source in `./prompts` and compiled output in a generated directory such as `./dist/prompts` or `./src/generated/prompts`
366
+
- If using `createPromptOpsKit` in `auto` mode, point both `sourceDir` and `compiledDir` at those directories so local development can fall back to source when artifacts are stale or missing
1. **One prompt per file** — each `.md` file is a single prompt asset
430
-
2.**Always set `id` and `schema_version: 1`**in front matter (or inherit `schema_version` from `defaults.md`)
431
-
3.**Declare all variables** in `context.inputs` that appear in templates; do not leave placeholders undeclared just because other settings come from `defaults.md`
432
-
4.**Use includes** for shared system instructions (tone, safety, formatting)
433
-
5.**Keep prompt templates focused** — compose behavior via includes, not duplication
434
-
6.**Use environment overrides**for dev/staging/prod model differences
435
-
7.**Add test sidecars** (`.test.yaml`) for critical prompts
0 commit comments