Prompt gallery (#957)
- [x] show prompt instead of app in autocomplete - [x] use proper array/list for db (tags) - [x] don't do <dyad-prompt> - replace inline
This commit is contained in:
@@ -61,6 +61,9 @@ import { FileUploadsState } from "../utils/file_uploads_state";
|
||||
import { OpenAIResponsesProviderOptions } from "@ai-sdk/openai";
|
||||
import { extractMentionedAppsCodebases } from "../utils/mention_apps";
|
||||
import { parseAppMentions } from "@/shared/parse_mention_apps";
|
||||
import { prompts as promptsTable } from "../../db/schema";
|
||||
import { inArray } from "drizzle-orm";
|
||||
import { replacePromptReference } from "../utils/replacePromptReference";
|
||||
|
||||
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
||||
|
||||
@@ -274,6 +277,26 @@ export function registerChatStreamHandlers() {
|
||||
|
||||
// Add user message to database with attachment info
|
||||
let userPrompt = req.prompt + (attachmentInfo ? attachmentInfo : "");
|
||||
// Inline referenced prompt contents for mentions like @prompt:<id>
|
||||
try {
|
||||
const matches = Array.from(userPrompt.matchAll(/@prompt:(\d+)/g));
|
||||
if (matches.length > 0) {
|
||||
const ids = Array.from(new Set(matches.map((m) => Number(m[1]))));
|
||||
const referenced = await db
|
||||
.select()
|
||||
.from(promptsTable)
|
||||
.where(inArray(promptsTable.id, ids));
|
||||
if (referenced.length > 0) {
|
||||
const promptsMap: Record<number, string> = {};
|
||||
for (const p of referenced) {
|
||||
promptsMap[p.id] = p.content;
|
||||
}
|
||||
userPrompt = replacePromptReference(userPrompt, promptsMap);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error("Failed to inline referenced prompts:", e);
|
||||
}
|
||||
if (req.selectedComponent) {
|
||||
let componentSnippet = "[component snippet not available]";
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user