@promptlycms/prompts 0.2.0 → 0.3.0-canary.2f7697e
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 -6
- package/dist/cli.js +183 -20
- package/dist/index.cjs +133 -4
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +130 -3
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/types-DIVyjOlH.d.cts +198 -0
- package/dist/types-DIVyjOlH.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
|
@@ -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
|
};
|
|
@@ -141,6 +141,26 @@ var createModelResolver = (config) => {
|
|
|
141
141
|
);
|
|
142
142
|
};
|
|
143
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) => fieldPath in input ? String(input[fieldPath]) : ""
|
|
153
|
+
);
|
|
154
|
+
result = result.replace(
|
|
155
|
+
VARIABLE_REF_ALT_REGEX,
|
|
156
|
+
(_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
|
|
157
|
+
);
|
|
158
|
+
result = result.replace(
|
|
159
|
+
MUSTACHE_REGEX,
|
|
160
|
+
(_, fieldPath) => fieldPath in input ? String(input[fieldPath]) : ""
|
|
161
|
+
);
|
|
162
|
+
return result;
|
|
163
|
+
};
|
|
144
164
|
var createPromptlyClient = (config) => {
|
|
145
165
|
const apiKey = config?.apiKey ?? process.env.PROMPTLY_API_KEY;
|
|
146
166
|
if (!apiKey) {
|
|
@@ -185,11 +205,118 @@ var createPromptlyClient = (config) => {
|
|
|
185
205
|
);
|
|
186
206
|
return results;
|
|
187
207
|
};
|
|
188
|
-
|
|
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
|
+
};
|
|
189
314
|
};
|
|
190
315
|
export {
|
|
191
316
|
PromptlyError,
|
|
192
317
|
createPromptlyClient,
|
|
193
318
|
getSdkModelId,
|
|
194
|
-
interpolate
|
|
319
|
+
interpolate,
|
|
320
|
+
interpolateStaticSegment,
|
|
321
|
+
toCamelCase
|
|
195
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, unknown> : Record<string, unknown>;
|
|
77
|
+
type PromptMessage<V extends Record<string, unknown> = Record<string, unknown>> = {
|
|
78
|
+
(variables: V): string;
|
|
79
|
+
toString(): string;
|
|
80
|
+
};
|
|
81
|
+
type PromptResult<V extends Record<string, unknown> = Record<string, unknown>> = 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, unknown> : Record<string, unknown>;
|
|
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, unknown>;
|
|
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, unknown> : Record<string, unknown>;
|
|
77
|
+
type PromptMessage<V extends Record<string, unknown> = Record<string, unknown>> = {
|
|
78
|
+
(variables: V): string;
|
|
79
|
+
toString(): string;
|
|
80
|
+
};
|
|
81
|
+
type PromptResult<V extends Record<string, unknown> = Record<string, unknown>> = 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, unknown> : Record<string, unknown>;
|
|
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, unknown>;
|
|
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.3.0-canary.2f7697e",
|
|
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.4.
|
|
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": "^5",
|
|
53
|
+
"typescript": "^5.0.0 || ^6.0.0",
|
|
54
54
|
"zod": "^4.0.0",
|
|
55
|
-
"ai": "^6.0.
|
|
55
|
+
"ai": "^6.0.137"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@ai-sdk/anthropic": {
|