작업실: AI 프롬프트로 작품 수정·새 작품 초안(DeepSeek)
This commit is contained in:
1 parent
109bd93bd2
commit
4dff91b483
5 files changed
+593
-21
No files matched your search
+281
-12
@@ -146,6 +146,30 @@
|
||||
button.ghost { background: none; border-color: transparent; color: var(--muted); }
|
||||
button.ghost:hover { color: var(--accent); }
|
||||
|
||||
/* ---------- AI 프롬프트 ---------- */
|
||||
.ai-bar { border-bottom: 1px solid var(--line); padding: 10px 20px 12px; background: #fbf8f2; }
|
||||
.ai-row { display: flex; gap: 8px; align-items: flex-start; }
|
||||
.ai-row select { width: auto; font-size: 12.5px; padding: 7px 8px; }
|
||||
.ai-row textarea { flex: 1; min-height: 46px; font-family: inherit; font-size: 13.5px; line-height: 1.5; }
|
||||
.ai-examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
|
||||
.ai-examples .chip { font-size: 11.5px; }
|
||||
#aiStatus { margin-top: 6px; }
|
||||
.ai-result { margin-top: 10px; border: 1px solid var(--accent); border-radius: 5px; background: #fff; padding: 12px 14px; }
|
||||
.ai-note { font-size: 13px; margin: 0 0 9px; }
|
||||
.ai-note strong { color: var(--accent); }
|
||||
.ai-changes { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-bottom: 10px; }
|
||||
.ai-changes th, .ai-changes td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
|
||||
.ai-changes th { color: var(--muted); font-weight: 500; width: 92px; }
|
||||
.ai-changes .old { color: var(--muted); text-decoration: line-through; }
|
||||
.ai-changes .new { color: var(--ok); }
|
||||
.ai-diff { font-family: ui-monospace, Menlo, monospace; font-size: 12px; line-height: 1.55; background: #fffdf9; border: 1px solid var(--line); border-radius: 4px; padding: 8px; max-height: 220px; overflow: auto; white-space: pre-wrap; }
|
||||
.ai-diff .add { color: var(--ok); background: #edf6f0; }
|
||||
.ai-diff .del { color: var(--warn); background: #fbefe9; text-decoration: line-through; }
|
||||
.ai-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
|
||||
.ai-actions .spacer { flex: 1; }
|
||||
.ai-spin { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; margin-right: 5px; }
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
|
||||
/* ---------- 이력 서랍 ---------- */
|
||||
#drawer {
|
||||
position: fixed; inset: 0; background: rgba(31, 28, 24, .28);
|
||||
@@ -217,6 +241,7 @@
|
||||
<option value="title">이름</option>
|
||||
<option value="price">가격</option>
|
||||
</select>
|
||||
<button id="btnNew" class="ghost" style="font-size:12px;padding:4px 8px;">+ 새 작품</button>
|
||||
<span class="count" id="rowcount"></span>
|
||||
</div>
|
||||
<ul class="rows" id="rows"></ul>
|
||||
@@ -229,6 +254,25 @@
|
||||
<span class="spacer"></span>
|
||||
<span class="hint" id="edModified"></span>
|
||||
</div>
|
||||
|
||||
<div class="ai-bar" id="aiBar">
|
||||
<div class="ai-row">
|
||||
<select id="aiMode">
|
||||
<option value="edit">이 작품 고치기</option>
|
||||
<option value="draft">새 작품 초안</option>
|
||||
</select>
|
||||
<textarea id="aiPrompt" rows="2" placeholder="예) 부제를 더 담백하게. 본문은 3문단으로, 린넨 결을 첫 문장에."></textarea>
|
||||
<button id="aiRun" class="primary">AI 실행</button>
|
||||
</div>
|
||||
<div class="ai-examples" id="aiExamples">
|
||||
<button class="chip" data-p="부제를 더 담백하게, 20자 이내로">부제 간결하게</button>
|
||||
<button class="chip" data-p="본문을 3문단으로 다시 써. 만드는 시간과 재료를 숫자로 넣어">본문 3문단</button>
|
||||
<button class="chip" data-p="40~50대 여성이 읽기 편하게 문장을 짧게 끊어">문장 짧게</button>
|
||||
<button class="chip" data-p="규격과 소재를 첫 문단에 자연스럽게 넣어">재료 강조</button>
|
||||
</div>
|
||||
<div class="hint" id="aiStatus"></div>
|
||||
<div id="aiResult"></div>
|
||||
</div>
|
||||
<div class="editor-body" id="edBody">
|
||||
<p class="empty">왼쪽 목록에서 작품을 고르면 여기서 바로 고칠 수 있습니다.</p>
|
||||
</div>
|
||||
@@ -282,7 +326,7 @@ async function api(path, opts) {
|
||||
function markDirty(dirty) {
|
||||
state.dirty = dirty;
|
||||
$('state').textContent = dirty ? '저장하지 않은 변경' : '변경 없음';
|
||||
$('btnSave').disabled = !state.current || !dirty;
|
||||
$('btnSave').disabled = !($('f_slug') || state.current) || !dirty;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ 목록 */
|
||||
@@ -355,10 +399,17 @@ function fieldHtml(f, value) {
|
||||
}
|
||||
|
||||
function renderEditor(p) {
|
||||
const known = new Set(state.fields.map((f) => f.key));
|
||||
const grid = state.fields.map((f) => fieldHtml(f, p.fields[f.key])).join('');
|
||||
const extra = p.extra_keys.length
|
||||
? '<p class="hint">이 파일에만 있는 키(보존됨): ' + p.extra_keys.map(esc).join(', ') + '</p>'
|
||||
const values = p.fields || {};
|
||||
const isDraft = !!p.draft;
|
||||
if (isDraft) state.current = null;
|
||||
const slugField = isDraft
|
||||
? '<label class="field wide"><span class="lbl">슬러그 (주소·파일명, 영문 소문자·하이픈)</span>' +
|
||||
'<input type="text" id="f_slug" value="' + esc(p.slug || '') + '" placeholder="예: magnolia-tea-mat"></label>'
|
||||
: '';
|
||||
const grid = slugField + state.fields.map((f) => fieldHtml(f, values[f.key])).join('');
|
||||
const extraKeys = p.extra_keys || [];
|
||||
const extra = extraKeys.length
|
||||
? '<p class="hint">이 파일에만 있는 키(보존됨): ' + extraKeys.map(esc).join(', ') + '</p>'
|
||||
: '';
|
||||
$('edBody').innerHTML =
|
||||
'<div class="grid">' + grid + '</div>' +
|
||||
@@ -367,9 +418,9 @@ function renderEditor(p) {
|
||||
'<textarea id="body" rows="14" style="min-height:240px">' + esc(p.body) + '</textarea>' +
|
||||
'<p class="hint" style="margin-top:8px">문단은 빈 줄로 나눕니다. <code>## 제목</code>, <code>- 목록</code>, <code></code> 지원.</p>' +
|
||||
'<div style="margin-top:10px">' + extra + '</div>';
|
||||
$('edTitle').textContent = p.fields.title || p.slug;
|
||||
$('edSlug').textContent = p.slug;
|
||||
$('edModified').textContent = '파일 수정 ' + p.modified;
|
||||
$('edTitle').textContent = isDraft ? '새 작품 (저장 전)' : (values.title || p.slug);
|
||||
$('edSlug').textContent = isDraft ? '' : p.slug;
|
||||
$('edModified').textContent = isDraft ? 'AI 초안' : '파일 수정 ' + p.modified;
|
||||
$('btnReload').disabled = false;
|
||||
wireEditor();
|
||||
markDirty(false);
|
||||
@@ -432,12 +483,18 @@ function collect() {
|
||||
document.querySelectorAll('[data-key]').forEach((el) => {
|
||||
fields[el.dataset.key] = el.type === 'checkbox' ? el.checked : el.value;
|
||||
});
|
||||
return { slug: state.current, fields, body: $('body').value, deploy: $('deployToo').checked };
|
||||
const slugEl = $('f_slug');
|
||||
return {
|
||||
slug: slugEl ? slugEl.value.trim() : state.current,
|
||||
fields, body: $('body').value,
|
||||
deploy: $('deployToo').checked,
|
||||
create: !!slugEl,
|
||||
};
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!state.current) return;
|
||||
const payload = collect();
|
||||
if (!payload.slug) { toast('슬러그를 입력해 주세요', 'err'); return; }
|
||||
$('btnSave').disabled = true;
|
||||
$('state').textContent = '저장 중… (빌드 → 커밋)';
|
||||
const data = await api('/api/product', {
|
||||
@@ -452,7 +509,13 @@ async function save() {
|
||||
markDirty(false);
|
||||
const deployNote = data.deploy ? (data.deploy.ok ? ' / 배포 OK' : ' / 배포 실패') : '';
|
||||
toast(data.message + (data.commit ? ' · ' + data.commit : '') + deployNote + (data.log ? '\n' + data.log : ''), data.deploy && !data.deploy.ok ? 'err' : 'ok');
|
||||
await refresh({ keep: true });
|
||||
if (payload.create) {
|
||||
state.current = null;
|
||||
await refresh({ keep: true });
|
||||
await openProduct(payload.slug);
|
||||
} else {
|
||||
await refresh({ keep: true });
|
||||
}
|
||||
}
|
||||
|
||||
async function refresh(opts = {}) {
|
||||
@@ -468,6 +531,175 @@ async function refresh(opts = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ AI */
|
||||
let aiLast = null;
|
||||
let aiModelLabel = '';
|
||||
|
||||
function labels() {
|
||||
const map = {};
|
||||
state.fields.forEach((f) => { map[f.key] = f.label; });
|
||||
return map;
|
||||
}
|
||||
|
||||
function diffLines(before, after) {
|
||||
const a = String(before || '').split('\n');
|
||||
const b = String(after || '').split('\n');
|
||||
const m = a.length, n = b.length;
|
||||
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
||||
for (let i = m - 1; i >= 0; i--) {
|
||||
for (let j = n - 1; j >= 0; j--) {
|
||||
dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
|
||||
}
|
||||
}
|
||||
const out = [];
|
||||
let i = 0, j = 0;
|
||||
while (i < m && j < n) {
|
||||
if (a[i] === b[j]) { out.push({ t: 'same', s: a[i] }); i++; j++; }
|
||||
else if (dp[i + 1][j] >= dp[i][j + 1]) { out.push({ t: 'del', s: a[i] }); i++; }
|
||||
else { out.push({ t: 'add', s: b[j] }); j++; }
|
||||
}
|
||||
while (i < m) out.push({ t: 'del', s: a[i++] });
|
||||
while (j < n) out.push({ t: 'add', s: b[j++] });
|
||||
return out;
|
||||
}
|
||||
|
||||
function diffHtml(before, after) {
|
||||
const rows = diffLines(before, after);
|
||||
const shown = rows.slice(0, 160).map((r) => {
|
||||
if (r.t === 'same') return esc(r.s);
|
||||
return '<span class="' + (r.t === 'add' ? 'add' : 'del') + '">' + (r.t === 'add' ? '+ ' : '- ') + esc(r.s) + '</span>';
|
||||
});
|
||||
if (rows.length > 160) shown.push('…');
|
||||
return shown.join('\n');
|
||||
}
|
||||
|
||||
async function loadAiStatus() {
|
||||
const data = await api('/api/ai-status');
|
||||
const el = $('aiStatus');
|
||||
if (!data.ok || !data.configured) {
|
||||
aiModelLabel = '';
|
||||
el.innerHTML = 'AI 연결 안 됨: ' + esc(data.error || '키를 확인하세요');
|
||||
el.style.color = 'var(--warn)';
|
||||
return;
|
||||
}
|
||||
aiModelLabel = data.model || '';
|
||||
el.textContent = 'AI: ' + data.model + ' · 키 출처 ' + data.source;
|
||||
el.style.color = '';
|
||||
}
|
||||
|
||||
async function runAi() {
|
||||
const mode = $('aiMode').value;
|
||||
const prompt = $('aiPrompt').value.trim();
|
||||
if (prompt.length < 2) { toast('요청 내용을 입력해 주세요', 'err'); $('aiPrompt').focus(); return; }
|
||||
if (mode === 'edit' && !state.current) { toast('먼저 왼쪽에서 작품을 고르세요', 'err'); return; }
|
||||
|
||||
$('aiRun').disabled = true;
|
||||
$('aiResult').innerHTML = '';
|
||||
$('aiStatus').innerHTML = '<span class="ai-spin"></span>' + (mode === 'draft' ? 'AI가 초안을 쓰는 중…' : 'AI가 고치는 중…');
|
||||
const data = await api('/api/ai', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ mode, slug: state.current, prompt }),
|
||||
});
|
||||
$('aiRun').disabled = false;
|
||||
loadAiStatus();
|
||||
if (!data.ok) { toast(data.error || 'AI 호출 실패', 'err'); return; }
|
||||
if (mode === 'draft') { renderDraftResult(data); return; }
|
||||
if (data.empty) {
|
||||
aiLast = null;
|
||||
$('aiResult').innerHTML = '<div class="ai-result"><p class="ai-note">' + esc(data.note || '바꿀 내용이 없습니다') + '</p><div class="ai-actions"><span class="spacer"></span><button class="ghost" onclick="document.getElementById(\'aiResult\').innerHTML=\'\'">닫기</button></div></div>';
|
||||
return;
|
||||
}
|
||||
aiLast = data;
|
||||
renderAiResult(data);
|
||||
}
|
||||
|
||||
function renderAiResult(data) {
|
||||
const map = labels();
|
||||
const keys = Object.keys(data.changes).filter((k) => k !== 'body');
|
||||
const rows = keys.map((key) => {
|
||||
const before = data.current.fields[key] ?? '';
|
||||
const after = data.changes[key] ?? '';
|
||||
return '<tr><th>' + esc(map[key] || key) + '</th><td><span class="old">' + esc(String(before) || '(빈 값)') +
|
||||
'</span><br><span class="new">' + esc(String(after) || '(비움)') + '</span></td></tr>';
|
||||
}).join('');
|
||||
const bodyChanged = Object.prototype.hasOwnProperty.call(data.changes, 'body');
|
||||
const bodyBlock = bodyChanged
|
||||
? '<div class="section-label">본문 변경</div><div class="ai-diff">' + diffHtml(data.current.body, data.changes.body) + '</div>'
|
||||
: '';
|
||||
const meta = [data.model || aiModelLabel, data.tokens ? data.tokens + ' 토큰' : ''].filter(Boolean).join(' · ');
|
||||
$('aiResult').innerHTML =
|
||||
'<div class="ai-result">' +
|
||||
'<p class="ai-note"><strong>' + esc(data.note || 'AI 제안') + '</strong> <span class="hint">' + esc(meta) + '</span></p>' +
|
||||
(rows ? '<table class="ai-changes"><tbody>' + rows + '</tbody></table>' : '') +
|
||||
bodyBlock +
|
||||
'<div class="ai-actions">' +
|
||||
'<button class="primary" id="aiApply">폼에 적용</button>' +
|
||||
'<button id="aiApplySave">적용하고 저장</button>' +
|
||||
'<span class="spacer"></span>' +
|
||||
'<button class="ghost" id="aiDiscard">버리기</button>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
$('aiApply').addEventListener('click', () => applyAi(false));
|
||||
$('aiApplySave').addEventListener('click', () => applyAi(true));
|
||||
$('aiDiscard').addEventListener('click', discardAi);
|
||||
}
|
||||
|
||||
function renderDraftResult(data) {
|
||||
const f = data.fields || {};
|
||||
$('aiResult').innerHTML =
|
||||
'<div class="ai-result">' +
|
||||
'<p class="ai-note"><strong>' + esc(f.title || '제목 없음') + '</strong> ' +
|
||||
'<span class="hint">slug ' + esc(f.slug || '') + (f.price ? ' · ' + Number(f.price).toLocaleString('ko-KR') + '원' : '') + '</span></p>' +
|
||||
(f.subtitle ? '<p class="hint" style="margin:0 0 8px">' + esc(f.subtitle) + '</p>' : '') +
|
||||
'<div class="ai-diff">' + esc(data.body || '') + '</div>' +
|
||||
'<div class="ai-actions">' +
|
||||
'<button class="primary" id="aiDraftOpen">초안 열기 (편집)</button>' +
|
||||
'<span class="spacer"></span>' +
|
||||
'<button class="ghost" id="aiDiscardDraft">버리기</button>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
$('aiDraftOpen').addEventListener('click', () => applyDraft(data));
|
||||
$('aiDiscardDraft').addEventListener('click', discardAi);
|
||||
}
|
||||
|
||||
function applyAi(saveNow) {
|
||||
if (!aiLast) return;
|
||||
let touched = false;
|
||||
Object.keys(aiLast.changes).forEach((key) => {
|
||||
if (key === 'body') {
|
||||
$('body').value = aiLast.changes.body;
|
||||
touched = true;
|
||||
return;
|
||||
}
|
||||
const el = document.querySelector('[data-key="' + key + '"]');
|
||||
if (!el) return;
|
||||
if (el.type === 'checkbox') el.checked = !!aiLast.changes[key];
|
||||
else el.value = aiLast.changes[key];
|
||||
el.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
touched = true;
|
||||
});
|
||||
if (!touched) return;
|
||||
markDirty(true);
|
||||
if (saveNow) save();
|
||||
else toast('폼에 적용했습니다. 확인 후 저장하세요.', 'ok');
|
||||
}
|
||||
|
||||
function applyDraft(data) {
|
||||
const fields = {};
|
||||
state.fields.forEach((f) => { fields[f.key] = ''; });
|
||||
Object.keys(data.fields || {}).forEach((key) => { fields[key] = data.fields[key] == null ? '' : String(data.fields[key]); });
|
||||
state.current = null;
|
||||
renderList();
|
||||
renderEditor({ slug: data.fields.slug || '', fields, body: data.body || '', draft: true, extra_keys: [], modified: '' });
|
||||
$('aiResult').innerHTML = '<p class="hint">초안을 폼에 열었습니다. 대표 이미지를 올리고 슬러그를 확인한 뒤 [저장(커밋)]을 누르세요.</p>';
|
||||
if (!fields.image) { const pick = $('f_image'); if (pick) pick.focus(); }
|
||||
}
|
||||
|
||||
function discardAi() {
|
||||
aiLast = null;
|
||||
$('aiResult').innerHTML = '';
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ 이력 */
|
||||
async function openHistory() {
|
||||
const data = await api('/api/history');
|
||||
@@ -511,6 +743,31 @@ $('rows').addEventListener('click', (e) => {
|
||||
if (btn) openProduct(btn.dataset.slug);
|
||||
});
|
||||
$('btnSave').addEventListener('click', save);
|
||||
$('aiRun').addEventListener('click', runAi);
|
||||
$('aiPrompt').addEventListener('keydown', (e) => {
|
||||
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { e.preventDefault(); runAi(); }
|
||||
});
|
||||
$('aiExamples').addEventListener('click', (e) => {
|
||||
const chip = e.target.closest('.chip');
|
||||
if (!chip) return;
|
||||
$('aiPrompt').value = chip.dataset.p;
|
||||
$('aiPrompt').focus();
|
||||
});
|
||||
$('aiMode').addEventListener('change', (e) => {
|
||||
discardAi();
|
||||
$('aiPrompt').placeholder = e.target.value === 'draft'
|
||||
? '예) 겨울 매화 티매트, 32×48cm, 6만원. 매화를 놓은 과정을 담백하게.'
|
||||
: '예) 부제를 더 담백하게. 본문은 3문단으로, 린넨 결을 첫 문장에.';
|
||||
});
|
||||
$('btnNew').addEventListener('click', () => {
|
||||
if (state.dirty && !confirm('저장하지 않은 변경이 있습니다. 버리고 새 작품을 쓸까요?')) return;
|
||||
$('aiMode').value = 'draft';
|
||||
state.q = ''; $('q').value = '';
|
||||
discardAi();
|
||||
$('aiPrompt').placeholder = '예) 겨울 매화 티매트, 32×48cm, 6만원. 매화를 놓은 과정을 담백하게.';
|
||||
$('aiPrompt').focus();
|
||||
toast('새 작품: 만들 내용을 적고 AI 실행을 누르세요');
|
||||
});
|
||||
$('btnReload').addEventListener('click', () => { if (state.current) openProduct(state.current); });
|
||||
$('btnHistory').addEventListener('click', openHistory);
|
||||
$('btnCloseDrawer').addEventListener('click', () => $('drawer').classList.remove('open'));
|
||||
@@ -539,7 +796,19 @@ document.addEventListener('keydown', (e) => {
|
||||
|
||||
window.addEventListener('beforeunload', (e) => { if (state.dirty) { e.preventDefault(); e.returnValue = ''; } });
|
||||
|
||||
refresh();
|
||||
async function boot() {
|
||||
await refresh();
|
||||
const params = new URLSearchParams(location.search);
|
||||
const preset = params.get('prompt');
|
||||
if (preset) {
|
||||
$('aiPrompt').value = preset;
|
||||
if (params.get('run') === '1') setTimeout(runAi, 600);
|
||||
}
|
||||
if (params.get('mode') === 'draft') $('aiMode').value = 'draft';
|
||||
loadAiStatus();
|
||||
}
|
||||
|
||||
boot();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user