@promptlycms/prompts 0.3.0 → 0.4.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
@@ -19,7 +19,8 @@ npm install @promptlycms/prompts
19
19
  Peer dependencies:
20
20
 
21
21
  ```bash
22
- npm install zod ai typescript
22
+ npm install zod ai
23
+ npm install --save-dev typescript
23
24
  ```
24
25
 
25
26
  You'll also need at least one AI provider SDK for model resolution:
package/dist/cli.js CHANGED
@@ -216,7 +216,43 @@ var groupAndSortVersions = (prompt) => {
216
216
  });
217
217
  return result;
218
218
  };
219
- var generateMappedTypeBlock = (group, indent) => {
219
+ var ELEMENT_TYPE_MAP = {
220
+ string: "string",
221
+ number: "number",
222
+ boolean: "boolean"
223
+ };
224
+ var schemaFieldToTsType = (field) => {
225
+ if (!field) {
226
+ return "string";
227
+ }
228
+ switch (field.type) {
229
+ case "number":
230
+ case "boolean":
231
+ return field.type;
232
+ case "array": {
233
+ const elementTs = ELEMENT_TYPE_MAP[field.params.elementType ?? ""] ?? "string";
234
+ return `${elementTs}[]`;
235
+ }
236
+ case "enum": {
237
+ if (field.params.enumValues && field.params.enumValues.length > 0) {
238
+ return field.params.enumValues.map((v) => `'${v}'`).join(" | ");
239
+ }
240
+ return "string";
241
+ }
242
+ case "object":
243
+ return "Record<string, unknown>";
244
+ default:
245
+ return "string";
246
+ }
247
+ };
248
+ var buildSchemaMap = (schema) => {
249
+ const map = /* @__PURE__ */ new Map();
250
+ for (const field of schema) {
251
+ map.set(field.name, field);
252
+ }
253
+ return map;
254
+ };
255
+ var generateMappedTypeBlock = (group, indent, schemaMap = /* @__PURE__ */ new Map()) => {
220
256
  const lines = [];
221
257
  const { versions, variables } = group;
222
258
  if (versions.length === 1) {
@@ -226,7 +262,9 @@ var generateMappedTypeBlock = (group, indent) => {
226
262
  } else {
227
263
  lines.push(`${indent}[V in ${vKey}]: {`);
228
264
  for (const v of variables) {
229
- lines.push(`${indent} ${v}: string;`);
265
+ lines.push(
266
+ `${indent} ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
267
+ );
230
268
  }
231
269
  lines.push(`${indent}};`);
232
270
  }
@@ -247,7 +285,9 @@ var generateMappedTypeBlock = (group, indent) => {
247
285
  }
248
286
  if (variables.length > 0) {
249
287
  for (const v of variables) {
250
- lines.push(`${indent} ${v}: string;`);
288
+ lines.push(
289
+ `${indent} ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
290
+ );
251
291
  }
252
292
  lines.push(`${indent}};`);
253
293
  }
@@ -264,11 +304,12 @@ var generateTypeDeclaration = (prompts, composers = []) => {
264
304
  ];
265
305
  for (const prompt of prompts) {
266
306
  const groups = groupAndSortVersions(prompt);
307
+ const schemaMap = buildSchemaMap(prompt.config.schema);
267
308
  if (groups.length === 1) {
268
309
  const group = groups[0];
269
310
  if (group) {
270
311
  lines.push(` '${prompt.promptId}': {`);
271
- lines.push(...generateMappedTypeBlock(group, " "));
312
+ lines.push(...generateMappedTypeBlock(group, " ", schemaMap));
272
313
  lines.push(" };");
273
314
  }
274
315
  } else {
@@ -282,7 +323,7 @@ var generateTypeDeclaration = (prompts, composers = []) => {
282
323
  } else {
283
324
  lines.push(" } & {");
284
325
  }
285
- lines.push(...generateMappedTypeBlock(group, " "));
326
+ lines.push(...generateMappedTypeBlock(group, " ", schemaMap));
286
327
  }
287
328
  lines.push(" };");
288
329
  }
@@ -292,6 +333,7 @@ var generateTypeDeclaration = (prompts, composers = []) => {
292
333
  lines.push(" interface ComposerVariableMap {");
293
334
  for (const composer of composers) {
294
335
  const variables = extractComposerVariables(composer);
336
+ const schemaMap = buildSchemaMap(composer.config.schema);
295
337
  const versions = ["'latest'"];
296
338
  if (composer.publishedVersions) {
297
339
  for (const pv of composer.publishedVersions) {
@@ -307,7 +349,9 @@ var generateTypeDeclaration = (prompts, composers = []) => {
307
349
  } else {
308
350
  lines.push(` [V in ${versions[0]}]: {`);
309
351
  for (const v of variables) {
310
- lines.push(` ${v}: string;`);
352
+ lines.push(
353
+ ` ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
354
+ );
311
355
  }
312
356
  lines.push(" };");
313
357
  }
@@ -318,7 +362,9 @@ var generateTypeDeclaration = (prompts, composers = []) => {
318
362
  } else {
319
363
  lines.push(` [V in ${versionUnion}]: {`);
320
364
  for (const v of variables) {
321
- lines.push(` ${v}: string;`);
365
+ lines.push(
366
+ ` ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
367
+ );
322
368
  }
323
369
  lines.push(" };");
324
370
  }
package/dist/index.cjs CHANGED
@@ -147,7 +147,7 @@ var resolveModel = async (modelId) => {
147
147
  var interpolate = (template, variables) => {
148
148
  let result = template;
149
149
  for (const [key, value] of Object.entries(variables)) {
150
- result = result.replaceAll(`\${${key}}`, value);
150
+ result = result.replaceAll(`\${${key}}`, String(value));
151
151
  }
152
152
  return result;
153
153
  };
@@ -190,15 +190,15 @@ var interpolateStaticSegment = (content, input) => {
190
190
  let result = content;
191
191
  result = result.replace(
192
192
  VARIABLE_REF_REGEX,
193
- (_, fieldPath) => input[fieldPath] ?? ""
193
+ (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
194
194
  );
195
195
  result = result.replace(
196
196
  VARIABLE_REF_ALT_REGEX,
197
- (_, fieldPath) => input[fieldPath] ?? ""
197
+ (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
198
198
  );
199
199
  result = result.replace(
200
200
  MUSTACHE_REGEX,
201
- (_, fieldPath) => input[fieldPath] ?? ""
201
+ (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
202
202
  );
203
203
  return result;
204
204
  };
package/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
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-DIVyjOlH.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-DIVyjOlH.cjs';
3
3
  import 'ai';
4
4
 
5
5
  declare const getSdkModelId: (modelId: string) => string;
6
- declare const interpolate: (template: string, variables: Record<string, string>) => string;
6
+ declare const interpolate: (template: string, variables: Record<string, unknown>) => string;
7
7
  declare const toCamelCase: (name: string) => string;
8
- declare const interpolateStaticSegment: (content: string, input: Record<string, string>) => string;
8
+ declare const interpolateStaticSegment: (content: string, input: Record<string, unknown>) => string;
9
9
  declare const createPromptlyClient: (config?: PromptlyClientConfig) => PromptlyClient;
10
10
 
11
11
  declare class PromptlyError extends Error {
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
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-DIVyjOlH.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-DIVyjOlH.js';
3
3
  import 'ai';
4
4
 
5
5
  declare const getSdkModelId: (modelId: string) => string;
6
- declare const interpolate: (template: string, variables: Record<string, string>) => string;
6
+ declare const interpolate: (template: string, variables: Record<string, unknown>) => string;
7
7
  declare const toCamelCase: (name: string) => string;
8
- declare const interpolateStaticSegment: (content: string, input: Record<string, string>) => string;
8
+ declare const interpolateStaticSegment: (content: string, input: Record<string, unknown>) => string;
9
9
  declare const createPromptlyClient: (config?: PromptlyClientConfig) => PromptlyClient;
10
10
 
11
11
  declare class PromptlyError extends Error {
package/dist/index.js CHANGED
@@ -106,7 +106,7 @@ var resolveModel = async (modelId) => {
106
106
  var interpolate = (template, variables) => {
107
107
  let result = template;
108
108
  for (const [key, value] of Object.entries(variables)) {
109
- result = result.replaceAll(`\${${key}}`, value);
109
+ result = result.replaceAll(`\${${key}}`, String(value));
110
110
  }
111
111
  return result;
112
112
  };
@@ -149,15 +149,15 @@ var interpolateStaticSegment = (content, input) => {
149
149
  let result = content;
150
150
  result = result.replace(
151
151
  VARIABLE_REF_REGEX,
152
- (_, fieldPath) => input[fieldPath] ?? ""
152
+ (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
153
153
  );
154
154
  result = result.replace(
155
155
  VARIABLE_REF_ALT_REGEX,
156
- (_, fieldPath) => input[fieldPath] ?? ""
156
+ (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
157
157
  );
158
158
  result = result.replace(
159
159
  MUSTACHE_REGEX,
160
- (_, fieldPath) => input[fieldPath] ?? ""
160
+ (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
161
161
  );
162
162
  return result;
163
163
  };
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-DIVyjOlH.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-DIVyjOlH.js';
3
3
  import 'ai';
4
4
 
5
5
  declare const buildFieldSchema: (field: SchemaField) => z.ZodTypeAny;
@@ -73,12 +73,12 @@ interface PromptVariableMap {
73
73
  }
74
74
  type PromptId = keyof PromptVariableMap | (string & {});
75
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>> = {
76
+ type VariablesFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof PromptVariableMap ? Ver extends keyof PromptVariableMap[Id] ? PromptVariableMap[Id][Ver] : Record<string, unknown> : Record<string, unknown>;
77
+ type PromptMessage<V extends Record<string, unknown> = Record<string, unknown>> = {
78
78
  (variables: V): string;
79
79
  toString(): string;
80
80
  };
81
- type PromptResult<V extends Record<string, string> = Record<string, string>> = Omit<PromptResponse, 'userMessage'> & {
81
+ type PromptResult<V extends Record<string, unknown> = Record<string, unknown>> = Omit<PromptResponse, 'userMessage'> & {
82
82
  userMessage: PromptMessage<V>;
83
83
  temperature: number;
84
84
  model: ai.LanguageModel;
@@ -130,7 +130,7 @@ interface ComposerPromptMap {
130
130
  }
131
131
  type ComposerId = keyof ComposerVariableMap | (string & {});
132
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>;
133
+ 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
134
  type ComposerPromptNamesFor<Id extends string> = Id extends keyof ComposerPromptMap ? ComposerPromptMap[Id] : string;
135
135
  type ComposerPrompt = {
136
136
  model: ai.LanguageModel;
@@ -165,7 +165,7 @@ type GetComposerOptions<Id extends string = string, V extends string = 'latest'>
165
165
  };
166
166
  type ComposerRequest = {
167
167
  composerId: string;
168
- input?: Record<string, string>;
168
+ input?: Record<string, unknown>;
169
169
  version?: string;
170
170
  };
171
171
  type GetComposersResults<T extends readonly ComposerRequest[]> = {
@@ -73,12 +73,12 @@ interface PromptVariableMap {
73
73
  }
74
74
  type PromptId = keyof PromptVariableMap | (string & {});
75
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>> = {
76
+ type VariablesFor<Id extends string, Ver extends string = 'latest'> = Id extends keyof PromptVariableMap ? Ver extends keyof PromptVariableMap[Id] ? PromptVariableMap[Id][Ver] : Record<string, unknown> : Record<string, unknown>;
77
+ type PromptMessage<V extends Record<string, unknown> = Record<string, unknown>> = {
78
78
  (variables: V): string;
79
79
  toString(): string;
80
80
  };
81
- type PromptResult<V extends Record<string, string> = Record<string, string>> = Omit<PromptResponse, 'userMessage'> & {
81
+ type PromptResult<V extends Record<string, unknown> = Record<string, unknown>> = Omit<PromptResponse, 'userMessage'> & {
82
82
  userMessage: PromptMessage<V>;
83
83
  temperature: number;
84
84
  model: ai.LanguageModel;
@@ -130,7 +130,7 @@ interface ComposerPromptMap {
130
130
  }
131
131
  type ComposerId = keyof ComposerVariableMap | (string & {});
132
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>;
133
+ 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
134
  type ComposerPromptNamesFor<Id extends string> = Id extends keyof ComposerPromptMap ? ComposerPromptMap[Id] : string;
135
135
  type ComposerPrompt = {
136
136
  model: ai.LanguageModel;
@@ -165,7 +165,7 @@ type GetComposerOptions<Id extends string = string, V extends string = 'latest'>
165
165
  };
166
166
  type ComposerRequest = {
167
167
  composerId: string;
168
- input?: Record<string, string>;
168
+ input?: Record<string, unknown>;
169
169
  version?: string;
170
170
  };
171
171
  type GetComposersResults<T extends readonly ComposerRequest[]> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptlycms/prompts",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "TypeScript SDK for Promptly CMS — fetch prompts, build Zod schemas, generate typed code",
5
5
  "type": "module",
6
6
  "exports": {
@@ -50,7 +50,7 @@
50
50
  "zod": "^4.3.6"
51
51
  },
52
52
  "peerDependencies": {
53
- "typescript": "^6.0.2",
53
+ "typescript": "^5.0.0 || ^6.0.0",
54
54
  "zod": "^4.0.0",
55
55
  "ai": "^6.0.137"
56
56
  },