@promptlycms/prompts 0.2.0-canary.1db6dca → 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/README.md CHANGED
@@ -3,9 +3,8 @@
3
3
  TypeScript SDK for the [Promptly CMS](https://promptlycms.com) API. Stop hardcoding prompts in your codebase — manage them in a purpose-built CMS with versioning and instant publishing, then fetch them at runtime with full type safety.
4
4
 
5
5
  - **Zero hardcoded prompts** — fetch prompts at runtime; update wording, models, and settings from the [CMS](https://promptlycms.com) without code changes or redeploys
6
- - **Runtime client** — `getPrompt()`, `getPrompts()`, `getComposer()`, and `getComposers()` with full TypeScript support
7
- - **Composers** — fetch multi-segment documents that combine static HTML with prompt references, then assemble AI-generated output with `formatComposer()`
8
- - **Codegen CLI** — generates typed template variables and composer types via declaration merging
6
+ - **Runtime client** — `getPrompt()` and `getPrompts()` with full TypeScript support
7
+ - **Codegen CLI** — generates typed template variables via declaration merging
9
8
  - **AI SDK integration** — destructure directly into [Vercel AI SDK](https://ai-sdk.dev/) `generateText` / `streamText`
10
9
  - **Any AI provider** — supports [all providers](https://ai-sdk.dev/providers/ai-sdk-providers#provider-support) supported by the Vercel AI SDK
11
10
  - **Structured output** — Zod schemas built from CMS-defined output schemas
@@ -47,7 +46,7 @@ PROMPTLY_API_KEY=pk_live_...
47
46
  npx promptly generate
48
47
  ```
49
48
 
50
- This fetches all your prompts and composers from the API and generates a `promptly-env.d.ts` file in your project root with typed autocomplete for every prompt ID, composer ID, template variables, and prompt names.
49
+ This fetches all your prompts from the API and generates a `promptly-env.d.ts` file in your project root with typed autocomplete for every prompt ID and its template variables.
51
50
 
52
51
  ```bash
53
52
  # Custom output path
@@ -136,49 +135,6 @@ const { text } = await generateText({
136
135
 
137
136
  The model configured in the CMS is auto-resolved to the correct AI SDK provider.
138
137
 
139
- ## Fetching composers
140
-
141
- A composer is a document template that combines static HTML segments with prompt references. Fetch a composer and use `compose()` to run all prompts and assemble the output in one call:
142
-
143
- ```typescript
144
- import { generateText } from 'ai';
145
-
146
- const composer = await promptly.getComposer('my-composer-id', {
147
- input: { text: 'Hello world', targetLang: 'French' },
148
- });
149
-
150
- // One line — runs all prompts in parallel, assembles the output
151
- const output = await composer.compose(generateText);
152
- ```
153
-
154
- Override parameters per prompt:
155
-
156
- ```typescript
157
- const output = await composer.compose((prompt) =>
158
- generateText({ ...prompt, maxTokens: 500 })
159
- );
160
- ```
161
-
162
- For full control, use the manual flow with named prompts and `formatComposer()`:
163
-
164
- ```typescript
165
- const { introPrompt, reviewPrompt, formatComposer } = composer;
166
-
167
- const output = formatComposer({
168
- introPrompt: await generateText(introPrompt),
169
- reviewPrompt: await generateText(reviewPrompt),
170
- });
171
- ```
172
-
173
- Batch fetch multiple composers in parallel:
174
-
175
- ```typescript
176
- const [first, second] = await promptly.getComposers([
177
- { composerId: 'comp-a', input: { name: 'Dan' } },
178
- { composerId: 'comp-b', input: { topic: 'AI' } },
179
- ]);
180
- ```
181
-
182
138
  ## Model auto-detection
183
139
 
184
140
  The SDK automatically resolves models configured in the CMS to the correct AI SDK provider based on the model name prefix:
@@ -231,7 +187,7 @@ declare module '@promptlycms/prompts' {
231
187
  }
232
188
  ```
233
189
 
234
- With this file present, `getPrompt()` and `getPrompts()` return typed `userMessage` functions with autocomplete. `getComposer()` and `getComposers()` get typed `input` and named prompt properties. Unknown IDs fall back to `Record<string, string>`.
190
+ With this file present, `getPrompt()` and `getPrompts()` return typed `userMessage` functions with autocomplete. Unknown prompt IDs fall back to `Record<string, string>`.
235
191
 
236
192
  Add the generated file to version control so types are available without running codegen in CI. Re-run `npx promptly generate` whenever you add, remove, or rename template variables in the CMS.
237
193
 
@@ -265,7 +221,7 @@ try {
265
221
  | `baseUrl` | `string` | No | API base URL (default: `https://api.promptlycms.com`) |
266
222
  | `model` | `(modelId: string) => LanguageModel` | No | Custom model resolver — overrides auto-detection |
267
223
 
268
- Returns a `PromptlyClient` with `getPrompt()`, `getPrompts()`, `getComposer()`, and `getComposers()` methods.
224
+ Returns a `PromptlyClient` with `getPrompt()` and `getPrompts()` methods.
269
225
 
270
226
  ### `client.getPrompt(promptId, options?)`
271
227
 
@@ -279,19 +235,6 @@ Fetch a single prompt. Returns `PromptResult` with typed `userMessage` when code
279
235
 
280
236
  Fetch multiple prompts in parallel. Accepts `PromptRequest[]` and returns a typed tuple matching the input order.
281
237
 
282
- ### `client.getComposer(composerId, options?)`
283
-
284
- Fetch a single composer. Returns `ComposerResult` with named prompt properties, a `prompts` array, and `formatComposer()`.
285
-
286
- | Option | Type | Description |
287
- |-----------|---------------------------|----------------------|
288
- | `input` | `Record<string, string>` | Template variables to interpolate |
289
- | `version` | `string` | Specific version to fetch (default: latest) |
290
-
291
- ### `client.getComposers(entries)`
292
-
293
- Fetch multiple composers in parallel. Accepts `ComposerRequest[]` and returns results in the same order.
294
-
295
238
  ### `@promptlycms/prompts/schema`
296
239
 
297
240
  Subpath export for working with Zod schemas from CMS schema fields:
package/dist/cli.js CHANGED
@@ -65,7 +65,6 @@ var detectProviderName = (modelId) => {
65
65
  }
66
66
  return void 0;
67
67
  };
68
- var toCamelCase = (name) => name.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()).replace(/^[A-Z]/, (char) => char.toLowerCase());
69
68
 
70
69
  // src/cli/generate.ts
71
70
  var PROVIDER_PACKAGES = {
@@ -99,50 +98,6 @@ var fetchAllPrompts = async (apiKey, baseUrl) => {
99
98
  }
100
99
  return response.json();
101
100
  };
102
- var fetchAllComposers = async (apiKey, baseUrl) => {
103
- const url = new URL("/composers", baseUrl ?? DEFAULT_BASE_URL);
104
- url.searchParams.set("include_versions", "true");
105
- const response = await fetch(url.toString(), {
106
- headers: {
107
- Authorization: `Bearer ${apiKey}`
108
- }
109
- });
110
- if (!response.ok) {
111
- throw await createErrorFromResponse(response);
112
- }
113
- return response.json();
114
- };
115
- var extractComposerVariables = (composer) => {
116
- const vars = /* @__PURE__ */ new Set();
117
- for (const segment of composer.segments) {
118
- if (segment.type !== "prompt") {
119
- continue;
120
- }
121
- if (!segment.userMessage) {
122
- continue;
123
- }
124
- for (const v of extractTemplateVariables(segment.userMessage)) {
125
- vars.add(v);
126
- }
127
- }
128
- return [...vars];
129
- };
130
- var extractComposerPromptNames = (composer) => {
131
- const seen = /* @__PURE__ */ new Set();
132
- const names = [];
133
- for (const segment of composer.segments) {
134
- if (segment.type !== "prompt") {
135
- continue;
136
- }
137
- const camelName = toCamelCase(segment.promptName);
138
- if (seen.has(camelName)) {
139
- continue;
140
- }
141
- seen.add(camelName);
142
- names.push(camelName);
143
- }
144
- return names;
145
- };
146
101
  var compareSemver = (a, b) => {
147
102
  const pa = a.split(".").map(Number);
148
103
  const pb = b.split(".").map(Number);
@@ -254,7 +209,7 @@ var generateMappedTypeBlock = (group, indent) => {
254
209
  }
255
210
  return lines;
256
211
  };
257
- var generateTypeDeclaration = (prompts, composers = []) => {
212
+ var generateTypeDeclaration = (prompts) => {
258
213
  const lines = [
259
214
  "// Auto-generated by @promptlycms/prompts \u2014 do not edit",
260
215
  "import '@promptlycms/prompts';",
@@ -288,91 +243,27 @@ var generateTypeDeclaration = (prompts, composers = []) => {
288
243
  }
289
244
  }
290
245
  lines.push(" }");
291
- if (composers.length > 0) {
292
- lines.push(" interface ComposerVariableMap {");
293
- for (const composer of composers) {
294
- const variables = extractComposerVariables(composer);
295
- const versions = ["'latest'"];
296
- if (composer.publishedVersions) {
297
- for (const pv of composer.publishedVersions) {
298
- versions.push(`'${pv.version}'`);
299
- }
300
- } else {
301
- versions.push(`'${composer.version}'`);
302
- }
303
- lines.push(` '${composer.composerId}': {`);
304
- if (versions.length === 1) {
305
- if (variables.length === 0) {
306
- lines.push(` [V in ${versions[0]}]: Record<string, never>;`);
307
- } else {
308
- lines.push(` [V in ${versions[0]}]: {`);
309
- for (const v of variables) {
310
- lines.push(` ${v}: string;`);
311
- }
312
- lines.push(" };");
313
- }
314
- } else {
315
- const versionUnion = versions.join(" | ");
316
- if (variables.length === 0) {
317
- lines.push(` [V in ${versionUnion}]: Record<string, never>;`);
318
- } else {
319
- lines.push(` [V in ${versionUnion}]: {`);
320
- for (const v of variables) {
321
- lines.push(` ${v}: string;`);
322
- }
323
- lines.push(" };");
324
- }
325
- }
326
- lines.push(" };");
327
- }
328
- lines.push(" }");
329
- lines.push(" interface ComposerPromptMap {");
330
- for (const composer of composers) {
331
- const names = extractComposerPromptNames(composer);
332
- if (names.length === 0) {
333
- lines.push(` '${composer.composerId}': never;`);
334
- } else {
335
- const union = names.map((n) => `'${n}'`).join(" | ");
336
- lines.push(` '${composer.composerId}': ${union};`);
337
- }
338
- }
339
- lines.push(" }");
340
- }
341
246
  lines.push("}");
342
247
  lines.push("");
343
248
  return lines.join("\n");
344
249
  };
345
- var warnMissingProviders = (prompts, composers = []) => {
250
+ var warnMissingProviders = (prompts) => {
346
251
  const require2 = createRequire(import.meta.url);
347
252
  const needed = /* @__PURE__ */ new Map();
348
- const trackModel = (modelId, label) => {
349
- const provider = detectProviderName(modelId);
253
+ for (const prompt of prompts) {
254
+ const provider = detectProviderName(prompt.config.model);
350
255
  if (!provider) {
351
- return;
256
+ continue;
352
257
  }
353
258
  const pkg = PROVIDER_PACKAGES[provider];
354
259
  if (!pkg) {
355
- return;
260
+ continue;
356
261
  }
357
262
  const existing = needed.get(pkg);
358
263
  if (existing) {
359
- existing.push(label);
264
+ existing.push(prompt.promptName);
360
265
  } else {
361
- needed.set(pkg, [label]);
362
- }
363
- };
364
- for (const prompt of prompts) {
365
- trackModel(prompt.config.model, prompt.promptName);
366
- }
367
- for (const composer of composers) {
368
- for (const segment of composer.segments) {
369
- if (segment.type !== "prompt") {
370
- continue;
371
- }
372
- const modelId = segment.config.model;
373
- if (modelId) {
374
- trackModel(modelId, `${composer.composerName}/${segment.promptName}`);
375
- }
266
+ needed.set(pkg, [prompt.promptName]);
376
267
  }
377
268
  }
378
269
  for (const [pkg, promptNames] of needed) {
@@ -387,22 +278,14 @@ var warnMissingProviders = (prompts, composers = []) => {
387
278
  }
388
279
  };
389
280
  var generate = async (apiKey, outputPath, baseUrl) => {
390
- const [prompts, composers] = await Promise.all([
391
- fetchAllPrompts(apiKey, baseUrl),
392
- fetchAllComposers(apiKey, baseUrl).catch(() => [])
393
- ]);
394
- if (prompts.length === 0 && composers.length === 0) {
395
- console.log(" No prompts or composers found for this API key.");
281
+ const prompts = await fetchAllPrompts(apiKey, baseUrl);
282
+ if (prompts.length === 0) {
283
+ console.log(" No prompts found for this API key.");
396
284
  return;
397
285
  }
398
- if (prompts.length > 0) {
399
- console.log(` Found ${prompts.length} prompt(s)`);
400
- }
401
- if (composers.length > 0) {
402
- console.log(` Found ${composers.length} composer(s)`);
403
- }
404
- warnMissingProviders(prompts, composers);
405
- const content = generateTypeDeclaration(prompts, composers);
286
+ console.log(` Found ${prompts.length} prompt(s)`);
287
+ warnMissingProviders(prompts);
288
+ const content = generateTypeDeclaration(prompts);
406
289
  await writeFile(outputPath, content, "utf-8");
407
290
  console.log(` Generated ${outputPath}`);
408
291
  };
@@ -472,7 +355,7 @@ var formatPromptlyError = (error) => {
472
355
  var generateCommand = defineCommand({
473
356
  meta: {
474
357
  name: "generate",
475
- description: "Generate typed TypeScript declarations from Promptly CMS prompts and composers"
358
+ description: "Generate typed TypeScript declarations from Promptly CMS prompts"
476
359
  },
477
360
  args: {
478
361
  output: {
package/dist/index.cjs CHANGED
@@ -33,9 +33,7 @@ __export(src_exports, {
33
33
  PromptlyError: () => PromptlyError,
34
34
  createPromptlyClient: () => createPromptlyClient,
35
35
  getSdkModelId: () => getSdkModelId,
36
- interpolate: () => interpolate,
37
- interpolateStaticSegment: () => interpolateStaticSegment,
38
- toCamelCase: () => toCamelCase
36
+ interpolate: () => interpolate
39
37
  });
40
38
  module.exports = __toCommonJS(src_exports);
41
39
 
@@ -182,26 +180,6 @@ var createModelResolver = (config) => {
182
180
  );
183
181
  };
184
182
  };
185
- var toCamelCase = (name) => name.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()).replace(/^[A-Z]/, (char) => char.toLowerCase());
186
- var VARIABLE_REF_REGEX = /<span[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*\sdata-field-path="([^"]+)"[^>]*><\/span>/g;
187
- var VARIABLE_REF_ALT_REGEX = /<span[^>]*\sdata-field-path="([^"]+)"[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*><\/span>/g;
188
- var MUSTACHE_REGEX = /\{\{(\w[\w.]*)\}\}/g;
189
- var interpolateStaticSegment = (content, input) => {
190
- let result = content;
191
- result = result.replace(
192
- VARIABLE_REF_REGEX,
193
- (_, fieldPath) => input[fieldPath] ?? ""
194
- );
195
- result = result.replace(
196
- VARIABLE_REF_ALT_REGEX,
197
- (_, fieldPath) => input[fieldPath] ?? ""
198
- );
199
- result = result.replace(
200
- MUSTACHE_REGEX,
201
- (_, fieldPath) => input[fieldPath] ?? ""
202
- );
203
- return result;
204
- };
205
183
  var createPromptlyClient = (config) => {
206
184
  const apiKey = config?.apiKey ?? process.env.PROMPTLY_API_KEY;
207
185
  if (!apiKey) {
@@ -246,119 +224,12 @@ var createPromptlyClient = (config) => {
246
224
  );
247
225
  return results;
248
226
  };
249
- const fetchComposer = async (composerId, options) => {
250
- const url = new URL(`/composers/${composerId}`, baseUrl);
251
- if (options?.version) {
252
- url.searchParams.set("version", options.version);
253
- }
254
- const response = await fetch(url.toString(), {
255
- headers: {
256
- Authorization: `Bearer ${apiKey}`
257
- }
258
- });
259
- if (!response.ok) {
260
- throw await createErrorFromResponse(response);
261
- }
262
- return response.json();
263
- };
264
- const getComposer = async (composerId, options) => {
265
- const response = await fetchComposer(composerId, options);
266
- const input = options?.input ?? {};
267
- const promptsByName = /* @__PURE__ */ new Map();
268
- const promptsOrdered = [];
269
- const processedSegments = [];
270
- for (const segment of response.segments) {
271
- if (segment.type === "static") {
272
- processedSegments.push({
273
- type: "static",
274
- content: interpolateStaticSegment(segment.content, input)
275
- });
276
- continue;
277
- }
278
- const camelName = toCamelCase(segment.promptName);
279
- if (!promptsByName.has(camelName)) {
280
- const segmentConfig = segment.config;
281
- const model = await modelResolver(segmentConfig.model ?? "");
282
- const userMessage = segment.userMessage ? interpolate(segment.userMessage, input) : "";
283
- const temperature = segmentConfig.temperature ?? 0.7;
284
- const composerPrompt = {
285
- model,
286
- system: segment.systemMessage ?? void 0,
287
- prompt: userMessage,
288
- temperature,
289
- promptId: segment.promptId,
290
- promptName: segment.promptName
291
- };
292
- promptsByName.set(camelName, composerPrompt);
293
- promptsOrdered.push(composerPrompt);
294
- }
295
- processedSegments.push({ type: "prompt", camelName });
296
- }
297
- const formatComposer = (results) => {
298
- const parts = [];
299
- for (const seg of processedSegments) {
300
- if (seg.type === "static") {
301
- parts.push(seg.content);
302
- continue;
303
- }
304
- const val = results[seg.camelName];
305
- if (val === void 0) {
306
- continue;
307
- }
308
- parts.push(typeof val === "string" ? val : val.text);
309
- }
310
- return parts.join("");
311
- };
312
- const compose = async (generate) => {
313
- const entries = [...promptsByName.entries()];
314
- const results = await Promise.all(
315
- entries.map(([, prompt]) => generate(prompt))
316
- );
317
- const resultMap = {};
318
- entries.forEach(([name], i) => {
319
- resultMap[name] = results[i] ?? "";
320
- });
321
- return formatComposer(resultMap);
322
- };
323
- const result = {
324
- composerId: response.composerId,
325
- composerName: response.composerName,
326
- version: response.version,
327
- config: response.config,
328
- segments: response.segments,
329
- prompts: promptsOrdered,
330
- formatComposer,
331
- compose
332
- };
333
- for (const [name, prompt] of promptsByName) {
334
- result[name] = prompt;
335
- }
336
- return result;
337
- };
338
- const getComposers = async (entries) => {
339
- const results = await Promise.all(
340
- entries.map(
341
- (entry) => getComposer(entry.composerId, {
342
- input: entry.input,
343
- version: entry.version
344
- })
345
- )
346
- );
347
- return results;
348
- };
349
- return {
350
- getPrompt,
351
- getPrompts,
352
- getComposer,
353
- getComposers
354
- };
227
+ return { getPrompt, getPrompts };
355
228
  };
356
229
  // Annotate the CommonJS export names for ESM import in node:
357
230
  0 && (module.exports = {
358
231
  PromptlyError,
359
232
  createPromptlyClient,
360
233
  getSdkModelId,
361
- interpolate,
362
- interpolateStaticSegment,
363
- toCamelCase
234
+ interpolate
364
235
  });
package/dist/index.d.cts CHANGED
@@ -1,11 +1,9 @@
1
- import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-DyMq5QKO.cjs';
2
- export { C as ComposerConfig, b as ComposerFormatFn, c as ComposerGenerateFn, d as ComposerId, e as ComposerInputFor, f as ComposerPrompt, g as ComposerPromptMap, h as ComposerPromptNamesFor, i as ComposerPromptSegment, j as ComposerRequest, k as ComposerResponse, l as ComposerResult, m as ComposerSegment, n as ComposerStaticSegment, o as ComposerVariableMap, p as ComposerVersion, q as ErrorResponse, F as FormatInput, G as GetComposerOptions, r as GetOptions, s as PromptConfig, t as PromptId, u as PromptMessage, v as PromptRequest, w as PromptResponse, x as PromptResult, y as PromptVariableMap, z as PromptVersion, A as PublishedVersion, S as SchemaField, B as SchemaFieldParams, V as ValidationRule } from './types-DyMq5QKO.cjs';
1
+ import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-BbNpKJej.cjs';
2
+ export { b as ErrorResponse, G as GetOptions, c as PromptConfig, d as PromptId, e as PromptMessage, f as PromptRequest, g as PromptResponse, h as PromptResult, i as PromptVariableMap, j as PromptVersion, k as PublishedVersion, S as SchemaField, l as SchemaFieldParams, V as ValidationRule } from './types-BbNpKJej.cjs';
3
3
  import 'ai';
4
4
 
5
5
  declare const getSdkModelId: (modelId: string) => string;
6
6
  declare const interpolate: (template: string, variables: Record<string, string>) => string;
7
- declare const toCamelCase: (name: string) => string;
8
- declare const interpolateStaticSegment: (content: string, input: Record<string, string>) => string;
9
7
  declare const createPromptlyClient: (config?: PromptlyClientConfig) => PromptlyClient;
10
8
 
11
9
  declare class PromptlyError extends Error {
@@ -16,4 +14,4 @@ declare class PromptlyError extends Error {
16
14
  constructor(message: string, code: ErrorCode, status: number, usage?: unknown, upgradeUrl?: string);
17
15
  }
18
16
 
19
- export { ErrorCode, PromptlyClient, PromptlyClientConfig, PromptlyError, createPromptlyClient, getSdkModelId, interpolate, interpolateStaticSegment, toCamelCase };
17
+ export { ErrorCode, PromptlyClient, PromptlyClientConfig, PromptlyError, createPromptlyClient, getSdkModelId, interpolate };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,9 @@
1
- import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-DyMq5QKO.js';
2
- export { C as ComposerConfig, b as ComposerFormatFn, c as ComposerGenerateFn, d as ComposerId, e as ComposerInputFor, f as ComposerPrompt, g as ComposerPromptMap, h as ComposerPromptNamesFor, i as ComposerPromptSegment, j as ComposerRequest, k as ComposerResponse, l as ComposerResult, m as ComposerSegment, n as ComposerStaticSegment, o as ComposerVariableMap, p as ComposerVersion, q as ErrorResponse, F as FormatInput, G as GetComposerOptions, r as GetOptions, s as PromptConfig, t as PromptId, u as PromptMessage, v as PromptRequest, w as PromptResponse, x as PromptResult, y as PromptVariableMap, z as PromptVersion, A as PublishedVersion, S as SchemaField, B as SchemaFieldParams, V as ValidationRule } from './types-DyMq5QKO.js';
1
+ import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-BbNpKJej.js';
2
+ export { b as ErrorResponse, G as GetOptions, c as PromptConfig, d as PromptId, e as PromptMessage, f as PromptRequest, g as PromptResponse, h as PromptResult, i as PromptVariableMap, j as PromptVersion, k as PublishedVersion, S as SchemaField, l as SchemaFieldParams, V as ValidationRule } from './types-BbNpKJej.js';
3
3
  import 'ai';
4
4
 
5
5
  declare const getSdkModelId: (modelId: string) => string;
6
6
  declare const interpolate: (template: string, variables: Record<string, string>) => string;
7
- declare const toCamelCase: (name: string) => string;
8
- declare const interpolateStaticSegment: (content: string, input: Record<string, string>) => string;
9
7
  declare const createPromptlyClient: (config?: PromptlyClientConfig) => PromptlyClient;
10
8
 
11
9
  declare class PromptlyError extends Error {
@@ -16,4 +14,4 @@ declare class PromptlyError extends Error {
16
14
  constructor(message: string, code: ErrorCode, status: number, usage?: unknown, upgradeUrl?: string);
17
15
  }
18
16
 
19
- export { ErrorCode, PromptlyClient, PromptlyClientConfig, PromptlyError, createPromptlyClient, getSdkModelId, interpolate, interpolateStaticSegment, toCamelCase };
17
+ export { ErrorCode, PromptlyClient, PromptlyClientConfig, PromptlyError, createPromptlyClient, getSdkModelId, interpolate };
package/dist/index.js CHANGED
@@ -141,26 +141,6 @@ var createModelResolver = (config) => {
141
141
  );
142
142
  };
143
143
  };
144
- var toCamelCase = (name) => name.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()).replace(/^[A-Z]/, (char) => char.toLowerCase());
145
- var VARIABLE_REF_REGEX = /<span[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*\sdata-field-path="([^"]+)"[^>]*><\/span>/g;
146
- var VARIABLE_REF_ALT_REGEX = /<span[^>]*\sdata-field-path="([^"]+)"[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*><\/span>/g;
147
- var MUSTACHE_REGEX = /\{\{(\w[\w.]*)\}\}/g;
148
- var interpolateStaticSegment = (content, input) => {
149
- let result = content;
150
- result = result.replace(
151
- VARIABLE_REF_REGEX,
152
- (_, fieldPath) => input[fieldPath] ?? ""
153
- );
154
- result = result.replace(
155
- VARIABLE_REF_ALT_REGEX,
156
- (_, fieldPath) => input[fieldPath] ?? ""
157
- );
158
- result = result.replace(
159
- MUSTACHE_REGEX,
160
- (_, fieldPath) => input[fieldPath] ?? ""
161
- );
162
- return result;
163
- };
164
144
  var createPromptlyClient = (config) => {
165
145
  const apiKey = config?.apiKey ?? process.env.PROMPTLY_API_KEY;
166
146
  if (!apiKey) {
@@ -205,118 +185,11 @@ var createPromptlyClient = (config) => {
205
185
  );
206
186
  return results;
207
187
  };
208
- const fetchComposer = async (composerId, options) => {
209
- const url = new URL(`/composers/${composerId}`, baseUrl);
210
- if (options?.version) {
211
- url.searchParams.set("version", options.version);
212
- }
213
- const response = await fetch(url.toString(), {
214
- headers: {
215
- Authorization: `Bearer ${apiKey}`
216
- }
217
- });
218
- if (!response.ok) {
219
- throw await createErrorFromResponse(response);
220
- }
221
- return response.json();
222
- };
223
- const getComposer = async (composerId, options) => {
224
- const response = await fetchComposer(composerId, options);
225
- const input = options?.input ?? {};
226
- const promptsByName = /* @__PURE__ */ new Map();
227
- const promptsOrdered = [];
228
- const processedSegments = [];
229
- for (const segment of response.segments) {
230
- if (segment.type === "static") {
231
- processedSegments.push({
232
- type: "static",
233
- content: interpolateStaticSegment(segment.content, input)
234
- });
235
- continue;
236
- }
237
- const camelName = toCamelCase(segment.promptName);
238
- if (!promptsByName.has(camelName)) {
239
- const segmentConfig = segment.config;
240
- const model = await modelResolver(segmentConfig.model ?? "");
241
- const userMessage = segment.userMessage ? interpolate(segment.userMessage, input) : "";
242
- const temperature = segmentConfig.temperature ?? 0.7;
243
- const composerPrompt = {
244
- model,
245
- system: segment.systemMessage ?? void 0,
246
- prompt: userMessage,
247
- temperature,
248
- promptId: segment.promptId,
249
- promptName: segment.promptName
250
- };
251
- promptsByName.set(camelName, composerPrompt);
252
- promptsOrdered.push(composerPrompt);
253
- }
254
- processedSegments.push({ type: "prompt", camelName });
255
- }
256
- const formatComposer = (results) => {
257
- const parts = [];
258
- for (const seg of processedSegments) {
259
- if (seg.type === "static") {
260
- parts.push(seg.content);
261
- continue;
262
- }
263
- const val = results[seg.camelName];
264
- if (val === void 0) {
265
- continue;
266
- }
267
- parts.push(typeof val === "string" ? val : val.text);
268
- }
269
- return parts.join("");
270
- };
271
- const compose = async (generate) => {
272
- const entries = [...promptsByName.entries()];
273
- const results = await Promise.all(
274
- entries.map(([, prompt]) => generate(prompt))
275
- );
276
- const resultMap = {};
277
- entries.forEach(([name], i) => {
278
- resultMap[name] = results[i] ?? "";
279
- });
280
- return formatComposer(resultMap);
281
- };
282
- const result = {
283
- composerId: response.composerId,
284
- composerName: response.composerName,
285
- version: response.version,
286
- config: response.config,
287
- segments: response.segments,
288
- prompts: promptsOrdered,
289
- formatComposer,
290
- compose
291
- };
292
- for (const [name, prompt] of promptsByName) {
293
- result[name] = prompt;
294
- }
295
- return result;
296
- };
297
- const getComposers = async (entries) => {
298
- const results = await Promise.all(
299
- entries.map(
300
- (entry) => getComposer(entry.composerId, {
301
- input: entry.input,
302
- version: entry.version
303
- })
304
- )
305
- );
306
- return results;
307
- };
308
- return {
309
- getPrompt,
310
- getPrompts,
311
- getComposer,
312
- getComposers
313
- };
188
+ return { getPrompt, getPrompts };
314
189
  };
315
190
  export {
316
191
  PromptlyError,
317
192
  createPromptlyClient,
318
193
  getSdkModelId,
319
- interpolate,
320
- interpolateStaticSegment,
321
- toCamelCase
194
+ interpolate
322
195
  };
package/dist/schema.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { S as SchemaField } from './types-DyMq5QKO.cjs';
2
+ import { S as SchemaField } from './types-BbNpKJej.cjs';
3
3
  import 'ai';
4
4
 
5
5
  declare const buildFieldSchema: (field: SchemaField) => z.ZodTypeAny;
package/dist/schema.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { S as SchemaField } from './types-DyMq5QKO.js';
2
+ import { S as SchemaField } from './types-BbNpKJej.js';
3
3
  import 'ai';
4
4
 
5
5
  declare const buildFieldSchema: (field: SchemaField) => z.ZodTypeAny;
@@ -0,0 +1,118 @@
1
+ import * as ai from 'ai';
2
+
3
+ type ValidationRule = {
4
+ id: string;
5
+ type: string;
6
+ message: string;
7
+ value: string;
8
+ transform?: string;
9
+ keyType?: string;
10
+ valueType?: string;
11
+ discriminator?: string;
12
+ cases?: Record<string, SchemaField[]>;
13
+ };
14
+ type SchemaFieldParams = {
15
+ coerce?: boolean;
16
+ description?: string;
17
+ enumValues?: string[];
18
+ unionTypes?: string[];
19
+ elementType?: string;
20
+ keyType?: string;
21
+ valueType?: string;
22
+ isTuple?: boolean;
23
+ tupleTypes?: string[];
24
+ isStrict?: boolean;
25
+ isPassthrough?: boolean;
26
+ isDiscriminatedUnion?: boolean;
27
+ discriminator?: string;
28
+ discriminatedUnion?: {
29
+ discriminator: string;
30
+ cases: Record<string, {
31
+ value: string;
32
+ fields: SchemaField[];
33
+ }>;
34
+ };
35
+ stringOptions?: {
36
+ datetime?: {
37
+ offset?: boolean;
38
+ precision?: number;
39
+ };
40
+ ip?: {
41
+ version?: 'v4' | 'v6';
42
+ };
43
+ };
44
+ };
45
+ type SchemaField = {
46
+ id: string;
47
+ name: string;
48
+ type: string;
49
+ validations: ValidationRule[];
50
+ params: SchemaFieldParams;
51
+ };
52
+ type PromptConfig = {
53
+ schema: SchemaField[];
54
+ model: string;
55
+ temperature: number;
56
+ inputData: unknown;
57
+ inputDataRootName: string | null;
58
+ };
59
+ type PublishedVersion = {
60
+ version: string;
61
+ userMessage: string;
62
+ };
63
+ type PromptResponse = {
64
+ promptId: string;
65
+ promptName: string;
66
+ version: string;
67
+ systemMessage: string;
68
+ userMessage: string;
69
+ config: PromptConfig;
70
+ publishedVersions?: PublishedVersion[];
71
+ };
72
+ interface PromptVariableMap {
73
+ }
74
+ type PromptId = keyof PromptVariableMap | (string & {});
75
+ type PromptVersion<Id extends string> = Id extends keyof PromptVariableMap ? Exclude<keyof PromptVariableMap[Id], 'latest'> : string;
76
+ type VariablesFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof PromptVariableMap ? Ver extends keyof PromptVariableMap[Id] ? PromptVariableMap[Id][Ver] : Record<string, string> : Record<string, string>;
77
+ type PromptMessage<V extends Record<string, string> = Record<string, string>> = {
78
+ (variables: V): string;
79
+ toString(): string;
80
+ };
81
+ type PromptResult<V extends Record<string, string> = Record<string, string>> = Omit<PromptResponse, 'userMessage'> & {
82
+ userMessage: PromptMessage<V>;
83
+ temperature: number;
84
+ model: ai.LanguageModel;
85
+ };
86
+ type PromptRequest = {
87
+ promptId: string;
88
+ version?: string;
89
+ };
90
+ type GetPromptsResults<T extends readonly PromptRequest[]> = {
91
+ [K in keyof T]: T[K] extends {
92
+ promptId: infer Id extends string;
93
+ version: infer Ver extends string;
94
+ } ? PromptResult<VariablesFor<Id, Ver>> : T[K] extends {
95
+ promptId: infer Id extends string;
96
+ } ? PromptResult<VariablesFor<Id, 'latest'>> : PromptResult;
97
+ };
98
+ type ErrorCode = 'UNAUTHORIZED' | 'INVALID_KEY' | 'NOT_FOUND' | 'VERSION_NOT_FOUND' | 'BAD_REQUEST' | 'USAGE_LIMIT_EXCEEDED';
99
+ type ErrorResponse = {
100
+ error: string;
101
+ code: ErrorCode;
102
+ usage?: unknown;
103
+ upgradeUrl?: string;
104
+ };
105
+ type PromptlyClientConfig = {
106
+ apiKey?: string;
107
+ baseUrl?: string;
108
+ model?: (modelId: string) => ai.LanguageModel;
109
+ };
110
+ type GetOptions<V extends string = string> = {
111
+ version?: V;
112
+ };
113
+ type PromptlyClient = {
114
+ getPrompt: <T extends string, V extends PromptVersion<T> | 'latest' = 'latest'>(promptId: T, options?: GetOptions<V>) => Promise<PromptResult<VariablesFor<T, V>>>;
115
+ getPrompts: <const T extends readonly PromptRequest[]>(entries: T) => Promise<GetPromptsResults<T>>;
116
+ };
117
+
118
+ export type { ErrorCode as E, GetOptions as G, PromptlyClientConfig as P, SchemaField as S, ValidationRule as V, PromptlyClient as a, ErrorResponse as b, PromptConfig as c, PromptId as d, PromptMessage as e, PromptRequest as f, PromptResponse as g, PromptResult as h, PromptVariableMap as i, PromptVersion as j, PublishedVersion as k, SchemaFieldParams as l };
@@ -0,0 +1,118 @@
1
+ import * as ai from 'ai';
2
+
3
+ type ValidationRule = {
4
+ id: string;
5
+ type: string;
6
+ message: string;
7
+ value: string;
8
+ transform?: string;
9
+ keyType?: string;
10
+ valueType?: string;
11
+ discriminator?: string;
12
+ cases?: Record<string, SchemaField[]>;
13
+ };
14
+ type SchemaFieldParams = {
15
+ coerce?: boolean;
16
+ description?: string;
17
+ enumValues?: string[];
18
+ unionTypes?: string[];
19
+ elementType?: string;
20
+ keyType?: string;
21
+ valueType?: string;
22
+ isTuple?: boolean;
23
+ tupleTypes?: string[];
24
+ isStrict?: boolean;
25
+ isPassthrough?: boolean;
26
+ isDiscriminatedUnion?: boolean;
27
+ discriminator?: string;
28
+ discriminatedUnion?: {
29
+ discriminator: string;
30
+ cases: Record<string, {
31
+ value: string;
32
+ fields: SchemaField[];
33
+ }>;
34
+ };
35
+ stringOptions?: {
36
+ datetime?: {
37
+ offset?: boolean;
38
+ precision?: number;
39
+ };
40
+ ip?: {
41
+ version?: 'v4' | 'v6';
42
+ };
43
+ };
44
+ };
45
+ type SchemaField = {
46
+ id: string;
47
+ name: string;
48
+ type: string;
49
+ validations: ValidationRule[];
50
+ params: SchemaFieldParams;
51
+ };
52
+ type PromptConfig = {
53
+ schema: SchemaField[];
54
+ model: string;
55
+ temperature: number;
56
+ inputData: unknown;
57
+ inputDataRootName: string | null;
58
+ };
59
+ type PublishedVersion = {
60
+ version: string;
61
+ userMessage: string;
62
+ };
63
+ type PromptResponse = {
64
+ promptId: string;
65
+ promptName: string;
66
+ version: string;
67
+ systemMessage: string;
68
+ userMessage: string;
69
+ config: PromptConfig;
70
+ publishedVersions?: PublishedVersion[];
71
+ };
72
+ interface PromptVariableMap {
73
+ }
74
+ type PromptId = keyof PromptVariableMap | (string & {});
75
+ type PromptVersion<Id extends string> = Id extends keyof PromptVariableMap ? Exclude<keyof PromptVariableMap[Id], 'latest'> : string;
76
+ type VariablesFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof PromptVariableMap ? Ver extends keyof PromptVariableMap[Id] ? PromptVariableMap[Id][Ver] : Record<string, string> : Record<string, string>;
77
+ type PromptMessage<V extends Record<string, string> = Record<string, string>> = {
78
+ (variables: V): string;
79
+ toString(): string;
80
+ };
81
+ type PromptResult<V extends Record<string, string> = Record<string, string>> = Omit<PromptResponse, 'userMessage'> & {
82
+ userMessage: PromptMessage<V>;
83
+ temperature: number;
84
+ model: ai.LanguageModel;
85
+ };
86
+ type PromptRequest = {
87
+ promptId: string;
88
+ version?: string;
89
+ };
90
+ type GetPromptsResults<T extends readonly PromptRequest[]> = {
91
+ [K in keyof T]: T[K] extends {
92
+ promptId: infer Id extends string;
93
+ version: infer Ver extends string;
94
+ } ? PromptResult<VariablesFor<Id, Ver>> : T[K] extends {
95
+ promptId: infer Id extends string;
96
+ } ? PromptResult<VariablesFor<Id, 'latest'>> : PromptResult;
97
+ };
98
+ type ErrorCode = 'UNAUTHORIZED' | 'INVALID_KEY' | 'NOT_FOUND' | 'VERSION_NOT_FOUND' | 'BAD_REQUEST' | 'USAGE_LIMIT_EXCEEDED';
99
+ type ErrorResponse = {
100
+ error: string;
101
+ code: ErrorCode;
102
+ usage?: unknown;
103
+ upgradeUrl?: string;
104
+ };
105
+ type PromptlyClientConfig = {
106
+ apiKey?: string;
107
+ baseUrl?: string;
108
+ model?: (modelId: string) => ai.LanguageModel;
109
+ };
110
+ type GetOptions<V extends string = string> = {
111
+ version?: V;
112
+ };
113
+ type PromptlyClient = {
114
+ getPrompt: <T extends string, V extends PromptVersion<T> | 'latest' = 'latest'>(promptId: T, options?: GetOptions<V>) => Promise<PromptResult<VariablesFor<T, V>>>;
115
+ getPrompts: <const T extends readonly PromptRequest[]>(entries: T) => Promise<GetPromptsResults<T>>;
116
+ };
117
+
118
+ export type { ErrorCode as E, GetOptions as G, PromptlyClientConfig as P, SchemaField as S, ValidationRule as V, PromptlyClient as a, ErrorResponse as b, PromptConfig as c, PromptId as d, PromptMessage as e, PromptRequest as f, PromptResponse as g, PromptResult as h, PromptVariableMap as i, PromptVersion as j, PublishedVersion as k, SchemaFieldParams as l };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptlycms/prompts",
3
- "version": "0.2.0-canary.1db6dca",
3
+ "version": "0.2.0",
4
4
  "description": "TypeScript SDK for Promptly CMS — fetch prompts, build Zod schemas, generate typed code",
5
5
  "type": "module",
6
6
  "exports": {
@@ -36,23 +36,23 @@
36
36
  "citty": "^0.2.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@ai-sdk/anthropic": "^3.0.63",
40
- "@ai-sdk/google": "^3.0.53",
41
- "@ai-sdk/mistral": "^3.0.27",
42
- "@ai-sdk/openai": "^3.0.48",
43
- "@biomejs/biome": "^2.4.8",
44
- "@changesets/changelog-github": "^0.6.0",
45
- "@changesets/cli": "^2.30.0",
46
- "@types/bun": "1.3.11",
47
- "@typescript/native-preview": "^7.0.0-dev.20260323.1",
48
- "ai": "^6.0.137",
39
+ "@ai-sdk/anthropic": "^3.0.45",
40
+ "@ai-sdk/google": "^3.0.29",
41
+ "@ai-sdk/mistral": "^3.0.20",
42
+ "@ai-sdk/openai": "^3.0.29",
43
+ "@biomejs/biome": "^2.4.2",
44
+ "@changesets/changelog-github": "^0.5.2",
45
+ "@changesets/cli": "^2.29.8",
46
+ "@types/bun": "latest",
47
+ "@typescript/native-preview": "^7.0.0-dev.20260217.1",
48
+ "ai": "^6.0.89",
49
49
  "tsup": "^8.5.1",
50
50
  "zod": "^4.3.6"
51
51
  },
52
52
  "peerDependencies": {
53
- "typescript": "^6.0.2",
53
+ "typescript": "^5",
54
54
  "zod": "^4.0.0",
55
- "ai": "^6.0.137"
55
+ "ai": "^6.0.89"
56
56
  },
57
57
  "peerDependenciesMeta": {
58
58
  "@ai-sdk/anthropic": {
@@ -1,198 +0,0 @@
1
- import * as ai from 'ai';
2
-
3
- type ValidationRule = {
4
- id: string;
5
- type: string;
6
- message: string;
7
- value: string;
8
- transform?: string;
9
- keyType?: string;
10
- valueType?: string;
11
- discriminator?: string;
12
- cases?: Record<string, SchemaField[]>;
13
- };
14
- type SchemaFieldParams = {
15
- coerce?: boolean;
16
- description?: string;
17
- enumValues?: string[];
18
- unionTypes?: string[];
19
- elementType?: string;
20
- keyType?: string;
21
- valueType?: string;
22
- isTuple?: boolean;
23
- tupleTypes?: string[];
24
- isStrict?: boolean;
25
- isPassthrough?: boolean;
26
- isDiscriminatedUnion?: boolean;
27
- discriminator?: string;
28
- discriminatedUnion?: {
29
- discriminator: string;
30
- cases: Record<string, {
31
- value: string;
32
- fields: SchemaField[];
33
- }>;
34
- };
35
- stringOptions?: {
36
- datetime?: {
37
- offset?: boolean;
38
- precision?: number;
39
- };
40
- ip?: {
41
- version?: 'v4' | 'v6';
42
- };
43
- };
44
- };
45
- type SchemaField = {
46
- id: string;
47
- name: string;
48
- type: string;
49
- validations: ValidationRule[];
50
- params: SchemaFieldParams;
51
- };
52
- type PromptConfig = {
53
- schema: SchemaField[];
54
- model: string;
55
- temperature: number;
56
- inputData: unknown;
57
- inputDataRootName: string | null;
58
- };
59
- type PublishedVersion = {
60
- version: string;
61
- userMessage: string;
62
- };
63
- type PromptResponse = {
64
- promptId: string;
65
- promptName: string;
66
- version: string;
67
- systemMessage: string;
68
- userMessage: string;
69
- config: PromptConfig;
70
- publishedVersions?: PublishedVersion[];
71
- };
72
- interface PromptVariableMap {
73
- }
74
- type PromptId = keyof PromptVariableMap | (string & {});
75
- type PromptVersion<Id extends string> = Id extends keyof PromptVariableMap ? Exclude<keyof PromptVariableMap[Id], 'latest'> : string;
76
- type VariablesFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof PromptVariableMap ? Ver extends keyof PromptVariableMap[Id] ? PromptVariableMap[Id][Ver] : Record<string, string> : Record<string, string>;
77
- type PromptMessage<V extends Record<string, string> = Record<string, string>> = {
78
- (variables: V): string;
79
- toString(): string;
80
- };
81
- type PromptResult<V extends Record<string, string> = Record<string, string>> = Omit<PromptResponse, 'userMessage'> & {
82
- userMessage: PromptMessage<V>;
83
- temperature: number;
84
- model: ai.LanguageModel;
85
- };
86
- type PromptRequest = {
87
- promptId: string;
88
- version?: string;
89
- };
90
- type GetPromptsResults<T extends readonly PromptRequest[]> = {
91
- [K in keyof T]: T[K] extends {
92
- promptId: infer Id extends string;
93
- version: infer Ver extends string;
94
- } ? PromptResult<VariablesFor<Id, Ver>> : T[K] extends {
95
- promptId: infer Id extends string;
96
- } ? PromptResult<VariablesFor<Id, 'latest'>> : PromptResult;
97
- };
98
- type ComposerStaticSegment = {
99
- type: 'static';
100
- content: string;
101
- };
102
- type ComposerPromptSegment = {
103
- type: 'prompt';
104
- promptId: string;
105
- promptName: string;
106
- version: string;
107
- systemMessage: string | null;
108
- userMessage: string | null;
109
- config: Record<string, unknown>;
110
- };
111
- type ComposerSegment = ComposerStaticSegment | ComposerPromptSegment;
112
- type ComposerConfig = {
113
- schema: SchemaField[];
114
- inputData: unknown;
115
- inputDataRootName: string | null;
116
- };
117
- type ComposerResponse = {
118
- composerId: string;
119
- composerName: string;
120
- version: string;
121
- config: ComposerConfig;
122
- segments: ComposerSegment[];
123
- publishedVersions?: {
124
- version: string;
125
- }[];
126
- };
127
- interface ComposerVariableMap {
128
- }
129
- interface ComposerPromptMap {
130
- }
131
- type ComposerId = keyof ComposerVariableMap | (string & {});
132
- type ComposerVersion<Id extends string> = Id extends keyof ComposerVariableMap ? Exclude<keyof ComposerVariableMap[Id], 'latest'> : string;
133
- type ComposerInputFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof ComposerVariableMap ? Ver extends keyof ComposerVariableMap[Id] ? ComposerVariableMap[Id][Ver] : Record<string, string> : Record<string, string>;
134
- type ComposerPromptNamesFor<Id extends string> = Id extends keyof ComposerPromptMap ? ComposerPromptMap[Id] : string;
135
- type ComposerPrompt = {
136
- model: ai.LanguageModel;
137
- system: string | undefined;
138
- prompt: string;
139
- temperature: number;
140
- promptId: string;
141
- promptName: string;
142
- };
143
- type FormatInput = {
144
- text: string;
145
- } | string;
146
- type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<{
147
- text: string;
148
- } | string>;
149
- type ComposerFormatFn<Names extends string = string> = (results: Record<Names, FormatInput>) => string;
150
- type ComposerResult<Names extends string = string> = {
151
- composerId: string;
152
- composerName: string;
153
- version: string;
154
- config: ComposerConfig;
155
- segments: ComposerSegment[];
156
- prompts: ComposerPrompt[];
157
- formatComposer: ComposerFormatFn<Names>;
158
- compose: (generate: ComposerGenerateFn) => Promise<string>;
159
- } & {
160
- [K in Names]: ComposerPrompt;
161
- };
162
- type GetComposerOptions<Id extends string = string, V extends string = 'latest'> = {
163
- input?: ComposerInputFor<Id, V>;
164
- version?: V;
165
- };
166
- type ComposerRequest = {
167
- composerId: string;
168
- input?: Record<string, string>;
169
- version?: string;
170
- };
171
- type GetComposersResults<T extends readonly ComposerRequest[]> = {
172
- [K in keyof T]: T[K] extends {
173
- composerId: infer Id extends string;
174
- } ? ComposerResult<ComposerPromptNamesFor<Id>> : ComposerResult;
175
- };
176
- type ErrorCode = 'UNAUTHORIZED' | 'INVALID_KEY' | 'NOT_FOUND' | 'VERSION_NOT_FOUND' | 'BAD_REQUEST' | 'USAGE_LIMIT_EXCEEDED' | 'UNRESOLVED_PROMPT';
177
- type ErrorResponse = {
178
- error: string;
179
- code: ErrorCode;
180
- usage?: unknown;
181
- upgradeUrl?: string;
182
- };
183
- type PromptlyClientConfig = {
184
- apiKey?: string;
185
- baseUrl?: string;
186
- model?: (modelId: string) => ai.LanguageModel;
187
- };
188
- type GetOptions<V extends string = string> = {
189
- version?: V;
190
- };
191
- type PromptlyClient = {
192
- getPrompt: <T extends string, V extends PromptVersion<T> | 'latest' = 'latest'>(promptId: T, options?: GetOptions<V>) => Promise<PromptResult<VariablesFor<T, V>>>;
193
- getPrompts: <const T extends readonly PromptRequest[]>(entries: T) => Promise<GetPromptsResults<T>>;
194
- getComposer: <T extends string, V extends ComposerVersion<T> | 'latest' = 'latest'>(composerId: T, options?: GetComposerOptions<T, V>) => Promise<ComposerResult<ComposerPromptNamesFor<T>>>;
195
- getComposers: <const T extends readonly ComposerRequest[]>(entries: T) => Promise<GetComposersResults<T>>;
196
- };
197
-
198
- export type { PublishedVersion as A, SchemaFieldParams as B, ComposerConfig as C, ErrorCode as E, FormatInput as F, GetComposerOptions as G, PromptlyClientConfig as P, SchemaField as S, ValidationRule as V, PromptlyClient as a, ComposerFormatFn as b, ComposerGenerateFn as c, ComposerId as d, ComposerInputFor as e, ComposerPrompt as f, ComposerPromptMap as g, ComposerPromptNamesFor as h, ComposerPromptSegment as i, ComposerRequest as j, ComposerResponse as k, ComposerResult as l, ComposerSegment as m, ComposerStaticSegment as n, ComposerVariableMap as o, ComposerVersion as p, ErrorResponse as q, GetOptions as r, PromptConfig as s, PromptId as t, PromptMessage as u, PromptRequest as v, PromptResponse as w, PromptResult as x, PromptVariableMap as y, PromptVersion as z };
@@ -1,198 +0,0 @@
1
- import * as ai from 'ai';
2
-
3
- type ValidationRule = {
4
- id: string;
5
- type: string;
6
- message: string;
7
- value: string;
8
- transform?: string;
9
- keyType?: string;
10
- valueType?: string;
11
- discriminator?: string;
12
- cases?: Record<string, SchemaField[]>;
13
- };
14
- type SchemaFieldParams = {
15
- coerce?: boolean;
16
- description?: string;
17
- enumValues?: string[];
18
- unionTypes?: string[];
19
- elementType?: string;
20
- keyType?: string;
21
- valueType?: string;
22
- isTuple?: boolean;
23
- tupleTypes?: string[];
24
- isStrict?: boolean;
25
- isPassthrough?: boolean;
26
- isDiscriminatedUnion?: boolean;
27
- discriminator?: string;
28
- discriminatedUnion?: {
29
- discriminator: string;
30
- cases: Record<string, {
31
- value: string;
32
- fields: SchemaField[];
33
- }>;
34
- };
35
- stringOptions?: {
36
- datetime?: {
37
- offset?: boolean;
38
- precision?: number;
39
- };
40
- ip?: {
41
- version?: 'v4' | 'v6';
42
- };
43
- };
44
- };
45
- type SchemaField = {
46
- id: string;
47
- name: string;
48
- type: string;
49
- validations: ValidationRule[];
50
- params: SchemaFieldParams;
51
- };
52
- type PromptConfig = {
53
- schema: SchemaField[];
54
- model: string;
55
- temperature: number;
56
- inputData: unknown;
57
- inputDataRootName: string | null;
58
- };
59
- type PublishedVersion = {
60
- version: string;
61
- userMessage: string;
62
- };
63
- type PromptResponse = {
64
- promptId: string;
65
- promptName: string;
66
- version: string;
67
- systemMessage: string;
68
- userMessage: string;
69
- config: PromptConfig;
70
- publishedVersions?: PublishedVersion[];
71
- };
72
- interface PromptVariableMap {
73
- }
74
- type PromptId = keyof PromptVariableMap | (string & {});
75
- type PromptVersion<Id extends string> = Id extends keyof PromptVariableMap ? Exclude<keyof PromptVariableMap[Id], 'latest'> : string;
76
- type VariablesFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof PromptVariableMap ? Ver extends keyof PromptVariableMap[Id] ? PromptVariableMap[Id][Ver] : Record<string, string> : Record<string, string>;
77
- type PromptMessage<V extends Record<string, string> = Record<string, string>> = {
78
- (variables: V): string;
79
- toString(): string;
80
- };
81
- type PromptResult<V extends Record<string, string> = Record<string, string>> = Omit<PromptResponse, 'userMessage'> & {
82
- userMessage: PromptMessage<V>;
83
- temperature: number;
84
- model: ai.LanguageModel;
85
- };
86
- type PromptRequest = {
87
- promptId: string;
88
- version?: string;
89
- };
90
- type GetPromptsResults<T extends readonly PromptRequest[]> = {
91
- [K in keyof T]: T[K] extends {
92
- promptId: infer Id extends string;
93
- version: infer Ver extends string;
94
- } ? PromptResult<VariablesFor<Id, Ver>> : T[K] extends {
95
- promptId: infer Id extends string;
96
- } ? PromptResult<VariablesFor<Id, 'latest'>> : PromptResult;
97
- };
98
- type ComposerStaticSegment = {
99
- type: 'static';
100
- content: string;
101
- };
102
- type ComposerPromptSegment = {
103
- type: 'prompt';
104
- promptId: string;
105
- promptName: string;
106
- version: string;
107
- systemMessage: string | null;
108
- userMessage: string | null;
109
- config: Record<string, unknown>;
110
- };
111
- type ComposerSegment = ComposerStaticSegment | ComposerPromptSegment;
112
- type ComposerConfig = {
113
- schema: SchemaField[];
114
- inputData: unknown;
115
- inputDataRootName: string | null;
116
- };
117
- type ComposerResponse = {
118
- composerId: string;
119
- composerName: string;
120
- version: string;
121
- config: ComposerConfig;
122
- segments: ComposerSegment[];
123
- publishedVersions?: {
124
- version: string;
125
- }[];
126
- };
127
- interface ComposerVariableMap {
128
- }
129
- interface ComposerPromptMap {
130
- }
131
- type ComposerId = keyof ComposerVariableMap | (string & {});
132
- type ComposerVersion<Id extends string> = Id extends keyof ComposerVariableMap ? Exclude<keyof ComposerVariableMap[Id], 'latest'> : string;
133
- type ComposerInputFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof ComposerVariableMap ? Ver extends keyof ComposerVariableMap[Id] ? ComposerVariableMap[Id][Ver] : Record<string, string> : Record<string, string>;
134
- type ComposerPromptNamesFor<Id extends string> = Id extends keyof ComposerPromptMap ? ComposerPromptMap[Id] : string;
135
- type ComposerPrompt = {
136
- model: ai.LanguageModel;
137
- system: string | undefined;
138
- prompt: string;
139
- temperature: number;
140
- promptId: string;
141
- promptName: string;
142
- };
143
- type FormatInput = {
144
- text: string;
145
- } | string;
146
- type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<{
147
- text: string;
148
- } | string>;
149
- type ComposerFormatFn<Names extends string = string> = (results: Record<Names, FormatInput>) => string;
150
- type ComposerResult<Names extends string = string> = {
151
- composerId: string;
152
- composerName: string;
153
- version: string;
154
- config: ComposerConfig;
155
- segments: ComposerSegment[];
156
- prompts: ComposerPrompt[];
157
- formatComposer: ComposerFormatFn<Names>;
158
- compose: (generate: ComposerGenerateFn) => Promise<string>;
159
- } & {
160
- [K in Names]: ComposerPrompt;
161
- };
162
- type GetComposerOptions<Id extends string = string, V extends string = 'latest'> = {
163
- input?: ComposerInputFor<Id, V>;
164
- version?: V;
165
- };
166
- type ComposerRequest = {
167
- composerId: string;
168
- input?: Record<string, string>;
169
- version?: string;
170
- };
171
- type GetComposersResults<T extends readonly ComposerRequest[]> = {
172
- [K in keyof T]: T[K] extends {
173
- composerId: infer Id extends string;
174
- } ? ComposerResult<ComposerPromptNamesFor<Id>> : ComposerResult;
175
- };
176
- type ErrorCode = 'UNAUTHORIZED' | 'INVALID_KEY' | 'NOT_FOUND' | 'VERSION_NOT_FOUND' | 'BAD_REQUEST' | 'USAGE_LIMIT_EXCEEDED' | 'UNRESOLVED_PROMPT';
177
- type ErrorResponse = {
178
- error: string;
179
- code: ErrorCode;
180
- usage?: unknown;
181
- upgradeUrl?: string;
182
- };
183
- type PromptlyClientConfig = {
184
- apiKey?: string;
185
- baseUrl?: string;
186
- model?: (modelId: string) => ai.LanguageModel;
187
- };
188
- type GetOptions<V extends string = string> = {
189
- version?: V;
190
- };
191
- type PromptlyClient = {
192
- getPrompt: <T extends string, V extends PromptVersion<T> | 'latest' = 'latest'>(promptId: T, options?: GetOptions<V>) => Promise<PromptResult<VariablesFor<T, V>>>;
193
- getPrompts: <const T extends readonly PromptRequest[]>(entries: T) => Promise<GetPromptsResults<T>>;
194
- getComposer: <T extends string, V extends ComposerVersion<T> | 'latest' = 'latest'>(composerId: T, options?: GetComposerOptions<T, V>) => Promise<ComposerResult<ComposerPromptNamesFor<T>>>;
195
- getComposers: <const T extends readonly ComposerRequest[]>(entries: T) => Promise<GetComposersResults<T>>;
196
- };
197
-
198
- export type { PublishedVersion as A, SchemaFieldParams as B, ComposerConfig as C, ErrorCode as E, FormatInput as F, GetComposerOptions as G, PromptlyClientConfig as P, SchemaField as S, ValidationRule as V, PromptlyClient as a, ComposerFormatFn as b, ComposerGenerateFn as c, ComposerId as d, ComposerInputFor as e, ComposerPrompt as f, ComposerPromptMap as g, ComposerPromptNamesFor as h, ComposerPromptSegment as i, ComposerRequest as j, ComposerResponse as k, ComposerResult as l, ComposerSegment as m, ComposerStaticSegment as n, ComposerVariableMap as o, ComposerVersion as p, ErrorResponse as q, GetOptions as r, PromptConfig as s, PromptId as t, PromptMessage as u, PromptRequest as v, PromptResponse as w, PromptResult as x, PromptVariableMap as y, PromptVersion as z };