@promptev/client 0.0.1

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.txt ADDED
@@ -0,0 +1,20 @@
1
+ Promptev SDK License
2
+
3
+ Copyright © 2025 Promptev Inc.
4
+
5
+ This software is proprietary and protected under applicable copyright laws.
6
+ By using this software, you agree to the following:
7
+
8
+ 1. You may use this SDK:
9
+ - Free of charge on the Free Tier of Promptev services
10
+ - For evaluation or development purposes
11
+ - In production only with an active Promptev subscription
12
+
13
+ 2. Restrictions:
14
+ - You may NOT sublicense, distribute, or reverse-engineer this software
15
+ - You may NOT modify or resell this SDK or derivative works
16
+ - You may NOT use this SDK outside the Promptev API without a license
17
+
18
+ 3. The SDK is provided “AS IS” without warranties. Promptev Inc. shall not be held liable for any damages.
19
+
20
+ By using this software, you accept these terms. For licensing inquiries or enterprise use, contact support@Promptev.ai.
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.PromptevClient = void 0;
40
+ const axios_1 = __importDefault(require("axios"));
41
+ class PromptevClient {
42
+ constructor(config) {
43
+ this.refreshInterval = null;
44
+ this.baseUrl = config.baseUrl || "https://api.promptev.ai";
45
+ this.projectKey = config.projectKey;
46
+ this.cacheRefreshIntervalMs = config.cacheRefreshIntervalMs || 30000;
47
+ this.client = axios_1.default.create({ baseURL: this.baseUrl });
48
+ const isNode = typeof window === "undefined";
49
+ this.isReady = (async () => {
50
+ if (isNode) {
51
+ const { default: NodeCache } = await Promise.resolve().then(() => __importStar(require("node-cache")));
52
+ this.promptCache = new NodeCache({
53
+ stdTTL: 3600,
54
+ checkperiod: 120,
55
+ useClones: false,
56
+ });
57
+ }
58
+ else {
59
+ this.promptCache = new Map();
60
+ }
61
+ this.startCacheRefresh();
62
+ })();
63
+ }
64
+ async ensureReady() {
65
+ await this.isReady;
66
+ }
67
+ makeCacheKey(promptKey, variables) {
68
+ const sorted = Object.keys(variables)
69
+ .sort()
70
+ .map(k => `${k}=${variables[k]}`)
71
+ .join("&");
72
+ return `${promptKey}:${btoa(sorted)}`;
73
+ }
74
+ async fetchPromptFromServer(promptKey) {
75
+ const url = `/api/sdk/v1/prompt/client/${this.projectKey}/${promptKey}`;
76
+ const response = await this.client.get(url);
77
+ const rawPrompt = response.data.prompt;
78
+ const rawVars = Array.isArray(response.data.variables)
79
+ ? response.data.variables
80
+ : typeof response.data.variables === "string"
81
+ ? response.data.variables.split(",").map(v => v.trim())
82
+ : [];
83
+ return { prompt: rawPrompt, variables: rawVars };
84
+ }
85
+ async formatPrompt(template, requiredVars, values) {
86
+ if (!requiredVars.length)
87
+ return template;
88
+ const missing = requiredVars.filter(v => !(v in values));
89
+ if (missing.length)
90
+ throw new Error(`Missing variables: ${missing.join(", ")}`);
91
+ let formatted = template;
92
+ for (const [key, val] of Object.entries(values)) {
93
+ const pattern = new RegExp(`{{\\s*${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*}}`, "g");
94
+ formatted = formatted.replace(pattern, val);
95
+ }
96
+ return formatted;
97
+ }
98
+ startCacheRefresh() {
99
+ if (this.refreshInterval)
100
+ clearInterval(this.refreshInterval);
101
+ this.refreshInterval = setInterval(async () => {
102
+ await this.ensureReady();
103
+ const keys = Array.from(this.promptCache instanceof Map ? this.promptCache.keys() : this.promptCache.keys());
104
+ for (const cacheKey of keys) {
105
+ const [promptKey, encoded] = cacheKey.split(":");
106
+ const vars = JSON.parse(atob(encoded));
107
+ try {
108
+ await this.fetchAndCache(promptKey, vars);
109
+ }
110
+ catch { }
111
+ }
112
+ }, this.cacheRefreshIntervalMs);
113
+ }
114
+ async fetchAndCache(promptKey, variables) {
115
+ const data = await this.fetchPromptFromServer(promptKey);
116
+ const compiled = await this.formatPrompt(data.prompt, data.variables, variables);
117
+ const cacheKey = this.makeCacheKey(promptKey, variables);
118
+ this.promptCache.set(cacheKey, compiled);
119
+ return compiled;
120
+ }
121
+ async getPrompt(promptKey, variables = {}) {
122
+ await this.ensureReady();
123
+ const cacheKey = this.makeCacheKey(promptKey, variables);
124
+ const cached = this.promptCache.get(cacheKey);
125
+ if (cached)
126
+ return cached;
127
+ return await this.fetchAndCache(promptKey, variables);
128
+ }
129
+ async dispose() {
130
+ await this.ensureReady();
131
+ if (this.refreshInterval)
132
+ clearInterval(this.refreshInterval);
133
+ if (this.promptCache instanceof Map) {
134
+ this.promptCache.clear();
135
+ }
136
+ else {
137
+ this.promptCache.flushAll();
138
+ this.promptCache.close();
139
+ }
140
+ }
141
+ }
142
+ exports.PromptevClient = PromptevClient;
143
+ exports.default = PromptevClient;
@@ -0,0 +1,30 @@
1
+ export interface PromptliyClientConfig {
2
+ baseUrl?: string;
3
+ projectKey: string;
4
+ }
5
+ export interface Prompt {
6
+ prompt: string;
7
+ variables: string[] | string | null;
8
+ format(values?: Record<string, string>): string;
9
+ }
10
+ export declare class PromptliyClient {
11
+ private client;
12
+ private baseUrl;
13
+ private projectKey;
14
+ private promptCache;
15
+ private refreshInterval;
16
+ private cacheRefreshIntervalMs;
17
+ private isReady;
18
+ constructor(config: PromptliyClientConfig);
19
+ private ensureReady;
20
+ private startCacheRefresh;
21
+ private refreshCachedPrompt;
22
+ private createPromptObject;
23
+ getPrompt(promptKey: string): Promise<Prompt> & {
24
+ format: (values: Record<string, string>) => Promise<string>;
25
+ };
26
+ private fetchPrompt;
27
+ private fetchPromptFromServer;
28
+ dispose(): Promise<void>;
29
+ }
30
+ export default PromptliyClient;
@@ -0,0 +1,24 @@
1
+ export interface PromptevClientConfig {
2
+ baseUrl?: string;
3
+ projectKey: string;
4
+ cacheRefreshIntervalMs?: number;
5
+ }
6
+ export declare class PromptevClient {
7
+ private client;
8
+ private baseUrl;
9
+ private projectKey;
10
+ private promptCache;
11
+ private refreshInterval;
12
+ private cacheRefreshIntervalMs;
13
+ private isReady;
14
+ constructor(config: PromptevClientConfig);
15
+ private ensureReady;
16
+ private makeCacheKey;
17
+ private fetchPromptFromServer;
18
+ private formatPrompt;
19
+ private startCacheRefresh;
20
+ private fetchAndCache;
21
+ getPrompt(promptKey: string, variables?: Record<string, string>): Promise<string>;
22
+ dispose(): Promise<void>;
23
+ }
24
+ export default PromptevClient;
@@ -0,0 +1,103 @@
1
+ import axios from "axios";
2
+ export class PromptevClient {
3
+ constructor(config) {
4
+ this.refreshInterval = null;
5
+ this.baseUrl = config.baseUrl || "https://api.promptev.ai";
6
+ this.projectKey = config.projectKey;
7
+ this.cacheRefreshIntervalMs = config.cacheRefreshIntervalMs || 30000;
8
+ this.client = axios.create({ baseURL: this.baseUrl });
9
+ const isNode = typeof window === "undefined";
10
+ this.isReady = (async () => {
11
+ if (isNode) {
12
+ const { default: NodeCache } = await import("node-cache");
13
+ this.promptCache = new NodeCache({
14
+ stdTTL: 3600,
15
+ checkperiod: 120,
16
+ useClones: false,
17
+ });
18
+ }
19
+ else {
20
+ this.promptCache = new Map();
21
+ }
22
+ this.startCacheRefresh();
23
+ })();
24
+ }
25
+ async ensureReady() {
26
+ await this.isReady;
27
+ }
28
+ makeCacheKey(promptKey, variables) {
29
+ const sorted = Object.keys(variables)
30
+ .sort()
31
+ .map(k => `${k}=${variables[k]}`)
32
+ .join("&");
33
+ return `${promptKey}:${btoa(sorted)}`;
34
+ }
35
+ async fetchPromptFromServer(promptKey) {
36
+ const url = `/api/sdk/v1/prompt/client/${this.projectKey}/${promptKey}`;
37
+ const response = await this.client.get(url);
38
+ const rawPrompt = response.data.prompt;
39
+ const rawVars = Array.isArray(response.data.variables)
40
+ ? response.data.variables
41
+ : typeof response.data.variables === "string"
42
+ ? response.data.variables.split(",").map(v => v.trim())
43
+ : [];
44
+ return { prompt: rawPrompt, variables: rawVars };
45
+ }
46
+ async formatPrompt(template, requiredVars, values) {
47
+ if (!requiredVars.length)
48
+ return template;
49
+ const missing = requiredVars.filter(v => !(v in values));
50
+ if (missing.length)
51
+ throw new Error(`Missing variables: ${missing.join(", ")}`);
52
+ let formatted = template;
53
+ for (const [key, val] of Object.entries(values)) {
54
+ const pattern = new RegExp(`{{\\s*${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*}}`, "g");
55
+ formatted = formatted.replace(pattern, val);
56
+ }
57
+ return formatted;
58
+ }
59
+ startCacheRefresh() {
60
+ if (this.refreshInterval)
61
+ clearInterval(this.refreshInterval);
62
+ this.refreshInterval = setInterval(async () => {
63
+ await this.ensureReady();
64
+ const keys = Array.from(this.promptCache instanceof Map ? this.promptCache.keys() : this.promptCache.keys());
65
+ for (const cacheKey of keys) {
66
+ const [promptKey, encoded] = cacheKey.split(":");
67
+ const vars = JSON.parse(atob(encoded));
68
+ try {
69
+ await this.fetchAndCache(promptKey, vars);
70
+ }
71
+ catch { }
72
+ }
73
+ }, this.cacheRefreshIntervalMs);
74
+ }
75
+ async fetchAndCache(promptKey, variables) {
76
+ const data = await this.fetchPromptFromServer(promptKey);
77
+ const compiled = await this.formatPrompt(data.prompt, data.variables, variables);
78
+ const cacheKey = this.makeCacheKey(promptKey, variables);
79
+ this.promptCache.set(cacheKey, compiled);
80
+ return compiled;
81
+ }
82
+ async getPrompt(promptKey, variables = {}) {
83
+ await this.ensureReady();
84
+ const cacheKey = this.makeCacheKey(promptKey, variables);
85
+ const cached = this.promptCache.get(cacheKey);
86
+ if (cached)
87
+ return cached;
88
+ return await this.fetchAndCache(promptKey, variables);
89
+ }
90
+ async dispose() {
91
+ await this.ensureReady();
92
+ if (this.refreshInterval)
93
+ clearInterval(this.refreshInterval);
94
+ if (this.promptCache instanceof Map) {
95
+ this.promptCache.clear();
96
+ }
97
+ else {
98
+ this.promptCache.flushAll();
99
+ this.promptCache.close();
100
+ }
101
+ }
102
+ }
103
+ export default PromptevClient;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@promptev/client",
3
+ "version": "0.0.1",
4
+ "description": "Client library for accessing Promptev API",
5
+ "type": "module",
6
+ "main": "./dist/cjs/index.cjs",
7
+ "module": "./dist/esm/index.js",
8
+ "types": "./dist/esm/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/esm/index.js",
12
+ "require": "./dist/cjs/index.cjs",
13
+ "types": "./dist/esm/index.d.ts"
14
+ }
15
+ },
16
+ "license": "MIT",
17
+ "author": "Promptev Inc. <support@promptev.ai>",
18
+ "private": false,
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "homepage": "https://promptliy.ai",
23
+ "files": [
24
+ "dist",
25
+ "readme.md",
26
+ "LICENSE"
27
+ ],
28
+ "keywords": [
29
+ "promptev",
30
+ "prompts",
31
+ "api",
32
+ "client",
33
+ "sdk",
34
+ "ai",
35
+ "promptDev",
36
+ "promptdev",
37
+ "promptops",
38
+ "typescript",
39
+ "javascript"
40
+ ],
41
+ "scripts": {
42
+ "prepare": "npm run build",
43
+ "build:esm": "tsc -p tsconfig.json",
44
+ "build:cjs": "tsc -p tsconfig.cjs.json && node scripts/rename-cjs.cjs",
45
+ "build": "npm run build:esm && npm run build:cjs"
46
+ },
47
+ "dependencies": {
48
+ "axios": "^1.10.0",
49
+ "node-cache": "^5.1.2"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^20.10.0",
53
+ "ts-node": "^10.9.2",
54
+ "typescript": "^5.8.3"
55
+ }
56
+ }
package/readme.md ADDED
@@ -0,0 +1,125 @@
1
+ # promptev-client (JavaScript / TypeScript)
2
+
3
+ A lightweight JS SDK to securely fetch, format, and cache prompts from [Promptev.ai](https://promptev.ai).
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @promptev/client
11
+ # or
12
+ yarn install @promptev/client
13
+ #or
14
+ pnpm add @promptev/client
15
+ ```
16
+
17
+ > Optional for Node.js caching (recommended):
18
+ ```bash
19
+ npm install node-cache
20
+ ```
21
+
22
+ ---
23
+
24
+ ## What is Promptev?
25
+
26
+ [Promptev](https://promptev.ai) helps teams manage, version, and collaborate on production-grade prompts with live context, variables, versioning and integrations.
27
+
28
+ ---
29
+
30
+ ## Usage
31
+
32
+ ### 1. Initialize the client
33
+
34
+ ```ts
35
+ import { PromptevClient } from "@promptev/client";
36
+
37
+ const client = new PromptevClient({
38
+ projectKey: "pv_sk_abc123yourkey"
39
+ });
40
+ ```
41
+
42
+ ---
43
+
44
+ ### 2. Fetch a prompt with variables
45
+
46
+ ```ts
47
+ const prompt = await client.getPrompt("onboarding-email", {
48
+ name: "Ava",
49
+ product: "Promptev"
50
+ });
51
+
52
+ console.log(prompt);
53
+ // "Subject: Welcome, Ava! Hey Ava, Thanks for joining Promptev..."
54
+ ```
55
+
56
+ ---
57
+
58
+ ### 3. Fetch a prompt without variables
59
+
60
+ ```ts
61
+ const staticPrompt = await client.getPrompt("system-intro");
62
+ console.log(staticPrompt);
63
+ // "You are a helpful AI assistant..."
64
+ ```
65
+
66
+ > ⚠️ No variables? You can omit the second argument.
67
+
68
+ ---
69
+
70
+ ### 4. Use with LLM APIs (OpenAI, Claude, Gemini, etc.)
71
+
72
+ ```ts
73
+ import OpenAI from "openai";
74
+
75
+ const openai = new OpenAI({ apiKey: "sk-..." });
76
+
77
+ const promptText = await client.getPrompt("clarify-topic", {
78
+ topic: "prompt engineering"
79
+ });
80
+
81
+ const response = await openai.chat.completions.create({
82
+ model: "gpt-4",
83
+ messages: [{ role: "user", content: promptText }]
84
+ });
85
+
86
+ console.log(response.choices[0].message.content);
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Features
92
+
93
+ - ✅ Works with or without prompt variables
94
+ - 🔁 In-memory caching (Map or NodeCache)
95
+ - 🔄 Background refresh (default: 30s, configurable)
96
+ - ⚡ Token-safe variable formatting
97
+ - 🔐 Secure for frontend & server
98
+ - 🔌 Works with any LLM provider
99
+
100
+ ---
101
+
102
+ ## Options
103
+
104
+ ```ts
105
+ new PromptevClient({
106
+ projectKey: "pv_sk_abc...",
107
+ baseUrl: "https://api.promptev.ai", // optional
108
+ cacheRefreshIntervalMs: 60000 // optional
109
+ });
110
+ ```
111
+
112
+ ---
113
+
114
+ ## License
115
+
116
+ This SDK is **commercial software** by Promptev Inc.
117
+
118
+ By using this package, you agree to the terms in [`LICENSE.txt`](./LICENSE.txt).
119
+
120
+ ---
121
+
122
+ ## Contact
123
+
124
+ - 🌐 [https://promptev.ai](https://promptev.ai)
125
+ - 📧 support@promptev.ai