@promptlycms/prompts 0.1.2 → 0.2.0-canary.2e499dc
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 +64 -7
- package/dist/cli.js +132 -15
- package/dist/index.cjs +133 -3
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +130 -2
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/types-DyMq5QKO.d.cts +198 -0
- package/dist/types-DyMq5QKO.d.ts +198 -0
- package/package.json +14 -14
- package/dist/types-BbNpKJej.d.cts +0 -118
- package/dist/types-BbNpKJej.d.ts +0 -118
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ var DEFAULT_BASE_URL = "https://api.promptlycms.com";
|
|
|
37
37
|
var MODEL_ID_MAP = {
|
|
38
38
|
// Anthropic: CMS display IDs → API model IDs
|
|
39
39
|
"claude-opus-4.6": "claude-opus-4-6-20250917",
|
|
40
|
+
"claude-sonnet-4.6": "claude-sonnet-4-6",
|
|
40
41
|
"claude-sonnet-4.5": "claude-sonnet-4-5-20250929",
|
|
41
42
|
"claude-haiku-4.5": "claude-haiku-4-5-20251001",
|
|
42
43
|
"claude-opus-4": "claude-opus-4-20250514",
|
|
@@ -140,6 +141,26 @@ var createModelResolver = (config) => {
|
|
|
140
141
|
);
|
|
141
142
|
};
|
|
142
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
|
+
};
|
|
143
164
|
var createPromptlyClient = (config) => {
|
|
144
165
|
const apiKey = config?.apiKey ?? process.env.PROMPTLY_API_KEY;
|
|
145
166
|
if (!apiKey) {
|
|
@@ -184,11 +205,118 @@ var createPromptlyClient = (config) => {
|
|
|
184
205
|
);
|
|
185
206
|
return results;
|
|
186
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
314
|
};
|
|
189
315
|
export {
|
|
190
316
|
PromptlyError,
|
|
191
317
|
createPromptlyClient,
|
|
192
318
|
getSdkModelId,
|
|
193
|
-
interpolate
|
|
319
|
+
interpolate,
|
|
320
|
+
interpolateStaticSegment,
|
|
321
|
+
toCamelCase
|
|
194
322
|
};
|
package/dist/schema.d.cts
CHANGED
package/dist/schema.d.ts
CHANGED
|
@@ -0,0 +1,198 @@
|
|
|
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 };
|
|
@@ -0,0 +1,198 @@
|
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptlycms/prompts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-canary.2e499dc",
|
|
4
4
|
"description": "TypeScript SDK for Promptly CMS — fetch prompts, build Zod schemas, generate typed code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"types": "tsgo --noEmit",
|
|
28
28
|
"lint": "biome check .",
|
|
29
29
|
"lint:fix": "biome check --write .",
|
|
30
|
-
"test": "bun test",
|
|
30
|
+
"test": "bun test src/__tests__/client src/__tests__/codegen src/__tests__/composer src/__tests__/generate src/__tests__/schema",
|
|
31
31
|
"test:smoke": "bun test src/__tests__/smoke.test.ts",
|
|
32
32
|
"test:watch": "bun test --watch",
|
|
33
33
|
"prepublishOnly": "bun run build"
|
|
@@ -36,23 +36,23 @@
|
|
|
36
36
|
"citty": "^0.2.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@ai-sdk/anthropic": "^3.0.
|
|
40
|
-
"@ai-sdk/google": "^3.0.
|
|
41
|
-
"@ai-sdk/mistral": "^3.0.
|
|
42
|
-
"@ai-sdk/openai": "^3.0.
|
|
43
|
-
"@biomejs/biome": "^2.
|
|
44
|
-
"@changesets/changelog-github": "^0.
|
|
45
|
-
"@changesets/cli": "^2.
|
|
46
|
-
"@types/bun": "
|
|
47
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
48
|
-
"ai": "^6.0",
|
|
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",
|
|
49
49
|
"tsup": "^8.5.1",
|
|
50
50
|
"zod": "^4.3.6"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"typescript": "^
|
|
53
|
+
"typescript": "^6.0.2",
|
|
54
54
|
"zod": "^4.0.0",
|
|
55
|
-
"ai": "^
|
|
55
|
+
"ai": "^6.0.137"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@ai-sdk/anthropic": {
|