- [x] show prompt instead of app in autocomplete - [x] use proper array/list for db (tags) - [x] don't do <dyad-prompt> - replace inline
17 lines
483 B
TypeScript
17 lines
483 B
TypeScript
export function replacePromptReference(
|
|
userPrompt: string,
|
|
promptsById: Record<number | string, string>,
|
|
): string {
|
|
if (typeof userPrompt !== "string" || userPrompt.length === 0)
|
|
return userPrompt;
|
|
|
|
return userPrompt.replace(
|
|
/@prompt:(\d+)/g,
|
|
(_match: string, idStr: string) => {
|
|
const idNum = Number(idStr);
|
|
const replacement = promptsById[idNum] ?? promptsById[idStr];
|
|
return replacement !== undefined ? replacement : _match;
|
|
},
|
|
);
|
|
}
|