PromStackμ μν 곡μ TypeScript/JavaScript SDKμ λλ€.
npm install @promstack-1/sdk
# λλ
yarn add @promstack-1/sdk
# λλ
pnpm add @promstack-1/sdkimport { PromStackClient } from '@promstack-1/sdk';
// ν΄λΌμ΄μΈνΈ μ΄κΈ°ν
const client = new PromptManagerClient({
apiKey: 'your-api-key',
baseUrl: 'https://promstack.com'
});
// ν둬ννΈ λͺ©λ‘ κ°μ Έμ€κΈ°
const prompts = await client.getPrompts();
console.log(prompts);
// νΉμ ν둬ννΈ κ°μ Έμ€κΈ°
const prompt = await client.getPrompt(1);
console.log(prompt.content);
// λ³μ ν
νλ¦Ώ λ λλ§
const rendered = client.renderPrompt(prompt.content, {
name: 'νκΈΈλ',
topic: 'AI'
});
// μ€ν κΈ°λ‘ μ μ₯
const { id } = await client.recordRun({
promptId: 1,
response: 'AIκ° μμ±ν μλ΅...',
provider: 'openai',
variables: { name: 'νκΈΈλ' }
});// κ°λ¨ν λ°©μ
const client = new PromptManagerClient('your-api-key');
// μ 체 μ΅μ
const client = new PromptManagerClient({
apiKey: 'your-api-key',
baseUrl: 'https://api.example.com', // κΈ°λ³Έκ°: http://localhost:3000
timeout: 30000, // κΈ°λ³Έκ°: 30000ms
retries: 3, // κΈ°λ³Έκ°: 3
retryDelay: 1000, // κΈ°λ³Έκ°: 1000ms
enableCache: true, // κΈ°λ³Έκ°: false
cacheTTL: 60000 // κΈ°λ³Έκ°: 60000ms
});const prompts = await client.getPrompts({
q: 'κ²μμ΄', // μ λͺ© κ²μ
tag: 'marketing', // νκ·Έ νν°
category: 'writing', // μΉ΄ν
κ³ λ¦¬ νν°
limit: 10, // κ²°κ³Ό μ μ ν
offset: 0, // νμ΄μ§λ€μ΄μ
μ€νμ
sort: 'updated', // μ λ ¬ (created, updated, title, likes)
order: 'desc' // μ λ ¬ λ°©ν₯ (asc, desc)
});const prompt = await client.getPrompt(1);
const promptV2 = await client.getPromptVersion(1, 2);
const versions = await client.getPromptVersions(1);const result = await client.searchPrompts('λ§μΌν
', { limit: 10 });
console.log(`μ΄ ${result.total}κ° μ€ ${result.prompts.length}κ° λ°ν`);// λ¨μΌ μ€ν κΈ°λ‘
const { id } = await client.recordRun({
promptId: 1,
response: 'AI μλ΅',
provider: 'openai',
tokenUsage: { totalTokens: 100 }
});
// μ€ν κΈ°λ‘ μ‘°ν
const runs = await client.getRuns({ promptId: 1, limit: 20 });
// μΌκ΄ κΈ°λ‘
const result = await client.batchRecordRuns([
{ promptId: 1, response: 'μλ΅ 1' },
{ promptId: 2, response: 'μλ΅ 2' }
]);
console.log(`μ±κ³΅: ${result.successful}, μ€ν¨: ${result.failed}`);const project = await client.getProject();
const stats = await client.getStats();
console.log(`ν둬ννΈ: ${stats.promptCount}, μ€ν: ${stats.runCount}`);
const categories = await client.getCategories();
const tags = await client.getTags();const template = 'μλ
νμΈμ {{name}}λ';
// λ³μ μΆμΆ
const vars = client.parseVariables(template); // ['name']
// λ³μ μ ν¨μ± κ²μ¦
const isValid = client.validateVariables(template, { name: 'νκΈΈλ' }); // true
// λ λλ§
const rendered = client.renderPrompt(template, { name: 'νκΈΈλ' });// μ¬μ¬μ© κ°λ₯ν λ¬λ μμ±
const runner = client.createRunner({
provider: 'openai',
executor: async (content, userInput) => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content }]
});
return response.choices[0].message.content;
}
});
// κ°νΈνκ² μ€ν
const result = await runner(1, 'μ§λ¬Έ', { name: 'νκΈΈλ' });client.clearCache(); // μ 체 μΊμ μμ
client.invalidateCache(key); // νΉμ ν€ μμ import {
PromptManagerError,
AuthenticationError,
NotFoundError,
ValidationError,
TimeoutError,
RateLimitError
} from '@promstack-1/sdk';
try {
const prompt = await client.getPrompt(999);
} catch (error) {
if (error instanceof AuthenticationError) {
console.log('API ν€κ° μ ν¨νμ§ μμ΅λλ€');
} else if (error instanceof NotFoundError) {
console.log('ν둬ννΈλ₯Ό μ°Ύμ μ μμ΅λλ€');
} else if (error instanceof ValidationError) {
console.log('μ
λ ₯κ°μ΄ μ¬λ°λ₯΄μ§ μμ΅λλ€');
} else if (error instanceof TimeoutError) {
console.log('μμ² μκ°μ΄ μ΄κ³Όλμμ΅λλ€');
} else if (error instanceof RateLimitError) {
console.log(`μμ² νλ μ΄κ³Ό. ${error.retryAfter}μ΄ ν μ¬μλ`);
}
}λͺ¨λ νμ μ ν¨ν€μ§μμ exportλ©λλ€:
import type {
Prompt,
PromptVersion,
Project,
Run,
RunInput,
Category,
Tag,
SearchResult,
BatchRunResult,
GetPromptsOptions,
GetRunsOptions,
ClientOptions
} from '@promstack-1/sdk';- Node.js 18+
- λΈλΌμ°μ (Fetch API μ§μ)
- Edge Runtime (Vercel, Cloudflare Workers)
MIT