1export const LICENSE_LABELS = Object.freeze({ 2 personal: "ä» ä¸ªäººä½¿ç¨", 3 commercial: "å 许åä¸ä½¿ç¨", 4 commercial_client: "å 许åä¸ä½¿ç¨å客æ·é¡¹ç®", 5}); 6 7export const CONTENT_TYPE_LABELS = Object.freeze({ 8 image: "å¾å", 9 video: "è§é¢", 10 text_office: "æåä¸åå ¬", 11 programming: "ç¼ç¨", 12}); 13 14export function normalizeVariables(value) { 15 if (!Array.isArray(value)) return []; 16 const names = new Set(); 17 return value 18 .map((item) => ({ 19 name: String(item?.name || "").trim(), 20 defaultValue: String(item?.defaultValue ?? item?.default ?? "").trim(), 21 description: String(item?.description || "").trim(), 22 })) 23 .filter((item) => item.name && !names.has(item.name) && names.add(item.name)); 24} 25 26export function parseKeyValueLines(value) { 27 const result = {}; 28 String(value || "") 29 .split(/\r?\n/) 30 .map((line) => line.trim()) 31 .filter(Boolean) 32 .forEach((line) => { 33 const index = line.search(/[:=ï¼]/); 34 if (index < 1) return; 35 const key = line.slice(0, index).trim(); 36 const itemValue = line.slice(index + 1).trim(); 37 if (key) result[key] = itemValue; 38 }); 39 return result; 40} 41 42export function formatKeyValueLines(value) { 43 if (!value || typeof value !== "object" || Array.isArray(value)) return ""; 44 return Object.entries(value) 45 .map(([key, itemValue]) => `${key}=${itemValue ?? ""}`) 46 .join("\n"); 47} 48 49export function parseTags(value) { 50 return [...new Set( 51 String(value || "") 52 .split(/[,ï¼\n]/) 53 .map((item) => item.trim()) 54 .filter(Boolean), 55 )].slice(0, 20); 56} 57 58export function renderPromptTemplate(template, variables, values = {}) { 59 const normalized = normalizeVariables(variables); 60 const replacements = new Map( 61 normalized.map((item) => [item.name, String(values[item.name] ?? item.defaultValue)]), 62 ); 63 const braceRendered = String(template || "").replace(/\{\{\s*([^{}]+?)\s*\}\}/g, (match, rawName) => { 64 const name = String(rawName).trim(); 65 return replacements.has(name) ? replacements.get(name) : match; 66 }); 67 return [...normalized].sort((a, b) => b.name.length - a.name.length).reduce((result, item) => { 68 const escapedName = item.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); 69 return result.replace(new RegExp(`@${escapedName}`, "g"), replacements.get(item.name)); 70 }, braceRendered); 71} 72 73export function snapshotToViewModel(snapshot = {}) { 74 return { 75 work_id: snapshot.workId || snapshot.work_id || "", 76 version_id: snapshot.versionId || snapshot.version_id || "", 77 version_no: Number(snapshot.versionNo || snapshot.version_no || 0), 78 title: snapshot.title || "", 79 summary: snapshot.summary || "", 80 content_type: snapshot.contentType || snapshot.content_type || "image", 81 prompt_text: snapshot.prompt || snapshot.prompt_text || "", 82 negative_prompt_text: snapshot.negativePrompt || snapshot.negative_prompt_text || "", 83 variables: normalizeVariables(snapshot.variables), 84 model_name: snapshot.model || snapshot.model_name || "", 85 model_version: snapshot.modelVersion || snapshot.model_version || "", 86 parameters: snapshot.parameters || {}, 87 dependencies: Array.isArray(snapshot.dependencies) ? snapshot.dependencies : [], 88 tags: Array.isArray(snapshot.tags) ? snapshot.tags : [], 89 license_code: snapshot.licenseCode || snapshot.license_code || "personal", 90 instructions: snapshot.instructions || "", 91 author_nickname: snapshot.authorNickname || snapshot.author_nickname || "", 92 }; 93}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.