@promptlycms/prompts 0.3.0-canary.2f7697e → 0.3.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,8 +19,7 @@ npm install @promptlycms/prompts
19
19
  Peer dependencies:
20
20
 
21
21
  ```bash
22
- npm install zod ai
23
- npm install --save-dev typescript
22
+ npm install zod ai typescript
24
23
  ```
25
24
 
26
25
  You'll also need at least one AI provider SDK for model resolution:
package/dist/cli.js CHANGED
@@ -216,43 +216,7 @@ var groupAndSortVersions = (prompt) => {
216
216
  });
217
217
  return result;
218
218
  };
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()) => {
219
+ var generateMappedTypeBlock = (group, indent) => {
256
220
  const lines = [];
257
221
  const { versions, variables } = group;
258
222
  if (versions.length === 1) {
@@ -262,9 +226,7 @@ var generateMappedTypeBlock = (group, indent, schemaMap = /* @__PURE__ */ new Ma
262
226
  } else {
263
227
  lines.push(`${indent}[V in ${vKey}]: {`);
264
228
  for (const v of variables) {
265
- lines.push(
266
- `${indent} ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
267
- );
229
+ lines.push(`${indent} ${v}: string;`);
268
230
  }
269
231
  lines.push(`${indent}};`);
270
232
  }
@@ -285,9 +247,7 @@ var generateMappedTypeBlock = (group, indent, schemaMap = /* @__PURE__ */ new Ma
285
247
  }
286
248
  if (variables.length > 0) {
287
249
  for (const v of variables) {
288
- lines.push(
289
- `${indent} ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
290
- );
250
+ lines.push(`${indent} ${v}: string;`);
291
251
  }
292
252
  lines.push(`${indent}};`);
293
253
  }
@@ -304,12 +264,11 @@ var generateTypeDeclaration = (prompts, composers = []) => {
304
264
  ];
305
265
  for (const prompt of prompts) {
306
266
  const groups = groupAndSortVersions(prompt);
307
- const schemaMap = buildSchemaMap(prompt.config.schema);
308
267
  if (groups.length === 1) {
309
268
  const group = groups[0];
310
269
  if (group) {
311
270
  lines.push(` '${prompt.promptId}': {`);
312
- lines.push(...generateMappedTypeBlock(group, " ", schemaMap));
271
+ lines.push(...generateMappedTypeBlock(group, " "));
313
272
  lines.push(" };");
314
273
  }
315
274
  } else {
@@ -323,7 +282,7 @@ var generateTypeDeclaration = (prompts, composers = []) => {
323
282
  } else {
324
283
  lines.push(" } & {");
325
284
  }
326
- lines.push(...generateMappedTypeBlock(group, " ", schemaMap));
285
+ lines.push(...generateMappedTypeBlock(group, " "));
327
286
  }
328
287
  lines.push(" };");
329
288
  }
@@ -333,7 +292,6 @@ var generateTypeDeclaration = (prompts, composers = []) => {
333
292
  lines.push(" interface ComposerVariableMap {");
334
293
  for (const composer of composers) {
335
294
  const variables = extractComposerVariables(composer);
336
- const schemaMap = buildSchemaMap(composer.config.schema);
337
295
  const versions = ["'latest'"];
338
296
  if (composer.publishedVersions) {
339
297
  for (const pv of composer.publishedVersions) {
@@ -349,9 +307,7 @@ var generateTypeDeclaration = (prompts, composers = []) => {
349
307
  } else {
350
308
  lines.push(` [V in ${versions[0]}]: {`);
351
309
  for (const v of variables) {
352
- lines.push(
353
- ` ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
354
- );
310
+ lines.push(` ${v}: string;`);
355
311
  }
356
312
  lines.push(" };");
357
313
  }
@@ -362,9 +318,7 @@ var generateTypeDeclaration = (prompts, composers = []) => {
362
318
  } else {
363
319
  lines.push(` [V in ${versionUnion}]: {`);
364
320
  for (const v of variables) {
365
- lines.push(
366
- ` ${v}: ${schemaFieldToTsType(schemaMap.get(v))};`
367
- );
321
+ lines.push(` ${v}: string;`);
368
322
  }
369
323
  lines.push(" };");
370
324
  }
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}}`, String(value));
150
+ result = result.replaceAll(`\${${key}}`, 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) => fieldPath in input ? String(input[fieldPath]) : ""
193
+ (_, fieldPath) => input[fieldPath] ?? ""
194
194
  );
195
195
  result = result.replace(
196
196
  VARIABLE_REF_ALT_REGEX,
197
- (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
197
+ (_, fieldPath) => input[fieldPath] ?? ""
198
198
  );
199
199
  result = result.replace(
200
200
  MUSTACHE_REGEX,
201
- (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
201
+ (_, fieldPath) => 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-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';
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';
3
3
  import 'ai';
4
4
 
5
5
  declare const getSdkModelId: (modelId: string) => string;
6
- declare const interpolate: (template: string, variables: Record<string, unknown>) => string;
6
+ declare const interpolate: (template: string, variables: Record<string, string>) => string;
7
7
  declare const toCamelCase: (name: string) => string;
8
- declare const interpolateStaticSegment: (content: string, input: Record<string, unknown>) => string;
8
+ declare const interpolateStaticSegment: (content: string, input: Record<string, string>) => 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-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';
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';
3
3
  import 'ai';
4
4
 
5
5
  declare const getSdkModelId: (modelId: string) => string;
6
- declare const interpolate: (template: string, variables: Record<string, unknown>) => string;
6
+ declare const interpolate: (template: string, variables: Record<string, string>) => string;
7
7
  declare const toCamelCase: (name: string) => string;
8
- declare const interpolateStaticSegment: (content: string, input: Record<string, unknown>) => string;
8
+ declare const interpolateStaticSegment: (content: string, input: Record<string, string>) => 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}}`, String(value));
109
+ result = result.replaceAll(`\${${key}}`, 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) => fieldPath in input ? String(input[fieldPath]) : ""
152
+ (_, fieldPath) => input[fieldPath] ?? ""
153
153
  );
154
154
  result = result.replace(
155
155
  VARIABLE_REF_ALT_REGEX,
156
- (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
156
+ (_, fieldPath) => input[fieldPath] ?? ""
157
157
  );
158
158
  result = result.replace(
159
159
  MUSTACHE_REGEX,
160
- (_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
160
+ (_, fieldPath) => 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-DIVyjOlH.cjs';
2
+ import { S as SchemaField } from './types-DyMq5QKO.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-DIVyjOlH.js';
2
+ import { S as SchemaField } from './types-DyMq5QKO.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, unknown> : Record<string, unknown>;
77
- type PromptMessage<V extends Record<string, unknown> = Record<string, unknown>> = {
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
78
  (variables: V): string;
79
79
  toString(): string;
80
80
  };
81
- type PromptResult<V extends Record<string, unknown> = Record<string, unknown>> = Omit<PromptResponse, 'userMessage'> & {
81
+ type PromptResult<V extends Record<string, string> = Record<string, string>> = 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, unknown> : Record<string, unknown>;
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
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, unknown>;
168
+ input?: Record<string, string>;
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, unknown> : Record<string, unknown>;
77
- type PromptMessage<V extends Record<string, unknown> = Record<string, unknown>> = {
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
78
  (variables: V): string;
79
79
  toString(): string;
80
80
  };
81
- type PromptResult<V extends Record<string, unknown> = Record<string, unknown>> = Omit<PromptResponse, 'userMessage'> & {
81
+ type PromptResult<V extends Record<string, string> = Record<string, string>> = 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, unknown> : Record<string, unknown>;
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
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, unknown>;
168
+ input?: Record<string, string>;
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-canary.2f7697e",
3
+ "version": "0.3.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": "^5.0.0 || ^6.0.0",
53
+ "typescript": "^6.0.2",
54
54
  "zod": "^4.0.0",
55
55
  "ai": "^6.0.137"
56
56
  },