@promptlycms/prompts 0.5.0 → 0.6.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
@@ -171,6 +171,11 @@ const output = formatComposer({
171
171
  });
172
172
  ```
173
173
 
174
+ Prompt results are treated as text by default. Newlines in strings or `{ text }`
175
+ results are preserved as `<br>` tags when the composer output is assembled. If a
176
+ prompt result already contains trusted HTML, pass `{ html: '<p>...</p>' }` to
177
+ `formatComposer()` to insert it without newline conversion.
178
+
174
179
  Batch fetch multiple composers in parallel:
175
180
 
176
181
  ```typescript
@@ -198,6 +203,9 @@ for (const segment of composer.segments) {
198
203
 
199
204
  Variable references inside an `html_block` (e.g. `<span data-variable-ref data-field-path="country">`) are interpolated normally during `formatComposer()` / `compose()`. Embedded prompt references inside an `html_block` are passed through opaquely — they aren't resolved as named prompts.
200
205
 
206
+ HTML blocks are otherwise left raw, including whitespace, comments, and empty
207
+ paragraphs.
208
+
201
209
  ## Model auto-detection
202
210
 
203
211
  The SDK automatically resolves models configured in the CMS to the correct AI SDK provider based on the model name prefix:
package/dist/index.cjs CHANGED
@@ -186,6 +186,21 @@ var toCamelCase = (name) => name.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.
186
186
  var VARIABLE_REF_REGEX = /<span[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*\sdata-field-path="([^"]+)"[^>]*><\/span>/g;
187
187
  var VARIABLE_REF_ALT_REGEX = /<span[^>]*\sdata-field-path="([^"]+)"[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*><\/span>/g;
188
188
  var MUSTACHE_REGEX = /\{\{(\w[\w.]*)\}\}/g;
189
+ var EMPTY_PARAGRAPH_REGEX = /<p(\s[^>]*)?>\s*<\/p>/gi;
190
+ var preserveEmptyParagraphs = (content) => content.replace(
191
+ EMPTY_PARAGRAPH_REGEX,
192
+ (_, attributes) => `<p${attributes ?? ""}><br></p>`
193
+ );
194
+ var preserveTextLineBreaks = (content) => content.replace(/\r\n?/g, "\n").replaceAll("\n", "<br>");
195
+ var formatComposerInput = (input) => {
196
+ if (typeof input === "string") {
197
+ return preserveTextLineBreaks(input);
198
+ }
199
+ if ("html" in input) {
200
+ return input.html;
201
+ }
202
+ return preserveTextLineBreaks(input.text);
203
+ };
189
204
  var interpolateStaticSegment = (content, input) => {
190
205
  let result = content;
191
206
  result = result.replace(
@@ -271,7 +286,9 @@ var createPromptlyClient = (config) => {
271
286
  if (segment.type === "static") {
272
287
  processedSegments.push({
273
288
  type: "static",
274
- content: interpolateStaticSegment(segment.content, input)
289
+ content: preserveEmptyParagraphs(
290
+ interpolateStaticSegment(segment.content, input)
291
+ )
275
292
  });
276
293
  continue;
277
294
  }
@@ -312,7 +329,7 @@ var createPromptlyClient = (config) => {
312
329
  if (val === void 0) {
313
330
  continue;
314
331
  }
315
- parts.push(typeof val === "string" ? val : val.text);
332
+ parts.push(formatComposerInput(val));
316
333
  }
317
334
  return parts.join("");
318
335
  };
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-DaIU82yN.cjs';
2
- export { C as ComposerConfig, b as ComposerFormatFn, c as ComposerGenerateFn, d as ComposerHtmlBlockSegment, e as ComposerId, f as ComposerInputFor, g as ComposerPrompt, h as ComposerPromptMap, i as ComposerPromptNamesFor, j as ComposerPromptSegment, k as ComposerRequest, l as ComposerResponse, m as ComposerResult, n as ComposerSegment, o as ComposerStaticSegment, p as ComposerVariableMap, q as ComposerVersion, r as ErrorResponse, F as FormatInput, G as GetComposerOptions, s as GetOptions, t as PromptConfig, u as PromptId, v as PromptMessage, w as PromptRequest, x as PromptResponse, y as PromptResult, z as PromptVariableMap, A as PromptVersion, B as PublishedVersion, S as SchemaField, D as SchemaFieldParams, V as ValidationRule } from './types-DaIU82yN.cjs';
1
+ import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-BStQVsgZ.cjs';
2
+ export { C as ComposerConfig, b as ComposerFormatFn, c as ComposerGenerateFn, d as ComposerHtmlBlockSegment, e as ComposerId, f as ComposerInputFor, g as ComposerPrompt, h as ComposerPromptMap, i as ComposerPromptNamesFor, j as ComposerPromptSegment, k as ComposerRequest, l as ComposerResponse, m as ComposerResult, n as ComposerSegment, o as ComposerStaticSegment, p as ComposerVariableMap, q as ComposerVersion, r as ErrorResponse, F as FormatInput, G as GetComposerOptions, s as GetOptions, t as PromptConfig, u as PromptId, v as PromptMessage, w as PromptRequest, x as PromptResponse, y as PromptResult, z as PromptVariableMap, A as PromptVersion, B as PublishedVersion, S as SchemaField, D as SchemaFieldParams, V as ValidationRule } from './types-BStQVsgZ.cjs';
3
3
  import 'ai';
4
4
 
5
5
  declare const getSdkModelId: (modelId: string) => string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-DaIU82yN.js';
2
- export { C as ComposerConfig, b as ComposerFormatFn, c as ComposerGenerateFn, d as ComposerHtmlBlockSegment, e as ComposerId, f as ComposerInputFor, g as ComposerPrompt, h as ComposerPromptMap, i as ComposerPromptNamesFor, j as ComposerPromptSegment, k as ComposerRequest, l as ComposerResponse, m as ComposerResult, n as ComposerSegment, o as ComposerStaticSegment, p as ComposerVariableMap, q as ComposerVersion, r as ErrorResponse, F as FormatInput, G as GetComposerOptions, s as GetOptions, t as PromptConfig, u as PromptId, v as PromptMessage, w as PromptRequest, x as PromptResponse, y as PromptResult, z as PromptVariableMap, A as PromptVersion, B as PublishedVersion, S as SchemaField, D as SchemaFieldParams, V as ValidationRule } from './types-DaIU82yN.js';
1
+ import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-BStQVsgZ.js';
2
+ export { C as ComposerConfig, b as ComposerFormatFn, c as ComposerGenerateFn, d as ComposerHtmlBlockSegment, e as ComposerId, f as ComposerInputFor, g as ComposerPrompt, h as ComposerPromptMap, i as ComposerPromptNamesFor, j as ComposerPromptSegment, k as ComposerRequest, l as ComposerResponse, m as ComposerResult, n as ComposerSegment, o as ComposerStaticSegment, p as ComposerVariableMap, q as ComposerVersion, r as ErrorResponse, F as FormatInput, G as GetComposerOptions, s as GetOptions, t as PromptConfig, u as PromptId, v as PromptMessage, w as PromptRequest, x as PromptResponse, y as PromptResult, z as PromptVariableMap, A as PromptVersion, B as PublishedVersion, S as SchemaField, D as SchemaFieldParams, V as ValidationRule } from './types-BStQVsgZ.js';
3
3
  import 'ai';
4
4
 
5
5
  declare const getSdkModelId: (modelId: string) => string;
package/dist/index.js CHANGED
@@ -145,6 +145,21 @@ var toCamelCase = (name) => name.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.
145
145
  var VARIABLE_REF_REGEX = /<span[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*\sdata-field-path="([^"]+)"[^>]*><\/span>/g;
146
146
  var VARIABLE_REF_ALT_REGEX = /<span[^>]*\sdata-field-path="([^"]+)"[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*><\/span>/g;
147
147
  var MUSTACHE_REGEX = /\{\{(\w[\w.]*)\}\}/g;
148
+ var EMPTY_PARAGRAPH_REGEX = /<p(\s[^>]*)?>\s*<\/p>/gi;
149
+ var preserveEmptyParagraphs = (content) => content.replace(
150
+ EMPTY_PARAGRAPH_REGEX,
151
+ (_, attributes) => `<p${attributes ?? ""}><br></p>`
152
+ );
153
+ var preserveTextLineBreaks = (content) => content.replace(/\r\n?/g, "\n").replaceAll("\n", "<br>");
154
+ var formatComposerInput = (input) => {
155
+ if (typeof input === "string") {
156
+ return preserveTextLineBreaks(input);
157
+ }
158
+ if ("html" in input) {
159
+ return input.html;
160
+ }
161
+ return preserveTextLineBreaks(input.text);
162
+ };
148
163
  var interpolateStaticSegment = (content, input) => {
149
164
  let result = content;
150
165
  result = result.replace(
@@ -230,7 +245,9 @@ var createPromptlyClient = (config) => {
230
245
  if (segment.type === "static") {
231
246
  processedSegments.push({
232
247
  type: "static",
233
- content: interpolateStaticSegment(segment.content, input)
248
+ content: preserveEmptyParagraphs(
249
+ interpolateStaticSegment(segment.content, input)
250
+ )
234
251
  });
235
252
  continue;
236
253
  }
@@ -271,7 +288,7 @@ var createPromptlyClient = (config) => {
271
288
  if (val === void 0) {
272
289
  continue;
273
290
  }
274
- parts.push(typeof val === "string" ? val : val.text);
291
+ parts.push(formatComposerInput(val));
275
292
  }
276
293
  return parts.join("");
277
294
  };
package/dist/schema.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { S as SchemaField } from './types-DaIU82yN.cjs';
2
+ import { S as SchemaField } from './types-BStQVsgZ.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-DaIU82yN.js';
2
+ import { S as SchemaField } from './types-BStQVsgZ.js';
3
3
  import 'ai';
4
4
 
5
5
  declare const buildFieldSchema: (field: SchemaField) => z.ZodTypeAny;
@@ -147,10 +147,10 @@ type ComposerPrompt = {
147
147
  };
148
148
  type FormatInput = {
149
149
  text: string;
150
+ } | {
151
+ html: string;
150
152
  } | string;
151
- type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<{
152
- text: string;
153
- } | string>;
153
+ type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<FormatInput>;
154
154
  type ComposerFormatFn<Names extends string = string> = (results: Record<Names, FormatInput>) => string;
155
155
  type ComposerResult<Names extends string = string> = {
156
156
  composerId: string;
@@ -147,10 +147,10 @@ type ComposerPrompt = {
147
147
  };
148
148
  type FormatInput = {
149
149
  text: string;
150
+ } | {
151
+ html: string;
150
152
  } | string;
151
- type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<{
152
- text: string;
153
- } | string>;
153
+ type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<FormatInput>;
154
154
  type ComposerFormatFn<Names extends string = string> = (results: Record<Names, FormatInput>) => string;
155
155
  type ComposerResult<Names extends string = string> = {
156
156
  composerId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptlycms/prompts",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "TypeScript SDK for Promptly CMS — fetch prompts, build Zod schemas, generate typed code",
5
5
  "type": "module",
6
6
  "exports": {