Spaces:
Paused
Paused
Big Brain Ape commited on
Commit ·
b484b4d
0
Parent(s):
Deploy Launch Desk to HuggingFace Spaces
Browse files- Dockerfile +14 -0
- README.md +15 -0
- frontend/index.html +552 -0
- requirements.txt +5 -0
- server/__init__.py +1 -0
- server/__pycache__/__init__.cpython-311.pyc +0 -0
- server/__pycache__/agent.cpython-311.pyc +0 -0
- server/__pycache__/main.cpython-311.pyc +0 -0
- server/__pycache__/tools.cpython-311.pyc +0 -0
- server/agent.py +39 -0
- server/main.py +226 -0
- server/tools.py +332 -0
- tests/__init__.py +1 -0
- tests/__pycache__/__init__.cpython-311.pyc +0 -0
- tests/__pycache__/test_agent.cpython-311-pytest-9.1.1.pyc +0 -0
- tests/test_agent.py +217 -0
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY server/ ./server/
|
| 9 |
+
COPY frontend/ ./frontend/
|
| 10 |
+
COPY tests/ ./tests/
|
| 11 |
+
|
| 12 |
+
EXPOSE 8001
|
| 13 |
+
|
| 14 |
+
CMD ["uvicorn", "server.main:app", "--host", "0.0.0.0", "--port", "8001"]
|
README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
title: Launch Desk
|
| 2 |
+
emoji: 🚀
|
| 3 |
+
colorFrom: blue
|
| 4 |
+
colorTo: indigo
|
| 5 |
+
sdk: docker
|
| 6 |
+
app_port: 8001
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
short_description: AI launch planning agent with streaming via OpenAI Agents SDK
|
| 10 |
+
tags:
|
| 11 |
+
- ai
|
| 12 |
+
- openai
|
| 13 |
+
- agents
|
| 14 |
+
- planning
|
| 15 |
+
- streaming
|
frontend/index.html
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Launch Desk — AI Launch Planning</title>
|
| 7 |
+
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--bg: #0d1117;
|
| 10 |
+
--card: #161b22;
|
| 11 |
+
--border: #30363d;
|
| 12 |
+
--accent: #58a6ff;
|
| 13 |
+
--accent-dim: #388bfd1a;
|
| 14 |
+
--text: #c9d1d9;
|
| 15 |
+
--text-dim: #8b949e;
|
| 16 |
+
--green: #3fb950;
|
| 17 |
+
--yellow: #d29922;
|
| 18 |
+
--red: #f85149;
|
| 19 |
+
--radius: 8px;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 23 |
+
|
| 24 |
+
body {
|
| 25 |
+
background: var(--bg);
|
| 26 |
+
color: var(--text);
|
| 27 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
|
| 28 |
+
line-height: 1.6;
|
| 29 |
+
min-height: 100vh;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.container {
|
| 33 |
+
max-width: 960px;
|
| 34 |
+
margin: 0 auto;
|
| 35 |
+
padding: 32px 24px 80px;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/* Header */
|
| 39 |
+
header {
|
| 40 |
+
display: flex;
|
| 41 |
+
align-items: center;
|
| 42 |
+
gap: 12px;
|
| 43 |
+
margin-bottom: 32px;
|
| 44 |
+
}
|
| 45 |
+
header h1 {
|
| 46 |
+
font-size: 1.6rem;
|
| 47 |
+
font-weight: 600;
|
| 48 |
+
color: var(--accent);
|
| 49 |
+
}
|
| 50 |
+
header .logo {
|
| 51 |
+
font-size: 1.8rem;
|
| 52 |
+
}
|
| 53 |
+
header .subtitle {
|
| 54 |
+
color: var(--text-dim);
|
| 55 |
+
font-size: 0.9rem;
|
| 56 |
+
margin-left: auto;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/* Form */
|
| 60 |
+
.form-card {
|
| 61 |
+
background: var(--card);
|
| 62 |
+
border: 1px solid var(--border);
|
| 63 |
+
border-radius: var(--radius);
|
| 64 |
+
padding: 24px;
|
| 65 |
+
margin-bottom: 24px;
|
| 66 |
+
}
|
| 67 |
+
.form-grid {
|
| 68 |
+
display: grid;
|
| 69 |
+
grid-template-columns: 1fr 1fr;
|
| 70 |
+
gap: 16px;
|
| 71 |
+
}
|
| 72 |
+
.form-group {
|
| 73 |
+
display: flex;
|
| 74 |
+
flex-direction: column;
|
| 75 |
+
gap: 6px;
|
| 76 |
+
}
|
| 77 |
+
.form-group.full { grid-column: 1 / -1; }
|
| 78 |
+
label {
|
| 79 |
+
font-size: 0.85rem;
|
| 80 |
+
color: var(--text-dim);
|
| 81 |
+
font-weight: 500;
|
| 82 |
+
}
|
| 83 |
+
textarea, input {
|
| 84 |
+
background: var(--bg);
|
| 85 |
+
border: 1px solid var(--border);
|
| 86 |
+
border-radius: 6px;
|
| 87 |
+
color: var(--text);
|
| 88 |
+
padding: 10px 12px;
|
| 89 |
+
font-size: 0.9rem;
|
| 90 |
+
font-family: inherit;
|
| 91 |
+
resize: vertical;
|
| 92 |
+
transition: border-color 0.2s;
|
| 93 |
+
}
|
| 94 |
+
textarea:focus, input:focus {
|
| 95 |
+
outline: none;
|
| 96 |
+
border-color: var(--accent);
|
| 97 |
+
}
|
| 98 |
+
textarea { min-height: 80px; }
|
| 99 |
+
textarea#brief { min-height: 100px; }
|
| 100 |
+
|
| 101 |
+
/* Button */
|
| 102 |
+
.btn {
|
| 103 |
+
background: var(--accent);
|
| 104 |
+
color: #fff;
|
| 105 |
+
border: none;
|
| 106 |
+
border-radius: 6px;
|
| 107 |
+
padding: 10px 24px;
|
| 108 |
+
font-size: 0.95rem;
|
| 109 |
+
font-weight: 600;
|
| 110 |
+
cursor: pointer;
|
| 111 |
+
transition: opacity 0.2s, background 0.2s;
|
| 112 |
+
display: flex;
|
| 113 |
+
align-items: center;
|
| 114 |
+
gap: 8px;
|
| 115 |
+
margin-top: 20px;
|
| 116 |
+
}
|
| 117 |
+
.btn:hover { opacity: 0.9; }
|
| 118 |
+
.btn:disabled {
|
| 119 |
+
background: var(--border);
|
| 120 |
+
color: var(--text-dim);
|
| 121 |
+
cursor: not-allowed;
|
| 122 |
+
}
|
| 123 |
+
.btn .spinner {
|
| 124 |
+
width: 16px; height: 16px;
|
| 125 |
+
border: 2px solid rgba(255,255,255,0.3);
|
| 126 |
+
border-top-color: #fff;
|
| 127 |
+
border-radius: 50%;
|
| 128 |
+
animation: spin 0.6s linear infinite;
|
| 129 |
+
display: none;
|
| 130 |
+
}
|
| 131 |
+
.btn.loading .spinner { display: inline-block; }
|
| 132 |
+
@keyframes spin { to { transform: rotate(360deg); } }
|
| 133 |
+
|
| 134 |
+
/* Results area */
|
| 135 |
+
.results {
|
| 136 |
+
margin-top: 24px;
|
| 137 |
+
}
|
| 138 |
+
.empty-state {
|
| 139 |
+
text-align: center;
|
| 140 |
+
padding: 48px 24px;
|
| 141 |
+
color: var(--text-dim);
|
| 142 |
+
}
|
| 143 |
+
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; }
|
| 144 |
+
|
| 145 |
+
/* Tool cards */
|
| 146 |
+
.tool-cards {
|
| 147 |
+
display: flex;
|
| 148 |
+
flex-direction: column;
|
| 149 |
+
gap: 8px;
|
| 150 |
+
margin-bottom: 20px;
|
| 151 |
+
}
|
| 152 |
+
.tool-card {
|
| 153 |
+
background: var(--card);
|
| 154 |
+
border: 1px solid var(--border);
|
| 155 |
+
border-radius: 6px;
|
| 156 |
+
padding: 12px 16px;
|
| 157 |
+
display: flex;
|
| 158 |
+
align-items: center;
|
| 159 |
+
gap: 10px;
|
| 160 |
+
font-size: 0.85rem;
|
| 161 |
+
}
|
| 162 |
+
.tool-card .status-icon {
|
| 163 |
+
width: 18px; height: 18px;
|
| 164 |
+
display: flex;
|
| 165 |
+
align-items: center;
|
| 166 |
+
justify-content: center;
|
| 167 |
+
flex-shrink: 0;
|
| 168 |
+
}
|
| 169 |
+
.tool-card .status-icon.spinner {
|
| 170 |
+
border: 2px solid var(--border);
|
| 171 |
+
border-top-color: var(--accent);
|
| 172 |
+
border-radius: 50%;
|
| 173 |
+
animation: spin 0.6s linear infinite;
|
| 174 |
+
}
|
| 175 |
+
.tool-card .status-icon.done {
|
| 176 |
+
color: var(--green);
|
| 177 |
+
font-size: 1.1rem;
|
| 178 |
+
}
|
| 179 |
+
.tool-card .tool-name {
|
| 180 |
+
color: var(--accent);
|
| 181 |
+
font-weight: 600;
|
| 182 |
+
}
|
| 183 |
+
.tool-card .tool-args {
|
| 184 |
+
color: var(--text-dim);
|
| 185 |
+
font-size: 0.8rem;
|
| 186 |
+
font-family: 'SF Mono', monospace;
|
| 187 |
+
max-width: 400px;
|
| 188 |
+
overflow: hidden;
|
| 189 |
+
text-overflow: ellipsis;
|
| 190 |
+
white-space: nowrap;
|
| 191 |
+
}
|
| 192 |
+
.tool-card .tool-result {
|
| 193 |
+
color: var(--green);
|
| 194 |
+
font-size: 0.8rem;
|
| 195 |
+
margin-left: auto;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
/* Plan output */
|
| 199 |
+
.plan-output-card {
|
| 200 |
+
background: var(--card);
|
| 201 |
+
border: 1px solid var(--border);
|
| 202 |
+
border-radius: var(--radius);
|
| 203 |
+
overflow: hidden;
|
| 204 |
+
}
|
| 205 |
+
.plan-output-card .header {
|
| 206 |
+
background: var(--bg);
|
| 207 |
+
padding: 12px 16px;
|
| 208 |
+
border-bottom: 1px solid var(--border);
|
| 209 |
+
font-weight: 600;
|
| 210 |
+
font-size: 0.9rem;
|
| 211 |
+
color: var(--accent);
|
| 212 |
+
display: flex;
|
| 213 |
+
align-items: center;
|
| 214 |
+
gap: 8px;
|
| 215 |
+
}
|
| 216 |
+
.plan-output-card .header .cursor {
|
| 217 |
+
display: inline-block;
|
| 218 |
+
width: 8px; height: 16px;
|
| 219 |
+
background: var(--accent);
|
| 220 |
+
animation: blink 1s infinite;
|
| 221 |
+
border-radius: 1px;
|
| 222 |
+
}
|
| 223 |
+
@keyframes blink { 50% { opacity: 0; } }
|
| 224 |
+
.plan-output-card .body {
|
| 225 |
+
padding: 16px 20px;
|
| 226 |
+
white-space: pre-wrap;
|
| 227 |
+
word-wrap: break-word;
|
| 228 |
+
font-size: 0.9rem;
|
| 229 |
+
line-height: 1.7;
|
| 230 |
+
max-height: 600px;
|
| 231 |
+
overflow-y: auto;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
/* Error state */
|
| 235 |
+
.error-state {
|
| 236 |
+
background: #f8514911;
|
| 237 |
+
border: 1px solid var(--red);
|
| 238 |
+
border-radius: var(--radius);
|
| 239 |
+
padding: 16px 20px;
|
| 240 |
+
color: var(--red);
|
| 241 |
+
font-size: 0.9rem;
|
| 242 |
+
}
|
| 243 |
+
.error-state .icon { margin-right: 8px; }
|
| 244 |
+
|
| 245 |
+
/* Markdown-ish section styling */
|
| 246 |
+
.plan-output-card .body h1,
|
| 247 |
+
.plan-output-card .body h2,
|
| 248 |
+
.plan-output-card .body h3 {
|
| 249 |
+
color: var(--accent);
|
| 250 |
+
margin-top: 18px;
|
| 251 |
+
margin-bottom: 8px;
|
| 252 |
+
}
|
| 253 |
+
.plan-output-card .body h2 { font-size: 1.05rem; }
|
| 254 |
+
.plan-output-card .body h3 { font-size: 0.95rem; }
|
| 255 |
+
.plan-output-card .body ul,
|
| 256 |
+
.plan-output-card .body ol {
|
| 257 |
+
margin-left: 20px;
|
| 258 |
+
margin-bottom: 10px;
|
| 259 |
+
}
|
| 260 |
+
.plan-output-card .body li { margin-bottom: 4px; }
|
| 261 |
+
.plan-output-card .body code {
|
| 262 |
+
background: var(--bg);
|
| 263 |
+
padding: 2px 6px;
|
| 264 |
+
border-radius: 4px;
|
| 265 |
+
font-family: 'SF Mono', monospace;
|
| 266 |
+
font-size: 0.85rem;
|
| 267 |
+
}
|
| 268 |
+
.plan-output-card .body strong { color: #fff; }
|
| 269 |
+
|
| 270 |
+
/* Scrollbar */
|
| 271 |
+
::-webkit-scrollbar { width: 8px; }
|
| 272 |
+
::-webkit-scrollbar-track { background: var(--bg); }
|
| 273 |
+
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
|
| 274 |
+
::-webkit-scrollbar-thumb:hover { background: #484f58; }
|
| 275 |
+
|
| 276 |
+
@media (max-width: 640px) {
|
| 277 |
+
.form-grid { grid-template-columns: 1fr; }
|
| 278 |
+
}
|
| 279 |
+
</style>
|
| 280 |
+
</head>
|
| 281 |
+
<body>
|
| 282 |
+
<div class="container">
|
| 283 |
+
|
| 284 |
+
<header>
|
| 285 |
+
<span class="logo">🚀</span>
|
| 286 |
+
<h1>Launch Desk</h1>
|
| 287 |
+
<span class="subtitle">AI-powered launch planning</span>
|
| 288 |
+
</header>
|
| 289 |
+
|
| 290 |
+
<!-- Form -->
|
| 291 |
+
<div class="form-card">
|
| 292 |
+
<div class="form-grid">
|
| 293 |
+
<div class="form-group full">
|
| 294 |
+
<label for="brief">Product Brief</label>
|
| 295 |
+
<textarea id="brief" placeholder="Describe the product you're launching..."></textarea>
|
| 296 |
+
</div>
|
| 297 |
+
<div class="form-group">
|
| 298 |
+
<label for="audience">Target Audience</label>
|
| 299 |
+
<input type="text" id="audience" placeholder="e.g., enterprise DevOps teams">
|
| 300 |
+
</div>
|
| 301 |
+
<div class="form-group">
|
| 302 |
+
<label for="launch_date">Launch Date</label>
|
| 303 |
+
<input type="date" id="launch_date">
|
| 304 |
+
</div>
|
| 305 |
+
<div class="form-group full">
|
| 306 |
+
<label for="constraints">Constraints</label>
|
| 307 |
+
<textarea id="constraints" placeholder="Budget limits, regulatory requirements, hard deadlines..."></textarea>
|
| 308 |
+
</div>
|
| 309 |
+
<div class="form-group full">
|
| 310 |
+
<label for="assets">Available Assets</label>
|
| 311 |
+
<textarea id="assets" placeholder="Existing content, design files, team capacity, budget..."></textarea>
|
| 312 |
+
</div>
|
| 313 |
+
</div>
|
| 314 |
+
<button class="btn" id="generateBtn" onclick="generatePlan()">
|
| 315 |
+
<span class="spinner"></span>
|
| 316 |
+
<span class="btn-text">Generate Plan</span>
|
| 317 |
+
</button>
|
| 318 |
+
</div>
|
| 319 |
+
|
| 320 |
+
<!-- Results -->
|
| 321 |
+
<div class="results" id="results">
|
| 322 |
+
<div class="empty-state">
|
| 323 |
+
<div class="icon">📋</div>
|
| 324 |
+
<p>Fill in the form above and click <strong>Generate Plan</strong> to create your launch plan.</p>
|
| 325 |
+
</div>
|
| 326 |
+
</div>
|
| 327 |
+
|
| 328 |
+
</div>
|
| 329 |
+
|
| 330 |
+
<script>
|
| 331 |
+
// ---------------------------------------------------------------------------
|
| 332 |
+
// State
|
| 333 |
+
// ---------------------------------------------------------------------------
|
| 334 |
+
let isGenerating = false;
|
| 335 |
+
|
| 336 |
+
// ---------------------------------------------------------------------------
|
| 337 |
+
// Helpers
|
| 338 |
+
// ---------------------------------------------------------------------------
|
| 339 |
+
function $(id) { return document.getElementById(id); }
|
| 340 |
+
|
| 341 |
+
function setButtonLoading(loading) {
|
| 342 |
+
const btn = $('generateBtn');
|
| 343 |
+
btn.classList.toggle('loading', loading);
|
| 344 |
+
btn.disabled = loading;
|
| 345 |
+
btn.querySelector('.btn-text').textContent = loading ? 'Generating...' : 'Generate Plan';
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
function escapeHtml(text) {
|
| 349 |
+
const div = document.createElement('div');
|
| 350 |
+
div.textContent = text;
|
| 351 |
+
return div.innerHTML;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
// Minimal markdown → HTML renderer (headings, lists, bold, code, paragraphs)
|
| 355 |
+
function renderMarkdown(md) {
|
| 356 |
+
let html = escapeHtml(md);
|
| 357 |
+
// Headings
|
| 358 |
+
html = html.replace(/^### (.+)$/gm, '<h3>$1</h3>');
|
| 359 |
+
html = html.replace(/^## (.+)$/gm, '<h2>$1</h2>');
|
| 360 |
+
html = html.replace(/^# (.+)$/gm, '<h2>$1</h2>');
|
| 361 |
+
// Bold
|
| 362 |
+
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
|
| 363 |
+
// Inline code
|
| 364 |
+
html = html.replace(/`([^`]+)`/g, '<code>$1</code>');
|
| 365 |
+
// Unordered list items
|
| 366 |
+
html = html.replace(/^\s*[-•] (.+)$/gm, '<li>$1</li>');
|
| 367 |
+
// Ordered list items
|
| 368 |
+
html = html.replace(/^\s*\d+\.\s+(.+)$/gm, '<li>$1</li>');
|
| 369 |
+
// Wrap consecutive <li> in <ul>
|
| 370 |
+
html = html.replace(/(<li>.*?<\/li>\n?)+/gs, function(m) {
|
| 371 |
+
return '<ul>' + m + '</ul>';
|
| 372 |
+
});
|
| 373 |
+
// Paragraphs (double newline)
|
| 374 |
+
html = html.replace(/\n\n/g, '</p><p>');
|
| 375 |
+
html = '<p>' + html + '</p>';
|
| 376 |
+
// Clean up empty <p> tags around block elements
|
| 377 |
+
html = html.replace(/<p>\s*(<h[23]>)/g, '$1');
|
| 378 |
+
html = html.replace(/(<\/h[23]>)\s*<\/p>/g, '$1');
|
| 379 |
+
html = html.replace(/<p>\s*(<ul>)/g, '$1');
|
| 380 |
+
html = html.replace(/(<\/ul>)\s*<\/p>/g, '$1');
|
| 381 |
+
return html;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
// ---------------------------------------------------------------------------
|
| 385 |
+
// SSE streaming
|
| 386 |
+
// ---------------------------------------------------------------------------
|
| 387 |
+
async function generatePlan() {
|
| 388 |
+
if (isGenerating) return;
|
| 389 |
+
isGenerating = true;
|
| 390 |
+
setButtonLoading(true);
|
| 391 |
+
|
| 392 |
+
const payload = {
|
| 393 |
+
brief: $('brief').value.trim(),
|
| 394 |
+
audience: $('audience').value.trim(),
|
| 395 |
+
launch_date: $('launch_date').value,
|
| 396 |
+
constraints: $('constraints').value.trim(),
|
| 397 |
+
assets: $('assets').value.trim(),
|
| 398 |
+
};
|
| 399 |
+
|
| 400 |
+
// Build results DOM
|
| 401 |
+
const results = $('results');
|
| 402 |
+
results.innerHTML = '';
|
| 403 |
+
|
| 404 |
+
// Tool cards container
|
| 405 |
+
const toolCardsDiv = document.createElement('div');
|
| 406 |
+
toolCardsDiv.className = 'tool-cards';
|
| 407 |
+
results.appendChild(toolCardsDiv);
|
| 408 |
+
|
| 409 |
+
// Plan output card
|
| 410 |
+
const planCard = document.createElement('div');
|
| 411 |
+
planCard.className = 'plan-output-card';
|
| 412 |
+
planCard.innerHTML = `
|
| 413 |
+
<div class="header">
|
| 414 |
+
<span>Plan Output</span>
|
| 415 |
+
<span class="cursor"></span>
|
| 416 |
+
</div>
|
| 417 |
+
<div class="body" id="planBody"></div>
|
| 418 |
+
`;
|
| 419 |
+
planCard.style.display = 'none';
|
| 420 |
+
results.appendChild(planCard);
|
| 421 |
+
|
| 422 |
+
const planBody = planCard.querySelector('.body');
|
| 423 |
+
let fullText = '';
|
| 424 |
+
const toolCardMap = {}; // name -> card element (for updating spinner → checkmark)
|
| 425 |
+
|
| 426 |
+
try {
|
| 427 |
+
const resp = await fetch('/api/agent/stream', {
|
| 428 |
+
method: 'POST',
|
| 429 |
+
headers: { 'Content-Type': 'application/json' },
|
| 430 |
+
body: JSON.stringify(payload),
|
| 431 |
+
});
|
| 432 |
+
|
| 433 |
+
if (!resp.ok) {
|
| 434 |
+
throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
const reader = resp.body.getReader();
|
| 438 |
+
const decoder = new TextDecoder();
|
| 439 |
+
let buffer = '';
|
| 440 |
+
|
| 441 |
+
while (true) {
|
| 442 |
+
const { done, value } = await reader.read();
|
| 443 |
+
if (done) break;
|
| 444 |
+
|
| 445 |
+
buffer += decoder.decode(value, { stream: true });
|
| 446 |
+
|
| 447 |
+
// Process complete SSE events (separated by \n\n)
|
| 448 |
+
let idx;
|
| 449 |
+
while ((idx = buffer.indexOf('\n\n')) !== -1) {
|
| 450 |
+
const rawEvent = buffer.slice(0, idx);
|
| 451 |
+
buffer = buffer.slice(idx + 2);
|
| 452 |
+
|
| 453 |
+
// Parse "data: {...}" line
|
| 454 |
+
const line = rawEvent.trim();
|
| 455 |
+
if (!line.startsWith('data:')) continue;
|
| 456 |
+
const jsonStr = line.slice(5).trim();
|
| 457 |
+
if (!jsonStr) continue;
|
| 458 |
+
|
| 459 |
+
let event;
|
| 460 |
+
try { event = JSON.parse(jsonStr); }
|
| 461 |
+
catch (e) { continue; }
|
| 462 |
+
|
| 463 |
+
switch (event.type) {
|
| 464 |
+
case 'tool_start': {
|
| 465 |
+
const card = document.createElement('div');
|
| 466 |
+
card.className = 'tool-card';
|
| 467 |
+
const argsStr = event.args ? JSON.stringify(event.args).slice(0, 120) : '';
|
| 468 |
+
card.innerHTML = `
|
| 469 |
+
<span class="status-icon spinner"></span>
|
| 470 |
+
<span class="tool-name">${escapeHtml(event.name)}</span>
|
| 471 |
+
<span class="tool-args">${escapeHtml(argsStr)}</span>
|
| 472 |
+
`;
|
| 473 |
+
toolCardsDiv.appendChild(card);
|
| 474 |
+
toolCardMap[event.name] = card;
|
| 475 |
+
break;
|
| 476 |
+
}
|
| 477 |
+
case 'tool_end': {
|
| 478 |
+
const card = toolCardMap[event.name];
|
| 479 |
+
if (card) {
|
| 480 |
+
const icon = card.querySelector('.status-icon');
|
| 481 |
+
icon.className = 'status-icon done';
|
| 482 |
+
icon.textContent = '✓';
|
| 483 |
+
// Add a result summary
|
| 484 |
+
const resultStr = event.result ? JSON.stringify(event.result).slice(0, 80) : '';
|
| 485 |
+
const resultSpan = document.createElement('span');
|
| 486 |
+
resultSpan.className = 'tool-result';
|
| 487 |
+
resultSpan.textContent = resultStr ? '✓ result' : 'done';
|
| 488 |
+
card.appendChild(resultSpan);
|
| 489 |
+
}
|
| 490 |
+
break;
|
| 491 |
+
}
|
| 492 |
+
case 'text_delta': {
|
| 493 |
+
planCard.style.display = '';
|
| 494 |
+
fullText += event.text;
|
| 495 |
+
planBody.innerHTML = renderMarkdown(fullText);
|
| 496 |
+
// Auto-scroll
|
| 497 |
+
planBody.scrollTop = planBody.scrollHeight;
|
| 498 |
+
break;
|
| 499 |
+
}
|
| 500 |
+
case 'done': {
|
| 501 |
+
if (event.output) {
|
| 502 |
+
fullText = event.output;
|
| 503 |
+
planBody.innerHTML = renderMarkdown(fullText);
|
| 504 |
+
}
|
| 505 |
+
// Remove blinking cursor
|
| 506 |
+
const cursor = planCard.querySelector('.cursor');
|
| 507 |
+
if (cursor) cursor.remove();
|
| 508 |
+
break;
|
| 509 |
+
}
|
| 510 |
+
case 'error': {
|
| 511 |
+
const errDiv = document.createElement('div');
|
| 512 |
+
errDiv.className = 'error-state';
|
| 513 |
+
errDiv.innerHTML = `<span class="icon">⚠</span>${escapeHtml(event.message || 'Unknown error')}`;
|
| 514 |
+
results.appendChild(errDiv);
|
| 515 |
+
break;
|
| 516 |
+
}
|
| 517 |
+
}
|
| 518 |
+
}
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
// If we got no output at all, show empty state
|
| 522 |
+
if (!fullText && toolCardsDiv.children.length === 0) {
|
| 523 |
+
results.innerHTML = `
|
| 524 |
+
<div class="empty-state">
|
| 525 |
+
<div class="icon">📭</div>
|
| 526 |
+
<p>No output received. Check your API key and try again.</p>
|
| 527 |
+
</div>
|
| 528 |
+
`;
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
} catch (err) {
|
| 532 |
+
results.innerHTML = `
|
| 533 |
+
<div class="error-state">
|
| 534 |
+
<span class="icon">⚠</span>
|
| 535 |
+
${escapeHtml(err.message || 'Failed to connect to the server.')}
|
| 536 |
+
</div>
|
| 537 |
+
`;
|
| 538 |
+
} finally {
|
| 539 |
+
isGenerating = false;
|
| 540 |
+
setButtonLoading(false);
|
| 541 |
+
}
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
// Set default date to 30 days from now
|
| 545 |
+
(function() {
|
| 546 |
+
const d = new Date();
|
| 547 |
+
d.setDate(d.getDate() + 30);
|
| 548 |
+
$('launch_date').value = d.toISOString().split('T')[0];
|
| 549 |
+
})();
|
| 550 |
+
</script>
|
| 551 |
+
</body>
|
| 552 |
+
</html>
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai-agents
|
| 2 |
+
fastapi
|
| 3 |
+
uvicorn
|
| 4 |
+
pydantic
|
| 5 |
+
httpx
|
server/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Launch Desk server package
|
server/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (150 Bytes). View file
|
|
|
server/__pycache__/agent.cpython-311.pyc
ADDED
|
Binary file (1.12 kB). View file
|
|
|
server/__pycache__/main.cpython-311.pyc
ADDED
|
Binary file (8.88 kB). View file
|
|
|
server/__pycache__/tools.cpython-311.pyc
ADDED
|
Binary file (13.3 kB). View file
|
|
|
server/agent.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Launch Desk — Agent Definition
|
| 3 |
+
==============================
|
| 4 |
+
Creates the "Launch Planner" agent using the OpenAI Agents SDK and
|
| 5 |
+
wires up four function tools from tools.py.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
from agents import Agent
|
| 11 |
+
|
| 12 |
+
from server.tools import (
|
| 13 |
+
extract_tasks,
|
| 14 |
+
check_readiness,
|
| 15 |
+
generate_checklist,
|
| 16 |
+
draft_copy,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Agent instructions — the system prompt that guides the Launch Planner.
|
| 20 |
+
INSTRUCTIONS = (
|
| 21 |
+
"You are a launch planning expert. Given a product brief, audience, "
|
| 22 |
+
"launch date, constraints, and available assets, create a prioritized "
|
| 23 |
+
"launch plan. Use your tools to extract tasks, check readiness, "
|
| 24 |
+
"generate checklists, and draft copy. If key details are missing, "
|
| 25 |
+
"ask follow-up questions."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# The agent definition. Model gpt-4.1 is specified by the task.
|
| 29 |
+
agent = Agent(
|
| 30 |
+
name="Launch Planner",
|
| 31 |
+
instructions=INSTRUCTIONS,
|
| 32 |
+
model="gpt-4.1",
|
| 33 |
+
tools=[
|
| 34 |
+
extract_tasks,
|
| 35 |
+
check_readiness,
|
| 36 |
+
generate_checklist,
|
| 37 |
+
draft_copy,
|
| 38 |
+
],
|
| 39 |
+
)
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Launch Desk — FastAPI Backend
|
| 3 |
+
==============================
|
| 4 |
+
Serves the frontend and exposes an SSE streaming endpoint that runs
|
| 5 |
+
the Launch Planner agent via the OpenAI Agents SDK.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import json
|
| 11 |
+
import os
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
from typing import Any
|
| 14 |
+
|
| 15 |
+
from fastapi import FastAPI, Request
|
| 16 |
+
from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
|
| 17 |
+
from pydantic import BaseModel, Field
|
| 18 |
+
|
| 19 |
+
from agents import Runner
|
| 20 |
+
from agents.items import (
|
| 21 |
+
ToolCallItem,
|
| 22 |
+
ToolCallOutputItem,
|
| 23 |
+
)
|
| 24 |
+
from agents.stream_events import (
|
| 25 |
+
RawResponsesStreamEvent,
|
| 26 |
+
RunItemStreamEvent,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
from server.agent import agent
|
| 30 |
+
|
| 31 |
+
# ---------------------------------------------------------------------------
|
| 32 |
+
# App setup
|
| 33 |
+
# ---------------------------------------------------------------------------
|
| 34 |
+
|
| 35 |
+
app = FastAPI(title="Launch Desk")
|
| 36 |
+
|
| 37 |
+
FRONTEND_DIR = Path(__file__).resolve().parent.parent / "frontend"
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# ---------------------------------------------------------------------------
|
| 41 |
+
# Request model
|
| 42 |
+
# ---------------------------------------------------------------------------
|
| 43 |
+
|
| 44 |
+
class LaunchBrief(BaseModel):
|
| 45 |
+
brief: str = Field(default="", description="Product brief text")
|
| 46 |
+
audience: str = Field(default="", description="Target audience")
|
| 47 |
+
launch_date: str = Field(default="", description="Target launch date YYYY-MM-DD")
|
| 48 |
+
constraints: str = Field(default="", description="Constraints or requirements")
|
| 49 |
+
assets: str = Field(default="", description="Available assets")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# ---------------------------------------------------------------------------
|
| 53 |
+
# SSE helper
|
| 54 |
+
# ---------------------------------------------------------------------------
|
| 55 |
+
|
| 56 |
+
def _sse(data: dict) -> str:
|
| 57 |
+
"""Format a dict as a Server-Sent Event line."""
|
| 58 |
+
return f"data: {json.dumps(data)}\n\n"
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _build_prompt(req: LaunchBrief) -> str:
|
| 62 |
+
"""Compose the user prompt from the structured request."""
|
| 63 |
+
parts: list[str] = []
|
| 64 |
+
if req.brief:
|
| 65 |
+
parts.append(f"## Product Brief\n{req.brief}")
|
| 66 |
+
if req.audience:
|
| 67 |
+
parts.append(f"## Target Audience\n{req.audience}")
|
| 68 |
+
if req.launch_date:
|
| 69 |
+
parts.append(f"## Launch Date\n{req.launch_date}")
|
| 70 |
+
if req.constraints:
|
| 71 |
+
parts.append(f"## Constraints\n{req.constraints}")
|
| 72 |
+
if req.assets:
|
| 73 |
+
parts.append(f"## Available Assets\n{req.assets}")
|
| 74 |
+
|
| 75 |
+
if not parts:
|
| 76 |
+
parts.append(
|
| 77 |
+
"No launch details were provided. Ask the user for a product "
|
| 78 |
+
"brief, audience, and target launch date."
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
parts.append(
|
| 82 |
+
"\n## Instructions\n"
|
| 83 |
+
"1. Use extract_tasks to break the brief into prioritised tasks.\n"
|
| 84 |
+
"2. Use check_readiness to assess launch readiness.\n"
|
| 85 |
+
"3. Use generate_checklist to create per-owner checklists.\n"
|
| 86 |
+
"4. Use draft_copy to write launch copy for email and twitter.\n"
|
| 87 |
+
"5. Produce a final plan with these sections:\n"
|
| 88 |
+
" - Prioritized Plan\n"
|
| 89 |
+
" - Risk Register\n"
|
| 90 |
+
" - Owner Checklist\n"
|
| 91 |
+
" - Launch Copy\n"
|
| 92 |
+
" - Follow-up Questions"
|
| 93 |
+
)
|
| 94 |
+
return "\n\n".join(parts)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
# ---------------------------------------------------------------------------
|
| 98 |
+
# SSE streaming generator
|
| 99 |
+
# ---------------------------------------------------------------------------
|
| 100 |
+
|
| 101 |
+
async def _stream_agent(req: LaunchBrief):
|
| 102 |
+
"""Async generator yielding SSE events from the agent run."""
|
| 103 |
+
prompt = _build_prompt(req)
|
| 104 |
+
|
| 105 |
+
# Track which tool calls we've seen so we can pair start/end events.
|
| 106 |
+
# call_id -> tool_name
|
| 107 |
+
seen_calls: dict[str, str] = {}
|
| 108 |
+
|
| 109 |
+
try:
|
| 110 |
+
result = Runner.run_streamed(agent, input=prompt)
|
| 111 |
+
|
| 112 |
+
async for event in result.stream_events():
|
| 113 |
+
|
| 114 |
+
# --- Raw LLM streaming events (text deltas) ---
|
| 115 |
+
if isinstance(event, RawResponsesStreamEvent):
|
| 116 |
+
raw = event.data
|
| 117 |
+
# ResponseTextDeltaEvent has type "response.output_text.delta"
|
| 118 |
+
if hasattr(raw, "type") and raw.type == "response.output_text.delta":
|
| 119 |
+
delta_text = getattr(raw, "delta", "")
|
| 120 |
+
if delta_text:
|
| 121 |
+
yield _sse({"type": "text_delta", "text": delta_text})
|
| 122 |
+
continue
|
| 123 |
+
|
| 124 |
+
# --- Run item events (tool calls, tool outputs, messages) ---
|
| 125 |
+
if isinstance(event, RunItemStreamEvent):
|
| 126 |
+
item = event.item
|
| 127 |
+
|
| 128 |
+
# Tool call started
|
| 129 |
+
if isinstance(item, ToolCallItem):
|
| 130 |
+
tool_name = item.tool_name or "unknown_tool"
|
| 131 |
+
call_id = item.call_id or ""
|
| 132 |
+
if call_id:
|
| 133 |
+
seen_calls[call_id] = tool_name
|
| 134 |
+
# Try to extract arguments from the raw item
|
| 135 |
+
args: Any = {}
|
| 136 |
+
raw_item = item.raw_item
|
| 137 |
+
if isinstance(raw_item, dict):
|
| 138 |
+
args = raw_item.get("arguments", {})
|
| 139 |
+
elif hasattr(raw_item, "arguments"):
|
| 140 |
+
args = raw_item.arguments
|
| 141 |
+
# Parse args if they're a JSON string
|
| 142 |
+
if isinstance(args, str):
|
| 143 |
+
try:
|
| 144 |
+
args = json.loads(args)
|
| 145 |
+
except (json.JSONDecodeError, TypeError):
|
| 146 |
+
pass
|
| 147 |
+
yield _sse({
|
| 148 |
+
"type": "tool_start",
|
| 149 |
+
"name": tool_name,
|
| 150 |
+
"args": args,
|
| 151 |
+
})
|
| 152 |
+
continue
|
| 153 |
+
|
| 154 |
+
# Tool call completed
|
| 155 |
+
if isinstance(item, ToolCallOutputItem):
|
| 156 |
+
raw_item = item.raw_item
|
| 157 |
+
call_id = item.call_id or ""
|
| 158 |
+
tool_name = seen_calls.get(call_id, "unknown_tool")
|
| 159 |
+
output = item.output
|
| 160 |
+
# Try to parse output as JSON for nicer SSE payload
|
| 161 |
+
if isinstance(output, str):
|
| 162 |
+
try:
|
| 163 |
+
output = json.loads(output)
|
| 164 |
+
except (json.JSONDecodeError, TypeError):
|
| 165 |
+
pass
|
| 166 |
+
yield _sse({
|
| 167 |
+
"type": "tool_end",
|
| 168 |
+
"name": tool_name,
|
| 169 |
+
"result": output,
|
| 170 |
+
})
|
| 171 |
+
continue
|
| 172 |
+
|
| 173 |
+
# --- Done ---
|
| 174 |
+
final_output = result.final_output
|
| 175 |
+
yield _sse({"type": "done", "output": final_output})
|
| 176 |
+
|
| 177 |
+
except Exception as exc:
|
| 178 |
+
yield _sse({
|
| 179 |
+
"type": "error",
|
| 180 |
+
"message": f"Agent error: {exc}",
|
| 181 |
+
})
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
# ---------------------------------------------------------------------------
|
| 185 |
+
# Endpoints
|
| 186 |
+
# ---------------------------------------------------------------------------
|
| 187 |
+
|
| 188 |
+
@app.get("/api/health")
|
| 189 |
+
async def health():
|
| 190 |
+
return {"status": "ok"}
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
@app.post("/api/agent/stream")
|
| 194 |
+
async def agent_stream(req: LaunchBrief):
|
| 195 |
+
return StreamingResponse(
|
| 196 |
+
_stream_agent(req),
|
| 197 |
+
media_type="text/event-stream",
|
| 198 |
+
headers={
|
| 199 |
+
"Cache-Control": "no-cache",
|
| 200 |
+
"Connection": "keep-alive",
|
| 201 |
+
"X-Accel-Buffering": "no",
|
| 202 |
+
},
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
@app.get("/", response_class=HTMLResponse)
|
| 207 |
+
async def serve_frontend():
|
| 208 |
+
index_path = FRONTEND_DIR / "index.html"
|
| 209 |
+
if index_path.exists():
|
| 210 |
+
return HTMLResponse(content=index_path.read_text(encoding="utf-8"))
|
| 211 |
+
return HTMLResponse(content="<h1>Frontend not found</h1>", status_code=404)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
# ---------------------------------------------------------------------------
|
| 215 |
+
# Entry point for `python -m server.main` or `uvicorn server.main:app`
|
| 216 |
+
# ---------------------------------------------------------------------------
|
| 217 |
+
|
| 218 |
+
if __name__ == "__main__":
|
| 219 |
+
import uvicorn
|
| 220 |
+
|
| 221 |
+
uvicorn.run(
|
| 222 |
+
"server.main:app",
|
| 223 |
+
host="0.0.0.0",
|
| 224 |
+
port=8001,
|
| 225 |
+
reload=False,
|
| 226 |
+
)
|
server/tools.py
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
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ool decorated tools for the Launch Planner agent.
|
| 5 |
+
Each does simple but realistic logic without external API calls.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import re
|
| 11 |
+
from agents import function_tool
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# ---------------------------------------------------------------------------
|
| 15 |
+
# 1. extract_tasks
|
| 16 |
+
# ---------------------------------------------------------------------------
|
| 17 |
+
|
| 18 |
+
@function_tool
|
| 19 |
+
def extract_tasks(brief: str) -> list[dict]:
|
| 20 |
+
"""Parse a product brief and extract a list of launch tasks.
|
| 21 |
+
|
| 22 |
+
Each task includes a name, priority (high/medium/low), owner role,
|
| 23 |
+
and a relative deadline expressed as days before launch.
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
brief: Free-form product brief text.
|
| 27 |
+
|
| 28 |
+
Returns:
|
| 29 |
+
A list of task dicts: {task, priority, owner, deadline}
|
| 30 |
+
"""
|
| 31 |
+
if not brief or not brief.strip():
|
| 32 |
+
return [
|
| 33 |
+
{"task": "Define launch goals and metrics", "priority": "high",
|
| 34 |
+
"owner": "Product", "deadline": "T-30 days"},
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
text = brief.lower()
|
| 38 |
+
|
| 39 |
+
# Heuristic keyword → task mapping. We scan the brief for domain keywords
|
| 40 |
+
# and build a prioritised task list from whatever matches.
|
| 41 |
+
task_templates: list[dict] = [
|
| 42 |
+
{"keywords": ["api", "backend", "server", "database", "infra"],
|
| 43 |
+
"task": "Freeze code and tag release candidate",
|
| 44 |
+
"priority": "high", "owner": "Engineering", "deadline": "T-14 days"},
|
| 45 |
+
{"keywords": ["qa", "test", "bug", "regression", "testing"],
|
| 46 |
+
"task": "Complete QA regression and smoke testing",
|
| 47 |
+
"priority": "high", "owner": "QA", "deadline": "T-7 days"},
|
| 48 |
+
{"keywords": ["doc", "documentation", "guide", "readme", "manual"],
|
| 49 |
+
"task": "Write user-facing documentation and API guides",
|
| 50 |
+
"priority": "medium", "owner": "Technical Writing", "deadline": "T-10 days"},
|
| 51 |
+
{"keywords": ["market", "marketing", "campaign", "ad", "social", "blog", "press"],
|
| 52 |
+
"task": "Prepare marketing campaign assets and schedule posts",
|
| 53 |
+
"priority": "high", "owner": "Marketing", "deadline": "T-5 days"},
|
| 54 |
+
{"keywords": ["support", "customer", "help", "ticket", "oncall"],
|
| 55 |
+
"task": "Staff support team and prepare runbooks",
|
| 56 |
+
"priority": "medium", "owner": "Customer Success", "deadline": "T-3 days"},
|
| 57 |
+
{"keywords": ["security", "compliance", "audit", "gdpr", "soc"],
|
| 58 |
+
"task": "Complete security review and compliance sign-off",
|
| 59 |
+
"priority": "high", "owner": "Security", "deadline": "T-21 days"},
|
| 60 |
+
{"keywords": ["pricing", "billing", "plan", "tier", "subscription"],
|
| 61 |
+
"task": "Finalise pricing tiers and billing configuration",
|
| 62 |
+
"priority": "medium", "owner": "Finance", "deadline": "T-12 days"},
|
| 63 |
+
{"keywords": ["analytics", "tracking", "metric", "dashboard", "kpi"],
|
| 64 |
+
"task": "Set up analytics dashboards and success metrics",
|
| 65 |
+
"priority": "low", "owner": "Data", "deadline": "T-8 days"},
|
| 66 |
+
{"keywords": ["design", "ui", "ux", "figma", "mockup", "brand"],
|
| 67 |
+
"task": "Finalise UI polish and brand assets",
|
| 68 |
+
"priority": "medium", "owner": "Design", "deadline": "T-10 days"},
|
| 69 |
+
{"keywords": ["legal", "contract", "terms", "privacy", "policy"],
|
| 70 |
+
"task": "Review legal terms and privacy policy updates",
|
| 71 |
+
"priority": "medium", "owner": "Legal", "deadline": "T-15 days"},
|
| 72 |
+
]
|
| 73 |
+
|
| 74 |
+
tasks: list[dict] = []
|
| 75 |
+
for tmpl in task_templates:
|
| 76 |
+
if any(kw in text for kw in tmpl["keywords"]):
|
| 77 |
+
tasks.append({
|
| 78 |
+
"task": tmpl["task"],
|
| 79 |
+
"priority": tmpl["priority"],
|
| 80 |
+
"owner": tmpl["owner"],
|
| 81 |
+
"deadline": tmpl["deadline"],
|
| 82 |
+
})
|
| 83 |
+
|
| 84 |
+
# Always include goal definition as the first task
|
| 85 |
+
always = {
|
| 86 |
+
"task": "Define launch goals and success metrics",
|
| 87 |
+
"priority": "high",
|
| 88 |
+
"owner": "Product",
|
| 89 |
+
"deadline": "T-30 days",
|
| 90 |
+
}
|
| 91 |
+
if not any(t["task"] == always["task"] for t in tasks):
|
| 92 |
+
tasks.insert(0, always)
|
| 93 |
+
|
| 94 |
+
# Always include a launch-day verification task
|
| 95 |
+
launch_day = {
|
| 96 |
+
"task": "Launch-day verification and monitoring",
|
| 97 |
+
"priority": "high",
|
| 98 |
+
"owner": "Engineering",
|
| 99 |
+
"deadline": "Launch day (T-0)",
|
| 100 |
+
}
|
| 101 |
+
if not any(t["task"] == launch_day["task"] for t in tasks):
|
| 102 |
+
tasks.append(launch_day)
|
| 103 |
+
|
| 104 |
+
return tasks
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
# ---------------------------------------------------------------------------
|
| 108 |
+
# 2. check_readiness
|
| 109 |
+
# ---------------------------------------------------------------------------
|
| 110 |
+
|
| 111 |
+
@function_tool
|
| 112 |
+
def check_readiness(tasks: str, launch_date: str) -> dict:
|
| 113 |
+
"""Check launch readiness against a five-point rubric.
|
| 114 |
+
|
| 115 |
+
The rubric covers: code frozen, docs written, QA passed, marketing
|
| 116 |
+
ready, and support staffed. We look for evidence of each in the
|
| 117 |
+
provided task list text.
|
| 118 |
+
|
| 119 |
+
Args:
|
| 120 |
+
tasks: The extracted task list (as a string or JSON).
|
| 121 |
+
launch_date: Target launch date in YYYY-MM-DD format.
|
| 122 |
+
|
| 123 |
+
Returns:
|
| 124 |
+
{ready: bool, score: int (0-100), gaps: list[str]}
|
| 125 |
+
"""
|
| 126 |
+
text = (tasks or "").lower()
|
| 127 |
+
|
| 128 |
+
rubric = [
|
| 129 |
+
("code frozen", ["code", "freeze", "tag", "release candidate", "engineering"]),
|
| 130 |
+
("docs written", ["doc", "documentation", "guide", "readme", "writing"]),
|
| 131 |
+
("QA passed", ["qa", "test", "regression", "smoke", "bug"]),
|
| 132 |
+
("marketing ready", ["market", "campaign", "social", "ad", "press", "blog"]),
|
| 133 |
+
("support staffed", ["support", "customer", "runbook", "oncall", "help"]),
|
| 134 |
+
]
|
| 135 |
+
|
| 136 |
+
covered: list[str] = []
|
| 137 |
+
gaps: list[str] = []
|
| 138 |
+
|
| 139 |
+
for label, keywords in rubric:
|
| 140 |
+
if any(kw in text for kw in keywords):
|
| 141 |
+
covered.append(label)
|
| 142 |
+
else:
|
| 143 |
+
gaps.append(label)
|
| 144 |
+
|
| 145 |
+
score = int((len(covered) / len(rubric)) * 100)
|
| 146 |
+
ready = len(gaps) == 0 and score >= 100
|
| 147 |
+
|
| 148 |
+
# If launch date is missing we flag it as a gap too
|
| 149 |
+
if not launch_date or not launch_date.strip():
|
| 150 |
+
gaps.append("launch date not set")
|
| 151 |
+
score = max(0, score - 10)
|
| 152 |
+
|
| 153 |
+
return {
|
| 154 |
+
"ready": ready,
|
| 155 |
+
"score": score,
|
| 156 |
+
"gaps": gaps,
|
| 157 |
+
"covered": covered,
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
# ---------------------------------------------------------------------------
|
| 162 |
+
# 3. generate_checklist
|
| 163 |
+
# ---------------------------------------------------------------------------
|
| 164 |
+
|
| 165 |
+
@function_tool
|
| 166 |
+
def generate_checklist(tasks: str) -> list[dict]:
|
| 167 |
+
"""Generate per-owner checklists from a task list.
|
| 168 |
+
|
| 169 |
+
Parses the tasks string and groups items by owner, producing a
|
| 170 |
+
checklist for each owner with concrete action items.
|
| 171 |
+
|
| 172 |
+
Args:
|
| 173 |
+
tasks: The extracted task list (string or JSON).
|
| 174 |
+
|
| 175 |
+
Returns:
|
| 176 |
+
A list of {owner, items: [str]} dicts.
|
| 177 |
+
"""
|
| 178 |
+
# Try to parse as JSON list of dicts; fall back to line parsing
|
| 179 |
+
import json
|
| 180 |
+
|
| 181 |
+
task_items: list[dict] = []
|
| 182 |
+
stripped = (tasks or "").strip()
|
| 183 |
+
|
| 184 |
+
if stripped:
|
| 185 |
+
try:
|
| 186 |
+
parsed = json.loads(stripped)
|
| 187 |
+
if isinstance(parsed, list):
|
| 188 |
+
task_items = parsed
|
| 189 |
+
except (json.JSONDecodeError, TypeError):
|
| 190 |
+
# Fall back: split by newline, treat each line as a task
|
| 191 |
+
for line in stripped.splitlines():
|
| 192 |
+
line = line.strip().strip("-").strip()
|
| 193 |
+
if line:
|
| 194 |
+
task_items.append({"task": line, "owner": "General"})
|
| 195 |
+
|
| 196 |
+
# If nothing parsed, provide a default checklist
|
| 197 |
+
if not task_items:
|
| 198 |
+
task_items = [
|
| 199 |
+
{"task": "Define launch goals and metrics", "owner": "Product"},
|
| 200 |
+
{"task": "Freeze code and tag release candidate", "owner": "Engineering"},
|
| 201 |
+
{"task": "Complete QA regression testing", "owner": "QA"},
|
| 202 |
+
{"task": "Write documentation", "owner": "Technical Writing"},
|
| 203 |
+
{"task": "Prepare marketing campaign", "owner": "Marketing"},
|
| 204 |
+
{"task": "Staff support team", "owner": "Customer Success"},
|
| 205 |
+
]
|
| 206 |
+
|
| 207 |
+
# Group tasks by owner
|
| 208 |
+
by_owner: dict[str, list[str]] = {}
|
| 209 |
+
for t in task_items:
|
| 210 |
+
owner = t.get("owner", "General")
|
| 211 |
+
task_name = t.get("task", str(t))
|
| 212 |
+
by_owner.setdefault(owner, []).append(task_name)
|
| 213 |
+
|
| 214 |
+
# Build owner checklists with concrete action items
|
| 215 |
+
checklists: list[dict] = []
|
| 216 |
+
for owner, task_names in by_owner.items():
|
| 217 |
+
items: list[str] = []
|
| 218 |
+
for tn in task_names:
|
| 219 |
+
items.append(f"Confirm: {tn}")
|
| 220 |
+
items.append(f"Sign off: {tn}")
|
| 221 |
+
# Add a shared pre-launch check for every owner
|
| 222 |
+
items.append("Review final launch checklist with launch lead")
|
| 223 |
+
checklists.append({"owner": owner, "items": items})
|
| 224 |
+
|
| 225 |
+
# Ensure there is always a Launch Lead checklist
|
| 226 |
+
if not any(c["owner"] == "Launch Lead" for c in checklists):
|
| 227 |
+
checklists.append({
|
| 228 |
+
"owner": "Launch Lead",
|
| 229 |
+
"items": [
|
| 230 |
+
"Confirm all owners have signed off",
|
| 231 |
+
"Verify go/no-go criteria are met",
|
| 232 |
+
"Schedule launch-day standup",
|
| 233 |
+
"Monitor dashboards during launch window",
|
| 234 |
+
],
|
| 235 |
+
})
|
| 236 |
+
|
| 237 |
+
return checklists
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
# ---------------------------------------------------------------------------
|
| 241 |
+
# 4. draft_copy
|
| 242 |
+
# ---------------------------------------------------------------------------
|
| 243 |
+
|
| 244 |
+
@function_tool
|
| 245 |
+
def draft_copy(channel: str, product: str, audience: str) -> dict:
|
| 246 |
+
"""Draft marketing copy for a specific channel.
|
| 247 |
+
|
| 248 |
+
Generates a headline, body, and call-to-action tailored to the
|
| 249 |
+
channel, product, and audience.
|
| 250 |
+
|
| 251 |
+
Args:
|
| 252 |
+
channel: Marketing channel (e.g. "email", "twitter", "blog",
|
| 253 |
+
"linkedin", "landing_page").
|
| 254 |
+
product: Product name or short description.
|
| 255 |
+
audience: Target audience description.
|
| 256 |
+
|
| 257 |
+
Returns:
|
| 258 |
+
{headline: str, body: str, cta: str}
|
| 259 |
+
"""
|
| 260 |
+
ch = (channel or "").lower().strip()
|
| 261 |
+
prod = (product or "").strip() or "our new product"
|
| 262 |
+
aud = (audience or "").strip() or "your team"
|
| 263 |
+
|
| 264 |
+
# Channel-specific copy templates
|
| 265 |
+
if ch in ("twitter", "x", "tweet"):
|
| 266 |
+
headline = f"🚀 {prod} is live — built for {aud}."
|
| 267 |
+
body = (
|
| 268 |
+
f"We just shipped {prod}, designed from the ground up for {aud}. "
|
| 269 |
+
"Faster, simpler, and ready for production today. "
|
| 270 |
+
"Check it out 👇"
|
| 271 |
+
)
|
| 272 |
+
cta = "Try it now →"
|
| 273 |
+
|
| 274 |
+
elif ch in ("email", "newsletter", "drip"):
|
| 275 |
+
headline = f"Introducing {prod} — now available for {aud}"
|
| 276 |
+
body = (
|
| 277 |
+
f"Hi there,\n\n"
|
| 278 |
+
f"We're excited to announce {prod}, purpose-built for {aud}. "
|
| 279 |
+
"This release brings a refined experience, improved performance, "
|
| 280 |
+
"and the features you've been asking for.\n\n"
|
| 281 |
+
"Here's what's new:\n"
|
| 282 |
+
" • Streamlined workflow that saves you time\n"
|
| 283 |
+
" • Built-in reliability for production use\n"
|
| 284 |
+
" • Thoughtful design choices throughout\n\n"
|
| 285 |
+
"We'd love your feedback as you try it out."
|
| 286 |
+
)
|
| 287 |
+
cta = "Get started today"
|
| 288 |
+
|
| 289 |
+
elif ch in ("blog", "blog post", "announcement"):
|
| 290 |
+
headline = f"{prod}: A new standard for {aud}"
|
| 291 |
+
body = (
|
| 292 |
+
f"Today we're launching {prod}, our most refined release yet. "
|
| 293 |
+
f"Built specifically for {aud}, it combines the features you need "
|
| 294 |
+
"with the reliability you expect.\n\n"
|
| 295 |
+
"In this post we'll walk through what's new, why we built it, "
|
| 296 |
+
"and how to get started in under five minutes."
|
| 297 |
+
)
|
| 298 |
+
cta = "Read the full announcement"
|
| 299 |
+
|
| 300 |
+
elif ch in ("linkedin", "li"):
|
| 301 |
+
headline = f"We just launched {prod} — here's why it matters for {aud}"
|
| 302 |
+
body = (
|
| 303 |
+
f"After months of iteration, {prod} is now generally available. "
|
| 304 |
+
f"We built it for {aud} who need a solution that's both powerful "
|
| 305 |
+
"and dependable. Here's what went into it and what it means for you."
|
| 306 |
+
)
|
| 307 |
+
cta = "Learn more"
|
| 308 |
+
|
| 309 |
+
elif ch in ("landing", "landing page", "landing_page", "homepage"):
|
| 310 |
+
headline = f"{prod} — purpose-built for {aud}"
|
| 311 |
+
body = (
|
| 312 |
+
f"{prod} gives {aud} the tools they need to move faster, "
|
| 313 |
+
"with the reliability required for real production workloads. "
|
| 314 |
+
"No noise, no bloat — just what matters."
|
| 315 |
+
)
|
| 316 |
+
cta = "Start building for free"
|
| 317 |
+
|
| 318 |
+
else:
|
| 319 |
+
# Generic fallback for unknown channels
|
| 320 |
+
headline = f"Introducing {prod}"
|
| 321 |
+
body = (
|
| 322 |
+
f"{prod} is now available. Designed for {aud}, it delivers "
|
| 323 |
+
"the features and reliability you need to succeed."
|
| 324 |
+
)
|
| 325 |
+
cta = "Learn more"
|
| 326 |
+
|
| 327 |
+
return {
|
| 328 |
+
"headline": headline,
|
| 329 |
+
"body": body,
|
| 330 |
+
"cta": cta,
|
| 331 |
+
"channel": ch or "general",
|
| 332 |
+
}
|
tests/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Tests package
|
tests/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (149 Bytes). View file
|
|
|
tests/__pycache__/test_agent.cpython-311-pytest-9.1.1.pyc
ADDED
|
Binary file (45.9 kB). View file
|
|
|
tests/test_agent.py
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Launch Desk — Agent & Tool Tests
|
| 3 |
+
================================
|
| 4 |
+
Pytest tests that verify the agent has 4 tools registered and that each
|
| 5 |
+
tool returns the expected structure.
|
| 6 |
+
|
| 7 |
+
Because @function_tool wraps functions in a FunctionTool dataclass, we
|
| 8 |
+
access the original callable via `tool.on_invoke_tool._get_wrapped_callable()`.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import pytest
|
| 12 |
+
|
| 13 |
+
from server.agent import agent
|
| 14 |
+
from server.tools import (
|
| 15 |
+
extract_tasks,
|
| 16 |
+
check_readiness,
|
| 17 |
+
generate_checklist,
|
| 18 |
+
draft_copy,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# ---------------------------------------------------------------------------
|
| 23 |
+
# Helper: get the original wrapped callable from a FunctionTool
|
| 24 |
+
# ---------------------------------------------------------------------------
|
| 25 |
+
|
| 26 |
+
def _get_callable(tool):
|
| 27 |
+
"""Extract the original Python function from a @function_tool wrapper."""
|
| 28 |
+
return tool.on_invoke_tool._get_wrapped_callable()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# ---------------------------------------------------------------------------
|
| 32 |
+
# Test: agent has 4 tools registered
|
| 33 |
+
# ---------------------------------------------------------------------------
|
| 34 |
+
|
| 35 |
+
def test_agent_has_four_tools():
|
| 36 |
+
"""The Launch Planner agent should have exactly 4 tools registered."""
|
| 37 |
+
assert agent is not None
|
| 38 |
+
assert agent.name == "Launch Planner"
|
| 39 |
+
assert agent.tools is not None
|
| 40 |
+
assert len(agent.tools) == 4, f"Expected 4 tools, got {len(agent.tools)}"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_agent_has_expected_tool_names():
|
| 44 |
+
"""The agent should have tools with the expected names."""
|
| 45 |
+
tool_names = {t.name for t in agent.tools}
|
| 46 |
+
expected = {"extract_tasks", "check_readiness", "generate_checklist", "draft_copy"}
|
| 47 |
+
assert tool_names == expected, f"Expected {expected}, got {tool_names}"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# ---------------------------------------------------------------------------
|
| 51 |
+
# Test: extract_tasks returns expected structure
|
| 52 |
+
# ---------------------------------------------------------------------------
|
| 53 |
+
|
| 54 |
+
def test_extract_tasks_returns_list_of_dicts():
|
| 55 |
+
"""extract_tasks should return a list of dicts with task/priority/owner/deadline."""
|
| 56 |
+
fn = _get_callable(extract_tasks)
|
| 57 |
+
brief = "We are launching a new API with backend, QA testing, and marketing campaign"
|
| 58 |
+
result = fn(brief)
|
| 59 |
+
|
| 60 |
+
assert isinstance(result, list)
|
| 61 |
+
assert len(result) > 0
|
| 62 |
+
|
| 63 |
+
for task in result:
|
| 64 |
+
assert isinstance(task, dict)
|
| 65 |
+
assert "task" in task
|
| 66 |
+
assert "priority" in task
|
| 67 |
+
assert "owner" in task
|
| 68 |
+
assert "deadline" in task
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def test_extract_tasks_handles_empty_brief():
|
| 72 |
+
"""extract_tasks should handle an empty brief gracefully."""
|
| 73 |
+
fn = _get_callable(extract_tasks)
|
| 74 |
+
result = fn("")
|
| 75 |
+
assert isinstance(result, list)
|
| 76 |
+
assert len(result) > 0
|
| 77 |
+
assert "task" in result[0]
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def test_extract_tasks_priority_values():
|
| 81 |
+
"""All priorities should be high, medium, or low."""
|
| 82 |
+
fn = _get_callable(extract_tasks)
|
| 83 |
+
result = fn("API, QA, docs, marketing, support, security, pricing, analytics, design, legal")
|
| 84 |
+
valid_priorities = {"high", "medium", "low"}
|
| 85 |
+
for task in result:
|
| 86 |
+
assert task["priority"] in valid_priorities
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# ---------------------------------------------------------------------------
|
| 90 |
+
# Test: check_readiness returns expected structure
|
| 91 |
+
# ---------------------------------------------------------------------------
|
| 92 |
+
|
| 93 |
+
def test_check_readiness_returns_dict():
|
| 94 |
+
"""check_readiness should return a dict with ready/score/gaps."""
|
| 95 |
+
fn = _get_callable(check_readiness)
|
| 96 |
+
tasks = "code freeze, QA testing, marketing campaign, documentation, support staffing"
|
| 97 |
+
result = fn(tasks, "2026-10-01")
|
| 98 |
+
|
| 99 |
+
assert isinstance(result, dict)
|
| 100 |
+
assert "ready" in result
|
| 101 |
+
assert "score" in result
|
| 102 |
+
assert "gaps" in result
|
| 103 |
+
assert isinstance(result["ready"], bool)
|
| 104 |
+
assert isinstance(result["score"], int)
|
| 105 |
+
assert isinstance(result["gaps"], list)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def test_check_readiness_high_score_when_covered():
|
| 109 |
+
"""check_readiness should give a high score when all rubric areas are covered."""
|
| 110 |
+
fn = _get_callable(check_readiness)
|
| 111 |
+
tasks = "code freeze, QA testing, marketing campaign, documentation, support staffing"
|
| 112 |
+
result = fn(tasks, "2026-10-01")
|
| 113 |
+
assert result["score"] >= 80, f"Expected high score, got {result['score']}"
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def test_check_readiness_low_score_when_gaps():
|
| 117 |
+
"""check_readiness should give a low score when rubric areas are missing."""
|
| 118 |
+
fn = _get_callable(check_readiness)
|
| 119 |
+
tasks = "just some random text with no keywords"
|
| 120 |
+
result = fn(tasks, "2026-10-01")
|
| 121 |
+
assert result["score"] < 100
|
| 122 |
+
assert len(result["gaps"]) > 0
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
# ---------------------------------------------------------------------------
|
| 126 |
+
# Test: generate_checklist returns expected structure
|
| 127 |
+
# ---------------------------------------------------------------------------
|
| 128 |
+
|
| 129 |
+
def test_generate_checklist_returns_list_of_dicts():
|
| 130 |
+
"""generate_checklist should return a list of {owner, items} dicts."""
|
| 131 |
+
fn = _get_callable(generate_checklist)
|
| 132 |
+
import json
|
| 133 |
+
tasks_json = json.dumps([
|
| 134 |
+
{"task": "Freeze code", "owner": "Engineering", "priority": "high", "deadline": "T-14"},
|
| 135 |
+
{"task": "QA testing", "owner": "QA", "priority": "high", "deadline": "T-7"},
|
| 136 |
+
{"task": "Marketing campaign", "owner": "Marketing", "priority": "high", "deadline": "T-5"},
|
| 137 |
+
])
|
| 138 |
+
result = fn(tasks_json)
|
| 139 |
+
|
| 140 |
+
assert isinstance(result, list)
|
| 141 |
+
assert len(result) > 0
|
| 142 |
+
|
| 143 |
+
for checklist in result:
|
| 144 |
+
assert isinstance(checklist, dict)
|
| 145 |
+
assert "owner" in checklist
|
| 146 |
+
assert "items" in checklist
|
| 147 |
+
assert isinstance(checklist["items"], list)
|
| 148 |
+
assert len(checklist["items"]) > 0
|
| 149 |
+
for item in checklist["items"]:
|
| 150 |
+
assert isinstance(item, str)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def test_generate_checklist_includes_launch_lead():
|
| 154 |
+
"""generate_checklist should include a Launch Lead checklist."""
|
| 155 |
+
fn = _get_callable(generate_checklist)
|
| 156 |
+
result = fn("[]")
|
| 157 |
+
owners = [c["owner"] for c in result]
|
| 158 |
+
assert "Launch Lead" in owners
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def test_generate_checklist_groups_by_owner():
|
| 162 |
+
"""generate_checklist should group tasks by owner."""
|
| 163 |
+
import json
|
| 164 |
+
fn = _get_callable(generate_checklist)
|
| 165 |
+
tasks_json = json.dumps([
|
| 166 |
+
{"task": "Task A", "owner": "Engineering"},
|
| 167 |
+
{"task": "Task B", "owner": "Engineering"},
|
| 168 |
+
{"task": "Task C", "owner": "Marketing"},
|
| 169 |
+
])
|
| 170 |
+
result = fn(tasks_json)
|
| 171 |
+
owners = {c["owner"] for c in result}
|
| 172 |
+
assert "Engineering" in owners
|
| 173 |
+
assert "Marketing" in owners
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
# ---------------------------------------------------------------------------
|
| 177 |
+
# Test: draft_copy returns expected structure
|
| 178 |
+
# ---------------------------------------------------------------------------
|
| 179 |
+
|
| 180 |
+
def test_draft_copy_returns_dict():
|
| 181 |
+
"""draft_copy should return a dict with headline/body/cta."""
|
| 182 |
+
fn = _get_callable(draft_copy)
|
| 183 |
+
result = fn("email", "LaunchDesk Pro", "enterprise DevOps teams")
|
| 184 |
+
|
| 185 |
+
assert isinstance(result, dict)
|
| 186 |
+
assert "headline" in result
|
| 187 |
+
assert "body" in result
|
| 188 |
+
assert "cta" in result
|
| 189 |
+
assert isinstance(result["headline"], str)
|
| 190 |
+
assert isinstance(result["body"], str)
|
| 191 |
+
assert isinstance(result["cta"], str)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def test_draft_copy_channel_specific():
|
| 195 |
+
"""draft_copy should produce different copy for different channels."""
|
| 196 |
+
fn = _get_callable(draft_copy)
|
| 197 |
+
email = fn("email", "ProductX", "developers")
|
| 198 |
+
twitter = fn("twitter", "ProductX", "developers")
|
| 199 |
+
assert email["headline"] != twitter["headline"], "Copy should differ by channel"
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def test_draft_copy_includes_product_and_audience():
|
| 203 |
+
"""draft_copy should reference the product name and audience."""
|
| 204 |
+
fn = _get_callable(draft_copy)
|
| 205 |
+
result = fn("email", "MyProduct", "data scientists")
|
| 206 |
+
assert "MyProduct" in result["headline"] or "MyProduct" in result["body"]
|
| 207 |
+
assert "data scientists" in result["headline"] or "data scientists" in result["body"]
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def test_draft_copy_handles_unknown_channel():
|
| 211 |
+
"""draft_copy should handle an unknown channel gracefully."""
|
| 212 |
+
fn = _get_callable(draft_copy)
|
| 213 |
+
result = fn("radio", "ProductX", "general audience")
|
| 214 |
+
assert isinstance(result, dict)
|
| 215 |
+
assert "headline" in result
|
| 216 |
+
assert "body" in result
|
| 217 |
+
assert "cta" in result
|