@promptlycms/prompts 0.4.1 → 0.5.0-canary.caa390f
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 +28 -2
- package/dist/cli.js +16 -3
- package/dist/index.cjs +26 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +26 -2
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/{types-DIVyjOlH.d.cts → types-BStQVsgZ.d.cts} +14 -9
- package/dist/{types-DIVyjOlH.d.ts → types-BStQVsgZ.d.ts} +14 -9
- package/package.json +1 -1
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
|
|
@@ -180,6 +185,27 @@ const [first, second] = await promptly.getComposers([
|
|
|
180
185
|
]);
|
|
181
186
|
```
|
|
182
187
|
|
|
188
|
+
### HTML blocks
|
|
189
|
+
|
|
190
|
+
Composers can contain raw HTML blocks (for vendor-specific markup like MSO conditional comments in transactional emails). These surface as a distinct `html_block` segment type:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const composer = await promptly.getComposer('my-email-composer', {
|
|
194
|
+
input: { country: 'United Kingdom' },
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
for (const segment of composer.segments) {
|
|
198
|
+
if (segment.type === 'html_block') {
|
|
199
|
+
console.log(segment.html); // raw HTML, byte-exact
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
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.
|
|
205
|
+
|
|
206
|
+
HTML blocks are otherwise left raw, including whitespace, comments, and empty
|
|
207
|
+
paragraphs.
|
|
208
|
+
|
|
183
209
|
## Model auto-detection
|
|
184
210
|
|
|
185
211
|
The SDK automatically resolves models configured in the CMS to the correct AI SDK provider based on the model name prefix:
|
|
@@ -232,7 +258,7 @@ declare module '@promptlycms/prompts' {
|
|
|
232
258
|
}
|
|
233
259
|
```
|
|
234
260
|
|
|
235
|
-
With this file present, `getPrompt()` and `getPrompts()` return typed `userMessage` functions with autocomplete. `getComposer()` and `getComposers()`
|
|
261
|
+
With this file present, `getPrompt()` and `getPrompts()` return typed `userMessage` functions with autocomplete. `getComposer()` and `getComposers()` only accept generated composer IDs, with typed `input` and named prompt properties. Unknown prompt IDs fall back to `Record<string, unknown>`.
|
|
236
262
|
|
|
237
263
|
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.
|
|
238
264
|
|
|
@@ -286,7 +312,7 @@ Fetch a single composer. Returns `ComposerResult` with named prompt properties,
|
|
|
286
312
|
|
|
287
313
|
| Option | Type | Description |
|
|
288
314
|
|-----------|---------------------------|----------------------|
|
|
289
|
-
| `input` | `Record<string,
|
|
315
|
+
| `input` | `Record<string, unknown>` | Template variables to interpolate |
|
|
290
316
|
| `version` | `string` | Specific version to fetch (default: latest) |
|
|
291
317
|
|
|
292
318
|
### `client.getComposers(entries)`
|
package/dist/cli.js
CHANGED
|
@@ -148,6 +148,10 @@ var extractComposerVariables = (composer) => {
|
|
|
148
148
|
for (const v of extractStaticSegmentVariables(segment.content)) {
|
|
149
149
|
vars.add(v);
|
|
150
150
|
}
|
|
151
|
+
} else if (segment.type === "html_block") {
|
|
152
|
+
for (const v of extractStaticSegmentVariables(segment.html)) {
|
|
153
|
+
vars.add(v);
|
|
154
|
+
}
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
return [...vars];
|
|
@@ -277,6 +281,13 @@ var buildSchemaMap = (schema) => {
|
|
|
277
281
|
}
|
|
278
282
|
return map;
|
|
279
283
|
};
|
|
284
|
+
var TYPE_IDENTIFIER_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
285
|
+
var typePropertyKey = (key) => {
|
|
286
|
+
if (TYPE_IDENTIFIER_RE.test(key)) {
|
|
287
|
+
return key;
|
|
288
|
+
}
|
|
289
|
+
return `'${key.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
290
|
+
};
|
|
280
291
|
var generateMappedTypeBlock = (group, indent, schemaMap = /* @__PURE__ */ new Map()) => {
|
|
281
292
|
const lines = [];
|
|
282
293
|
const { versions, variables } = group;
|
|
@@ -358,6 +369,7 @@ var generateTypeDeclaration = (prompts, composers = []) => {
|
|
|
358
369
|
lines.push(" interface ComposerVariableMap {");
|
|
359
370
|
for (const composer of composers) {
|
|
360
371
|
const variables = extractComposerVariables(composer);
|
|
372
|
+
const composerKey = typePropertyKey(composer.composerId);
|
|
361
373
|
const schemaMap = buildSchemaMap(composer.config.schema);
|
|
362
374
|
const versions = ["'latest'"];
|
|
363
375
|
if (composer.publishedVersions) {
|
|
@@ -367,7 +379,7 @@ var generateTypeDeclaration = (prompts, composers = []) => {
|
|
|
367
379
|
} else {
|
|
368
380
|
versions.push(`'${composer.version}'`);
|
|
369
381
|
}
|
|
370
|
-
lines.push(`
|
|
382
|
+
lines.push(` ${composerKey}: {`);
|
|
371
383
|
if (versions.length === 1) {
|
|
372
384
|
if (variables.length === 0) {
|
|
373
385
|
lines.push(` [V in ${versions[0]}]: Record<string, never>;`);
|
|
@@ -400,11 +412,12 @@ var generateTypeDeclaration = (prompts, composers = []) => {
|
|
|
400
412
|
lines.push(" interface ComposerPromptMap {");
|
|
401
413
|
for (const composer of composers) {
|
|
402
414
|
const names = extractComposerPromptNames(composer);
|
|
415
|
+
const composerKey = typePropertyKey(composer.composerId);
|
|
403
416
|
if (names.length === 0) {
|
|
404
|
-
lines.push(`
|
|
417
|
+
lines.push(` ${composerKey}: never;`);
|
|
405
418
|
} else {
|
|
406
419
|
const union = names.map((n) => `'${n}'`).join(" | ");
|
|
407
|
-
lines.push(`
|
|
420
|
+
lines.push(` ${composerKey}: ${union};`);
|
|
408
421
|
}
|
|
409
422
|
}
|
|
410
423
|
lines.push(" }");
|
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,16 @@ var createPromptlyClient = (config) => {
|
|
|
271
286
|
if (segment.type === "static") {
|
|
272
287
|
processedSegments.push({
|
|
273
288
|
type: "static",
|
|
274
|
-
content:
|
|
289
|
+
content: preserveEmptyParagraphs(
|
|
290
|
+
interpolateStaticSegment(segment.content, input)
|
|
291
|
+
)
|
|
292
|
+
});
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (segment.type === "html_block") {
|
|
296
|
+
processedSegments.push({
|
|
297
|
+
type: "static",
|
|
298
|
+
content: interpolateStaticSegment(segment.html, input)
|
|
275
299
|
});
|
|
276
300
|
continue;
|
|
277
301
|
}
|
|
@@ -305,7 +329,7 @@ var createPromptlyClient = (config) => {
|
|
|
305
329
|
if (val === void 0) {
|
|
306
330
|
continue;
|
|
307
331
|
}
|
|
308
|
-
parts.push(
|
|
332
|
+
parts.push(formatComposerInput(val));
|
|
309
333
|
}
|
|
310
334
|
return parts.join("");
|
|
311
335
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PromptlyClientConfig, a as PromptlyClient, E as ErrorCode } from './types-
|
|
2
|
-
export { C as ComposerConfig, b as ComposerFormatFn, c as ComposerGenerateFn, d as
|
|
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-
|
|
2
|
-
export { C as ComposerConfig, b as ComposerFormatFn, c as ComposerGenerateFn, d as
|
|
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,16 @@ var createPromptlyClient = (config) => {
|
|
|
230
245
|
if (segment.type === "static") {
|
|
231
246
|
processedSegments.push({
|
|
232
247
|
type: "static",
|
|
233
|
-
content:
|
|
248
|
+
content: preserveEmptyParagraphs(
|
|
249
|
+
interpolateStaticSegment(segment.content, input)
|
|
250
|
+
)
|
|
251
|
+
});
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (segment.type === "html_block") {
|
|
255
|
+
processedSegments.push({
|
|
256
|
+
type: "static",
|
|
257
|
+
content: interpolateStaticSegment(segment.html, input)
|
|
234
258
|
});
|
|
235
259
|
continue;
|
|
236
260
|
}
|
|
@@ -264,7 +288,7 @@ var createPromptlyClient = (config) => {
|
|
|
264
288
|
if (val === void 0) {
|
|
265
289
|
continue;
|
|
266
290
|
}
|
|
267
|
-
parts.push(
|
|
291
|
+
parts.push(formatComposerInput(val));
|
|
268
292
|
}
|
|
269
293
|
return parts.join("");
|
|
270
294
|
};
|
package/dist/schema.d.cts
CHANGED
package/dist/schema.d.ts
CHANGED
|
@@ -108,7 +108,11 @@ type ComposerPromptSegment = {
|
|
|
108
108
|
userMessage: string | null;
|
|
109
109
|
config: Record<string, unknown>;
|
|
110
110
|
};
|
|
111
|
-
type
|
|
111
|
+
type ComposerHtmlBlockSegment = {
|
|
112
|
+
type: 'html_block';
|
|
113
|
+
html: string;
|
|
114
|
+
};
|
|
115
|
+
type ComposerSegment = ComposerStaticSegment | ComposerPromptSegment | ComposerHtmlBlockSegment;
|
|
112
116
|
type ComposerConfig = {
|
|
113
117
|
schema: SchemaField[];
|
|
114
118
|
inputData: unknown;
|
|
@@ -128,7 +132,8 @@ interface ComposerVariableMap {
|
|
|
128
132
|
}
|
|
129
133
|
interface ComposerPromptMap {
|
|
130
134
|
}
|
|
131
|
-
type
|
|
135
|
+
type KnownComposerId = Extract<keyof ComposerVariableMap, string>;
|
|
136
|
+
type ComposerId = [KnownComposerId] extends [never] ? string : KnownComposerId;
|
|
132
137
|
type ComposerVersion<Id extends string> = Id extends keyof ComposerVariableMap ? Exclude<keyof ComposerVariableMap[Id], 'latest'> : string;
|
|
133
138
|
type ComposerInputFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof ComposerVariableMap ? Ver extends keyof ComposerVariableMap[Id] ? ComposerVariableMap[Id][Ver] : Record<string, unknown> : Record<string, unknown>;
|
|
134
139
|
type ComposerPromptNamesFor<Id extends string> = Id extends keyof ComposerPromptMap ? ComposerPromptMap[Id] : string;
|
|
@@ -142,10 +147,10 @@ type ComposerPrompt = {
|
|
|
142
147
|
};
|
|
143
148
|
type FormatInput = {
|
|
144
149
|
text: string;
|
|
150
|
+
} | {
|
|
151
|
+
html: string;
|
|
145
152
|
} | string;
|
|
146
|
-
type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<
|
|
147
|
-
text: string;
|
|
148
|
-
} | string>;
|
|
153
|
+
type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<FormatInput>;
|
|
149
154
|
type ComposerFormatFn<Names extends string = string> = (results: Record<Names, FormatInput>) => string;
|
|
150
155
|
type ComposerResult<Names extends string = string> = {
|
|
151
156
|
composerId: string;
|
|
@@ -159,12 +164,12 @@ type ComposerResult<Names extends string = string> = {
|
|
|
159
164
|
} & {
|
|
160
165
|
[K in Names]: ComposerPrompt;
|
|
161
166
|
};
|
|
162
|
-
type GetComposerOptions<Id extends string =
|
|
167
|
+
type GetComposerOptions<Id extends string = ComposerId, V extends string = 'latest'> = {
|
|
163
168
|
input?: ComposerInputFor<Id, V>;
|
|
164
169
|
version?: V;
|
|
165
170
|
};
|
|
166
171
|
type ComposerRequest = {
|
|
167
|
-
composerId:
|
|
172
|
+
composerId: ComposerId;
|
|
168
173
|
input?: Record<string, unknown>;
|
|
169
174
|
version?: string;
|
|
170
175
|
};
|
|
@@ -191,8 +196,8 @@ type GetOptions<V extends string = string> = {
|
|
|
191
196
|
type PromptlyClient = {
|
|
192
197
|
getPrompt: <T extends string, V extends PromptVersion<T> | 'latest' = 'latest'>(promptId: T, options?: GetOptions<V>) => Promise<PromptResult<VariablesFor<T, V>>>;
|
|
193
198
|
getPrompts: <const T extends readonly PromptRequest[]>(entries: T) => Promise<GetPromptsResults<T>>;
|
|
194
|
-
getComposer: <T extends
|
|
199
|
+
getComposer: <T extends ComposerId, V extends ComposerVersion<T> | 'latest' = 'latest'>(composerId: T, options?: GetComposerOptions<T, V>) => Promise<ComposerResult<ComposerPromptNamesFor<T>>>;
|
|
195
200
|
getComposers: <const T extends readonly ComposerRequest[]>(entries: T) => Promise<GetComposersResults<T>>;
|
|
196
201
|
};
|
|
197
202
|
|
|
198
|
-
export type {
|
|
203
|
+
export type { PromptVersion as A, PublishedVersion as B, ComposerConfig as C, SchemaFieldParams as D, 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, ComposerHtmlBlockSegment as d, ComposerId as e, ComposerInputFor as f, ComposerPrompt as g, ComposerPromptMap as h, ComposerPromptNamesFor as i, ComposerPromptSegment as j, ComposerRequest as k, ComposerResponse as l, ComposerResult as m, ComposerSegment as n, ComposerStaticSegment as o, ComposerVariableMap as p, ComposerVersion as q, ErrorResponse as r, GetOptions as s, PromptConfig as t, PromptId as u, PromptMessage as v, PromptRequest as w, PromptResponse as x, PromptResult as y, PromptVariableMap as z };
|
|
@@ -108,7 +108,11 @@ type ComposerPromptSegment = {
|
|
|
108
108
|
userMessage: string | null;
|
|
109
109
|
config: Record<string, unknown>;
|
|
110
110
|
};
|
|
111
|
-
type
|
|
111
|
+
type ComposerHtmlBlockSegment = {
|
|
112
|
+
type: 'html_block';
|
|
113
|
+
html: string;
|
|
114
|
+
};
|
|
115
|
+
type ComposerSegment = ComposerStaticSegment | ComposerPromptSegment | ComposerHtmlBlockSegment;
|
|
112
116
|
type ComposerConfig = {
|
|
113
117
|
schema: SchemaField[];
|
|
114
118
|
inputData: unknown;
|
|
@@ -128,7 +132,8 @@ interface ComposerVariableMap {
|
|
|
128
132
|
}
|
|
129
133
|
interface ComposerPromptMap {
|
|
130
134
|
}
|
|
131
|
-
type
|
|
135
|
+
type KnownComposerId = Extract<keyof ComposerVariableMap, string>;
|
|
136
|
+
type ComposerId = [KnownComposerId] extends [never] ? string : KnownComposerId;
|
|
132
137
|
type ComposerVersion<Id extends string> = Id extends keyof ComposerVariableMap ? Exclude<keyof ComposerVariableMap[Id], 'latest'> : string;
|
|
133
138
|
type ComposerInputFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof ComposerVariableMap ? Ver extends keyof ComposerVariableMap[Id] ? ComposerVariableMap[Id][Ver] : Record<string, unknown> : Record<string, unknown>;
|
|
134
139
|
type ComposerPromptNamesFor<Id extends string> = Id extends keyof ComposerPromptMap ? ComposerPromptMap[Id] : string;
|
|
@@ -142,10 +147,10 @@ type ComposerPrompt = {
|
|
|
142
147
|
};
|
|
143
148
|
type FormatInput = {
|
|
144
149
|
text: string;
|
|
150
|
+
} | {
|
|
151
|
+
html: string;
|
|
145
152
|
} | string;
|
|
146
|
-
type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<
|
|
147
|
-
text: string;
|
|
148
|
-
} | string>;
|
|
153
|
+
type ComposerGenerateFn = (prompt: ComposerPrompt) => Promise<FormatInput>;
|
|
149
154
|
type ComposerFormatFn<Names extends string = string> = (results: Record<Names, FormatInput>) => string;
|
|
150
155
|
type ComposerResult<Names extends string = string> = {
|
|
151
156
|
composerId: string;
|
|
@@ -159,12 +164,12 @@ type ComposerResult<Names extends string = string> = {
|
|
|
159
164
|
} & {
|
|
160
165
|
[K in Names]: ComposerPrompt;
|
|
161
166
|
};
|
|
162
|
-
type GetComposerOptions<Id extends string =
|
|
167
|
+
type GetComposerOptions<Id extends string = ComposerId, V extends string = 'latest'> = {
|
|
163
168
|
input?: ComposerInputFor<Id, V>;
|
|
164
169
|
version?: V;
|
|
165
170
|
};
|
|
166
171
|
type ComposerRequest = {
|
|
167
|
-
composerId:
|
|
172
|
+
composerId: ComposerId;
|
|
168
173
|
input?: Record<string, unknown>;
|
|
169
174
|
version?: string;
|
|
170
175
|
};
|
|
@@ -191,8 +196,8 @@ type GetOptions<V extends string = string> = {
|
|
|
191
196
|
type PromptlyClient = {
|
|
192
197
|
getPrompt: <T extends string, V extends PromptVersion<T> | 'latest' = 'latest'>(promptId: T, options?: GetOptions<V>) => Promise<PromptResult<VariablesFor<T, V>>>;
|
|
193
198
|
getPrompts: <const T extends readonly PromptRequest[]>(entries: T) => Promise<GetPromptsResults<T>>;
|
|
194
|
-
getComposer: <T extends
|
|
199
|
+
getComposer: <T extends ComposerId, V extends ComposerVersion<T> | 'latest' = 'latest'>(composerId: T, options?: GetComposerOptions<T, V>) => Promise<ComposerResult<ComposerPromptNamesFor<T>>>;
|
|
195
200
|
getComposers: <const T extends readonly ComposerRequest[]>(entries: T) => Promise<GetComposersResults<T>>;
|
|
196
201
|
};
|
|
197
202
|
|
|
198
|
-
export type {
|
|
203
|
+
export type { PromptVersion as A, PublishedVersion as B, ComposerConfig as C, SchemaFieldParams as D, 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, ComposerHtmlBlockSegment as d, ComposerId as e, ComposerInputFor as f, ComposerPrompt as g, ComposerPromptMap as h, ComposerPromptNamesFor as i, ComposerPromptSegment as j, ComposerRequest as k, ComposerResponse as l, ComposerResult as m, ComposerSegment as n, ComposerStaticSegment as o, ComposerVariableMap as p, ComposerVersion as q, ErrorResponse as r, GetOptions as s, PromptConfig as t, PromptId as u, PromptMessage as v, PromptRequest as w, PromptResponse as x, PromptResult as y, PromptVariableMap as z };
|