@migma/mcp 1.11.9 → 1.11.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -5
- package/build/index.d.ts +8 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +15 -8
- package/build/index.js.map +1 -1
- package/build/tools/__tests__/email-card.test.d.ts +2 -0
- package/build/tools/__tests__/email-card.test.d.ts.map +1 -0
- package/build/tools/__tests__/email-card.test.js +216 -0
- package/build/tools/__tests__/email-card.test.js.map +1 -0
- package/build/tools/__tests__/send-approval.test.js +30 -14
- package/build/tools/__tests__/send-approval.test.js.map +1 -1
- package/build/tools/email-card.d.ts +14 -0
- package/build/tools/email-card.d.ts.map +1 -0
- package/build/tools/email-card.js +717 -0
- package/build/tools/email-card.js.map +1 -0
- package/build/tools/email-images.d.ts +2 -2
- package/build/tools/email-images.d.ts.map +1 -1
- package/build/tools/email-images.js +25 -10
- package/build/tools/email-images.js.map +1 -1
- package/build/tools/generate.d.ts +2 -2
- package/build/tools/generate.d.ts.map +1 -1
- package/build/tools/generate.js +24 -9
- package/build/tools/generate.js.map +1 -1
- package/build/tools/mcp-apps.d.ts +16 -0
- package/build/tools/mcp-apps.d.ts.map +1 -0
- package/build/tools/mcp-apps.js +27 -0
- package/build/tools/mcp-apps.js.map +1 -0
- package/build/tools/send-approval-card.d.ts.map +1 -1
- package/build/tools/send-approval-card.js +8 -8
- package/build/tools/send-approval-card.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import { mcpAppMeta, registerMcpApp } from "./mcp-apps.js";
|
|
2
|
+
/**
|
|
3
|
+
* MCP Apps card for the email tools (generate, generation status, edit, get): progress while
|
|
4
|
+
* Migma designs or changes an email, then each email as its picture at real width, a series
|
|
5
|
+
* as tabs, "Edit in Migma" through ui/open-link, a few asks sent to the chat through
|
|
6
|
+
* ui/message, and full screen where the host has it. It only reads: migma_get_generation_status,
|
|
7
|
+
* migma_get_email_edit_status and migma_get_email. Hosts without MCP Apps read the text result.
|
|
8
|
+
*/
|
|
9
|
+
export const EMAIL_CARD_URI = "ui://migma/email";
|
|
10
|
+
/** Tool `_meta` that links an email tool to the card, when the server shows it. */
|
|
11
|
+
export function emailCardMeta(card) {
|
|
12
|
+
return mcpAppMeta(EMAIL_CARD_URI, card);
|
|
13
|
+
}
|
|
14
|
+
export function registerEmailCard(server, card) {
|
|
15
|
+
if (!card)
|
|
16
|
+
return;
|
|
17
|
+
registerMcpApp(server, {
|
|
18
|
+
name: "Email",
|
|
19
|
+
uri: EMAIL_CARD_URI,
|
|
20
|
+
description: "Progress and pictures of emails Migma designs or changes.",
|
|
21
|
+
html: EMAIL_CARD_HTML,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export const EMAIL_CARD_HTML = `<!doctype html>
|
|
25
|
+
<html lang="en">
|
|
26
|
+
<head>
|
|
27
|
+
<meta charset="utf-8">
|
|
28
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
29
|
+
<meta name="color-scheme" content="light dark">
|
|
30
|
+
<title>Email</title>
|
|
31
|
+
<style>
|
|
32
|
+
:root {
|
|
33
|
+
color-scheme: light dark;
|
|
34
|
+
--surface: var(--color-background-primary, light-dark(#ffffff, #30302e));
|
|
35
|
+
--muted: var(--color-background-secondary, light-dark(#f5f4ed, #262624));
|
|
36
|
+
--muted-2: var(--color-background-tertiary, light-dark(#ebe9df, #3a3a37));
|
|
37
|
+
--text: var(--color-text-primary, light-dark(#141413, #faf9f5));
|
|
38
|
+
--text-2: var(--color-text-secondary, light-dark(#3d3d3a, #c2c0b6));
|
|
39
|
+
--text-3: var(--color-text-tertiary, light-dark(#73726c, #9c9a92));
|
|
40
|
+
--line: var(--color-border-tertiary, light-dark(rgb(31 30 29 / 15%), rgb(222 220 209 / 15%)));
|
|
41
|
+
--line-2: var(--color-border-secondary, light-dark(rgb(31 30 29 / 30%), rgb(222 220 209 / 30%)));
|
|
42
|
+
--inverse: var(--color-background-inverse, light-dark(#141413, #faf9f5));
|
|
43
|
+
--on-inverse: var(--color-text-inverse, light-dark(#ffffff, #141413));
|
|
44
|
+
--info: var(--color-border-info, light-dark(#4682d5, #6c9be0));
|
|
45
|
+
--success: var(--color-border-success, light-dark(#437426, #7fb05b));
|
|
46
|
+
--danger: var(--color-border-danger, light-dark(#a73d39, #d1615c));
|
|
47
|
+
--danger-text: var(--color-text-danger, light-dark(#7f2c28, #ee8884));
|
|
48
|
+
--warning-text: var(--color-text-warning, light-dark(#5a4815, #d1a041));
|
|
49
|
+
--radius: var(--border-radius-lg, 10px);
|
|
50
|
+
--radius-md: var(--border-radius-md, 8px);
|
|
51
|
+
}
|
|
52
|
+
* { box-sizing: border-box; }
|
|
53
|
+
html, body { margin: 0; background: transparent; }
|
|
54
|
+
body {
|
|
55
|
+
font-family: var(--font-sans, system-ui, -apple-system, sans-serif);
|
|
56
|
+
font-size: var(--font-text-sm-size, 14px);
|
|
57
|
+
line-height: var(--font-text-sm-line-height, 1.4);
|
|
58
|
+
color: var(--text);
|
|
59
|
+
-webkit-font-smoothing: antialiased;
|
|
60
|
+
}
|
|
61
|
+
p, h1, ul { margin: 0; }
|
|
62
|
+
button { font: inherit; cursor: pointer; }
|
|
63
|
+
button:focus-visible, .stage:focus-visible { outline: 2px solid var(--color-ring-primary, var(--info)); outline-offset: 2px; }
|
|
64
|
+
button[disabled] { cursor: default; opacity: .5; }
|
|
65
|
+
main {
|
|
66
|
+
container-type: inline-size;
|
|
67
|
+
padding: calc(16px + var(--inset-top, 0px)) calc(16px + var(--inset-right, 0px)) calc(16px + var(--inset-bottom, 0px)) calc(16px + var(--inset-left, 0px));
|
|
68
|
+
}
|
|
69
|
+
.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
|
|
70
|
+
.i.big { width: 24px; height: 24px; }
|
|
71
|
+
|
|
72
|
+
.head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
|
|
73
|
+
.title { min-width: 0; }
|
|
74
|
+
h1 { font-size: var(--font-heading-md-size, 16px); line-height: var(--font-heading-md-line-height, 1.4); font-weight: var(--font-weight-semibold, 600); overflow-wrap: anywhere; }
|
|
75
|
+
.pre { color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
76
|
+
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-2); }
|
|
77
|
+
.icon-btn:hover { background: var(--muted); }
|
|
78
|
+
|
|
79
|
+
.stage { position: relative; margin-top: 12px; height: var(--stage-h, 520px); border-radius: var(--radius); background: var(--muted); overflow: auto; overscroll-behavior: contain; display: flex; justify-content: center; align-items: flex-start; padding: 16px; scrollbar-width: thin; }
|
|
80
|
+
.stage.short { height: 240px; overflow: hidden; }
|
|
81
|
+
.shot { width: min(600px, 100%); flex: none; border-radius: 4px; overflow: hidden; box-shadow: 0 0 0 0.5px var(--line); background: var(--surface); }
|
|
82
|
+
.shot img { display: block; width: 100%; height: auto; }
|
|
83
|
+
.shot.dim { opacity: .45; }
|
|
84
|
+
.skel { width: min(600px, 100%); height: 100%; min-height: 200px; flex: none; border-radius: 4px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--line); padding: 28px; display: flex; flex-direction: column; gap: 14px; overflow: hidden; }
|
|
85
|
+
.sk { background: var(--muted-2); border-radius: 6px; flex: none; }
|
|
86
|
+
.stage-note { position: absolute; inset: 0; margin: auto; height: fit-content; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px; color: var(--text-2); text-align: center; max-width: 340px; }
|
|
87
|
+
.pill { display: inline-flex; gap: 8px; align-items: center; padding: 6px 12px; border-radius: 999px; background: var(--surface); box-shadow: 0 0 0 0.5px var(--line); color: var(--text-2); }
|
|
88
|
+
|
|
89
|
+
.tabs { display: flex; gap: 4px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; }
|
|
90
|
+
.tab { display: inline-flex; gap: 8px; align-items: center; height: 36px; max-width: 220px; flex: none; padding: 0 12px 0 8px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-2); font-size: 13px; }
|
|
91
|
+
.tab .n { display: grid; place-items: center; width: 20px; height: 20px; flex: none; border-radius: 50%; background: var(--muted); font-size: 12px; font-weight: 600; }
|
|
92
|
+
.tab .t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
93
|
+
.tab .d { color: var(--text-3); flex: none; }
|
|
94
|
+
.tab[aria-selected="true"] { background: var(--muted); color: var(--text); }
|
|
95
|
+
.tab[aria-selected="true"] .n { background: var(--inverse); color: var(--on-inverse); }
|
|
96
|
+
|
|
97
|
+
.foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
|
|
98
|
+
.asks { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
99
|
+
.chip { display: inline-flex; gap: 6px; align-items: center; min-height: 32px; padding: 0 12px; border: 0.5px solid var(--line-2); border-radius: 999px; background: transparent; color: var(--text); font-size: 13px; font-weight: var(--font-weight-medium, 500); }
|
|
100
|
+
.chip:hover { background: var(--muted); }
|
|
101
|
+
.primary, .ghost { display: inline-flex; gap: 6px; align-items: center; justify-content: center; min-height: 36px; padding: 0 14px; border-radius: var(--radius-md); white-space: nowrap; font-weight: var(--font-weight-semibold, 600); }
|
|
102
|
+
.primary { border: 0; background: var(--inverse); color: var(--on-inverse); margin-left: auto; }
|
|
103
|
+
.ghost { border: 0.5px solid var(--line-2); background: transparent; color: var(--text); font-weight: var(--font-weight-medium, 500); margin-left: auto; }
|
|
104
|
+
.ghost:hover { background: var(--muted); }
|
|
105
|
+
@container (max-width: 420px) { .foot .primary, .foot .ghost { width: 100%; } }
|
|
106
|
+
|
|
107
|
+
.status { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; color: var(--text-2); font-weight: var(--font-weight-medium, 500); }
|
|
108
|
+
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-3); }
|
|
109
|
+
.dot.info { background: var(--info); } .dot.ok { background: var(--success); } .dot.bad { background: var(--danger); }
|
|
110
|
+
.time { margin-left: auto; color: var(--text-3); font-variant-numeric: tabular-nums; font-weight: 400; }
|
|
111
|
+
.steps { list-style: none; padding: 0; margin-top: 12px; display: grid; gap: 6px; }
|
|
112
|
+
.steps li { display: flex; gap: 8px; align-items: center; color: var(--text-3); min-width: 0; }
|
|
113
|
+
.steps li span:nth-child(2) { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
114
|
+
.steps li.now { color: var(--text); }
|
|
115
|
+
.mark { display: grid; place-items: center; width: 16px; height: 16px; flex: none; }
|
|
116
|
+
.ring { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--line-2); }
|
|
117
|
+
.now .ring { border-color: var(--info); background: var(--info); }
|
|
118
|
+
.note { margin-top: 12px; color: var(--text-2); overflow-wrap: anywhere; }
|
|
119
|
+
.note.bad { color: var(--danger-text); }
|
|
120
|
+
.note.warn { margin-top: 4px; color: var(--warning-text); }
|
|
121
|
+
.note.small { color: var(--text-3); font-size: 13px; }
|
|
122
|
+
|
|
123
|
+
.slots { display: flex; gap: 12px; margin-top: 12px; overflow-x: auto; }
|
|
124
|
+
.slot { flex: 1 0 72px; min-width: 0; max-width: 200px; display: flex; flex-direction: column; gap: 8px; }
|
|
125
|
+
.slot .frame { aspect-ratio: 3 / 4; border-radius: var(--radius-md); background: var(--muted); display: grid; place-items: center; color: var(--text-3); }
|
|
126
|
+
.slot.done .frame { color: var(--success); }
|
|
127
|
+
.slot .lab { display: flex; flex-wrap: wrap; column-gap: 6px; color: var(--text-2); font-size: 13px; }
|
|
128
|
+
.slot .lab span:last-child { color: var(--text-3); margin-left: auto; }
|
|
129
|
+
|
|
130
|
+
.line { display: flex; gap: 8px; align-items: center; min-height: 28px; color: var(--text-2); min-width: 0; }
|
|
131
|
+
.line .t { color: var(--text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
|
|
132
|
+
.line .s { color: var(--text-3); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
|
|
133
|
+
.line .thumb { width: 40px; height: 40px; flex: none; border-radius: 6px; overflow: hidden; box-shadow: 0 0 0 0.5px var(--line); background: var(--muted); }
|
|
134
|
+
.line .thumb img { display: block; width: 100%; }
|
|
135
|
+
.line .ghost, .line .primary { min-height: 30px; padding: 0 10px; font-size: 13px; margin-left: 0; }
|
|
136
|
+
.line .ghost:first-of-type { margin-left: auto; }
|
|
137
|
+
@container (max-width: 420px) { .line { flex-wrap: wrap; } .line .ghost:first-of-type { margin-left: 48px; } }
|
|
138
|
+
|
|
139
|
+
:root:has(.fs), :root:has(.fs) body { height: 100%; }
|
|
140
|
+
main:has(.fs) { height: 100%; padding: 0; }
|
|
141
|
+
.fs { height: 100%; display: flex; flex-direction: column; }
|
|
142
|
+
.fs > .head { padding: calc(14px + var(--inset-top, 0px)) calc(20px + var(--inset-right, 0px)) 14px calc(20px + var(--inset-left, 0px)); border-bottom: 0.5px solid var(--line); }
|
|
143
|
+
.fs-body { flex: 1; display: flex; min-height: 0; }
|
|
144
|
+
.rail { width: 200px; flex: none; padding: 16px; display: flex; flex-direction: column; gap: 12px; border-right: 0.5px solid var(--line); overflow-y: auto; }
|
|
145
|
+
.rail-item { display: flex; flex-direction: column; gap: 6px; padding: 6px; border-radius: var(--radius); border: 0; background: transparent; text-align: left; color: var(--text-2); font-size: 13px; }
|
|
146
|
+
.rail-item .thumb { height: 140px; border-radius: 6px; overflow: hidden; box-shadow: 0 0 0 0.5px var(--line); background: var(--muted); display: grid; place-items: center; color: var(--text-3); }
|
|
147
|
+
.rail-item .thumb img { display: block; width: 100%; align-self: start; }
|
|
148
|
+
.rail-item[aria-current="true"] { background: var(--muted); color: var(--text); }
|
|
149
|
+
.fs .stage { flex: 1; height: auto; margin: 0; border-radius: 0; padding: 24px; }
|
|
150
|
+
.fs .foot { margin: 0; padding: 12px calc(20px + var(--inset-right, 0px)) calc(12px + var(--inset-bottom, 0px)) calc(20px + var(--inset-left, 0px)); border-top: 0.5px solid var(--line); }
|
|
151
|
+
.fs .note { margin: 0; padding: 0 20px 12px; }
|
|
152
|
+
.step-btn { position: absolute; top: 50%; margin-top: -18px; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 0.5px solid var(--line); background: var(--surface); color: var(--text); }
|
|
153
|
+
.step-btn.prev { left: 16px; } .step-btn.next { right: 16px; }
|
|
154
|
+
.fs-wrap { flex: 1; position: relative; display: flex; min-width: 0; }
|
|
155
|
+
.fs .tabs { display: none; margin: 0; padding: 8px calc(20px + var(--inset-right, 0px)) 8px calc(20px + var(--inset-left, 0px)); border-bottom: 0.5px solid var(--line); }
|
|
156
|
+
/* Narrow full screen (Claude's side panel): tabs replace the rail and the arrows over the email. */
|
|
157
|
+
@container (max-width: 720px) { .rail, .step-btn { display: none; } .fs .tabs { display: flex; } }
|
|
158
|
+
|
|
159
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
160
|
+
.sk, .now .ring { animation: pulse 1.4s ease-in-out infinite; }
|
|
161
|
+
@keyframes pulse { 50% { opacity: .55; } }
|
|
162
|
+
}
|
|
163
|
+
</style>
|
|
164
|
+
</head>
|
|
165
|
+
<body>
|
|
166
|
+
<main id="card" aria-busy="true">
|
|
167
|
+
<div class="sk" style="height:16px;width:40%"></div>
|
|
168
|
+
<div class="sk" style="height:12px;width:70%;margin-top:8px"></div>
|
|
169
|
+
<div class="stage short"></div>
|
|
170
|
+
</main>
|
|
171
|
+
<script type="module">
|
|
172
|
+
const ICON = {
|
|
173
|
+
expand: '<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/>',
|
|
174
|
+
collapse: '<path d="M4 14h6v6M20 10h-6V4M14 10l7-7M3 21l7-7"/>',
|
|
175
|
+
out: '<path d="M7 17L17 7M8 7h9v9"/>',
|
|
176
|
+
check: '<path d="M5 12l5 5L20 7"/>',
|
|
177
|
+
prev: '<path d="M15 18l-6-6 6-6"/>',
|
|
178
|
+
next: '<path d="M9 18l6-6-6-6"/>',
|
|
179
|
+
image: '<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="M21 15l-5-5L5 21"/>',
|
|
180
|
+
alert: '<circle cx="12" cy="12" r="9"/><path d="M12 8v4M12 16h.01"/>',
|
|
181
|
+
};
|
|
182
|
+
const EDIT_STEPS = [["Checking the email", ["queued", "checking"]], ["Changing it", ["editing"]], ["Saving", ["saved"]]];
|
|
183
|
+
const PICTURE_TRIES = 4;
|
|
184
|
+
const $ = (id) => document.getElementById(id);
|
|
185
|
+
const el = (tag, text, attrs = {}) => Object.assign(document.createElement(tag), { textContent: text ?? "" }, attrs);
|
|
186
|
+
function icon(name, big) {
|
|
187
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
188
|
+
svg.setAttribute("class", big ? "i big" : "i");
|
|
189
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
190
|
+
svg.setAttribute("aria-hidden", "true");
|
|
191
|
+
svg.innerHTML = ICON[name];
|
|
192
|
+
return svg;
|
|
193
|
+
}
|
|
194
|
+
function button(className, label, onclick, attrs = {}) {
|
|
195
|
+
const b = el("button", label, { type: "button", className, ...attrs });
|
|
196
|
+
b.addEventListener("click", onclick);
|
|
197
|
+
return b;
|
|
198
|
+
}
|
|
199
|
+
const https = (url) => (typeof url === "string" && url.startsWith("https://") ? url : "");
|
|
200
|
+
|
|
201
|
+
let host = {}, caps = {}, input = {}, s = null, sel = 0, nextId = 1, timer = 0, ticker = 0, delay = 3000, tries = 0, busy = false;
|
|
202
|
+
const pending = new Map();
|
|
203
|
+
|
|
204
|
+
function send(msg) { window.parent.postMessage({ jsonrpc: "2.0", ...msg }, "*"); }
|
|
205
|
+
function request(method, params, ms) {
|
|
206
|
+
const id = nextId++;
|
|
207
|
+
send({ id, method, params });
|
|
208
|
+
return new Promise((resolve, reject) => {
|
|
209
|
+
pending.set(id, { resolve, reject });
|
|
210
|
+
// A host that never answers must not stall the card's reads.
|
|
211
|
+
if (ms) setTimeout(() => pending.delete(id) && reject(new Error("timeout")), ms);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
window.addEventListener("message", (event) => {
|
|
216
|
+
if (event.source !== window.parent) return;
|
|
217
|
+
const msg = event.data;
|
|
218
|
+
if (!msg || msg.jsonrpc !== "2.0") return;
|
|
219
|
+
if (msg.id !== undefined && !msg.method) {
|
|
220
|
+
const waiter = pending.get(msg.id);
|
|
221
|
+
pending.delete(msg.id);
|
|
222
|
+
if (waiter) msg.error ? waiter.reject(msg.error) : waiter.resolve(msg.result);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (msg.id !== undefined) {
|
|
226
|
+
// Host requests (ping, teardown) need an answer; this card holds no state to save.
|
|
227
|
+
send({ id: msg.id, result: {} });
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (msg.method === "ui/notifications/tool-input") input = msg.params?.arguments ?? {};
|
|
231
|
+
if (msg.method === "ui/notifications/tool-result") onResult(msg.params);
|
|
232
|
+
if (msg.method === "ui/notifications/host-context-changed") { applyHost(msg.params); if (s) render(); }
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
function applyHost(ctx = {}) {
|
|
236
|
+
host = { ...host, ...ctx };
|
|
237
|
+
const root = document.documentElement;
|
|
238
|
+
if (ctx.theme) { root.dataset.theme = ctx.theme; root.style.colorScheme = ctx.theme; }
|
|
239
|
+
for (const [key, value] of Object.entries(ctx.styles?.variables ?? {})) if (value) root.style.setProperty(key, value);
|
|
240
|
+
if (ctx.styles?.css?.fonts && !$("host-fonts")) document.head.append(el("style", ctx.styles.css.fonts, { id: "host-fonts" }));
|
|
241
|
+
const inset = ctx.safeAreaInsets;
|
|
242
|
+
if (inset) for (const side of ["top", "right", "bottom", "left"]) root.style.setProperty("--inset-" + side, (inset[side] || 0) + "px");
|
|
243
|
+
root.dataset.mode = host.displayMode || "inline";
|
|
244
|
+
// Inline, the email scrolls inside the card; keep the card within the height the host allows.
|
|
245
|
+
const max = host.containerDimensions?.maxHeight;
|
|
246
|
+
root.style.setProperty("--stage-h", (max ? Math.max(240, Math.min(520, max - 200)) : innerWidth < 480 ? 420 : 520) + "px");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Each tool puts its JSON in one text item among others (a lead sentence, guidance, the Previews list).
|
|
250
|
+
const texts = (result) => (result?.content ?? []).filter((c) => c.type === "text").map((c) => c.text);
|
|
251
|
+
function json(result) {
|
|
252
|
+
for (const text of texts(result)) {
|
|
253
|
+
try { const value = JSON.parse(text); if (value && typeof value === "object" && !Array.isArray(value)) return value; } catch {}
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
function toEmail(e = {}, link = "") {
|
|
258
|
+
return {
|
|
259
|
+
emailId: e.emailId || e.id || "",
|
|
260
|
+
subject: e.subject || "",
|
|
261
|
+
preheader: e.preheader || e.previewText || "",
|
|
262
|
+
picture: https(e.screenshotFullUrl) || https(e.screenshotUrl) || https(e.thumbnailUrl),
|
|
263
|
+
appUrl: https(e.appUrl) || link,
|
|
264
|
+
failed: e.status === "failed",
|
|
265
|
+
day: typeof e.sendOffsetDays === "number" ? e.sendOffsetDays : null,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function onResult(result) {
|
|
270
|
+
clearTimeout(timer);
|
|
271
|
+
sel = 0; tries = 0;
|
|
272
|
+
const data = json(result);
|
|
273
|
+
if (result?.isError || !data || (data.error && !data.conversationId && !data.editId)) {
|
|
274
|
+
const mode = input.emailId && input.prompt ? "edit" : input.prompt ? "create" : "email";
|
|
275
|
+
// Refused before anything started (no credits, a locked email): trying again would only repeat it.
|
|
276
|
+
s = { mode, phase: "failed", refused: true, emailId: input.emailId, count: input.count, error: (typeof data?.error === "string" && data.error) || (!data && texts(result)[0]) || "Migma could not do this." };
|
|
277
|
+
render();
|
|
278
|
+
if (mode === "edit") readBefore();
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (data.editId) {
|
|
282
|
+
s = { mode: "edit", phase: "working", emailId: data.emailId, editId: data.editId, appUrl: https(data.appUrl), createdAt: data.createdAt, stage: data.stage };
|
|
283
|
+
delay = data.pollAfterMs || 2000;
|
|
284
|
+
render();
|
|
285
|
+
readBefore();
|
|
286
|
+
poll();
|
|
287
|
+
} else if (data.emailId && "subject" in data) {
|
|
288
|
+
s = { mode: "email", phase: "ready", emails: [toEmail(data)] };
|
|
289
|
+
render();
|
|
290
|
+
if (missingPicture()) retryPicture();
|
|
291
|
+
} else if (data.conversationId) {
|
|
292
|
+
// A status check draws one line that turns into a Ready row, which opens in place. It keeps
|
|
293
|
+
// itself current: ChatGPT shows only the last card of a reply, so the generate call's card may
|
|
294
|
+
// never be seen.
|
|
295
|
+
s = { mode: "create", phase: "working", compact: !!data.createdAt && !input.prompt, conversationId: data.conversationId, appUrl: https(data.appUrl), count: data.count || input.count };
|
|
296
|
+
applyStatus(data);
|
|
297
|
+
// Slower than the full card: several status lines can poll at once, and hosted MCP allows 100 calls a minute.
|
|
298
|
+
delay = s.compact ? 6000 : 3000;
|
|
299
|
+
render();
|
|
300
|
+
poll();
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function applyStatus(d) {
|
|
305
|
+
if (d.createdAt) s.createdAt = d.createdAt;
|
|
306
|
+
if (d.status === "failed") { s.phase = "failed"; s.error = d.error || "Migma could not create this email."; return; }
|
|
307
|
+
if (d.status === "completed") {
|
|
308
|
+
const r = d.result || {};
|
|
309
|
+
const rows = Array.isArray(r.emails) && r.emails.length ? r.emails : [r];
|
|
310
|
+
s.emails = rows.map((e) => toEmail(e, s.appUrl));
|
|
311
|
+
s.phase = "ready";
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const p = d.progress || {};
|
|
315
|
+
const events = Array.isArray(p.events) ? p.events.filter((e) => e?.label) : [];
|
|
316
|
+
const done = [...new Set(events.filter((e) => e.status === "complete").map((e) => e.label))];
|
|
317
|
+
const live = p.now?.label && (p.now.status === "start" || p.now.status === "progress") ? p.now.label : "";
|
|
318
|
+
s.now = live || events.filter((e) => e.status === "processing").pop()?.label || s.now || "";
|
|
319
|
+
s.steps = done.filter((label) => label !== s.now).slice(-3);
|
|
320
|
+
if (Array.isArray(p.slots) && p.slots.length) s.slots = p.slots;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function applyEdit(d) {
|
|
324
|
+
if (d.createdAt) s.createdAt = d.createdAt;
|
|
325
|
+
s.stage = d.stage || s.stage;
|
|
326
|
+
if (d.status === "completed") {
|
|
327
|
+
s.mode = "email"; s.phase = "ready";
|
|
328
|
+
s.emails = [unchanged(toEmail(d.result || { emailId: s.emailId, subject: s.before?.subject }, s.before?.appUrl || s.appUrl), s.before?.picture)];
|
|
329
|
+
} else if (d.status === "failed") {
|
|
330
|
+
s.phase = "failed"; s.error = d.error || "Migma could not change this email."; s.mayHaveSaved = !!d.changesMayHaveBeenSaved;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Right after a change the email can still carry its old picture until Migma captures the new
|
|
335
|
+
// one: wait for a different picture, and show the old one only once the retries run out.
|
|
336
|
+
function unchanged(e, old) {
|
|
337
|
+
if (e.picture && e.picture === old) { e.stale = e.picture; e.picture = ""; }
|
|
338
|
+
return e;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Tried even when the host does not list serverTools or openLinks: a refusal falls back.
|
|
342
|
+
async function read(name, args) {
|
|
343
|
+
try {
|
|
344
|
+
const result = await request("tools/call", { name, arguments: args }, 30000);
|
|
345
|
+
return result?.isError ? null : json(result);
|
|
346
|
+
} catch { return null; }
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function readBefore() {
|
|
350
|
+
if (!s?.emailId) return;
|
|
351
|
+
const d = await read("migma_get_email", { emailId: s.emailId });
|
|
352
|
+
if (d?.emailId && s.mode !== "email") { s.before = toEmail(d); render(); }
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async function poll() {
|
|
356
|
+
clearTimeout(timer);
|
|
357
|
+
if (!s || s.phase !== "working" || busy || document.visibilityState !== "visible") return;
|
|
358
|
+
busy = true;
|
|
359
|
+
if (s.mode === "create") {
|
|
360
|
+
const d = await read("migma_get_generation_status", { conversationId: s.conversationId });
|
|
361
|
+
if (d?.conversationId) applyStatus(d);
|
|
362
|
+
} else {
|
|
363
|
+
const d = await read("migma_get_email_edit_status", { emailId: s.emailId, editId: s.editId });
|
|
364
|
+
if (d?.status) applyEdit(d);
|
|
365
|
+
}
|
|
366
|
+
busy = false;
|
|
367
|
+
render();
|
|
368
|
+
if (s.phase === "working") {
|
|
369
|
+
// ponytail: backoff to one read every 15 s; a push from Migma would replace polling if hosts add it.
|
|
370
|
+
timer = setTimeout(poll, delay);
|
|
371
|
+
delay = Math.min(delay * 1.4, 15000);
|
|
372
|
+
} else if (missingPicture()) retryPicture();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const missingPicture = () => s?.phase === "ready" && s.emails.some((e) => !e.failed && !e.picture);
|
|
376
|
+
// The picture is captured after the email is saved. Each read returns every picture of the
|
|
377
|
+
// run, so try a few times, further apart, then say it is ready in Migma.
|
|
378
|
+
function retryPicture() {
|
|
379
|
+
clearTimeout(timer);
|
|
380
|
+
if (tries >= PICTURE_TRIES) {
|
|
381
|
+
for (const e of s.emails) if (!e.picture && e.stale) e.picture = e.stale;
|
|
382
|
+
s.noPicture = true;
|
|
383
|
+
return render();
|
|
384
|
+
}
|
|
385
|
+
timer = setTimeout(async () => {
|
|
386
|
+
tries++;
|
|
387
|
+
if (s.mode === "create") {
|
|
388
|
+
const d = await read("migma_get_generation_status", { conversationId: s.conversationId });
|
|
389
|
+
if (d?.status === "completed") applyStatus(d);
|
|
390
|
+
} else {
|
|
391
|
+
const d = await read("migma_get_email", { emailId: s.emails[0].emailId });
|
|
392
|
+
if (d?.emailId) s.emails = [unchanged(toEmail(d, s.emails[0].appUrl), s.emails[0].stale)];
|
|
393
|
+
}
|
|
394
|
+
render();
|
|
395
|
+
if (missingPicture()) retryPicture();
|
|
396
|
+
}, 4000 * 2 ** tries);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function refreshSoon() { if (s?.phase === "working") { delay = 3000; poll(); } }
|
|
400
|
+
document.addEventListener("visibilitychange", () => document.visibilityState === "visible" && refreshSoon());
|
|
401
|
+
window.addEventListener("focus", refreshSoon);
|
|
402
|
+
|
|
403
|
+
function elapsed() {
|
|
404
|
+
const start = Date.parse(s.createdAt);
|
|
405
|
+
if (!start) return "";
|
|
406
|
+
const secs = Math.max(0, Math.round((Date.now() - start) / 1000));
|
|
407
|
+
return Math.floor(secs / 60) + ":" + String(secs % 60).padStart(2, "0");
|
|
408
|
+
}
|
|
409
|
+
function tick() {
|
|
410
|
+
clearInterval(ticker);
|
|
411
|
+
if (s.phase !== "working" || !s.createdAt) return;
|
|
412
|
+
ticker = setInterval(() => document.querySelectorAll(".time").forEach((t) => { t.textContent = elapsed(); }), 1000);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// ---- actions ----
|
|
416
|
+
async function openLink(url) {
|
|
417
|
+
if (!url) return;
|
|
418
|
+
try { const r = await request("ui/open-link", { url }); if (!r?.isError) return; } catch {}
|
|
419
|
+
s.note = "Could not open the link. Copy it: " + url;
|
|
420
|
+
render();
|
|
421
|
+
}
|
|
422
|
+
async function ask(text) {
|
|
423
|
+
try {
|
|
424
|
+
const r = await request("ui/message", { role: "user", content: [{ type: "text", text }] });
|
|
425
|
+
if (r?.isError) throw new Error();
|
|
426
|
+
} catch {
|
|
427
|
+
s.note = "Could not send that to the chat. Type it there instead.";
|
|
428
|
+
render();
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
async function displayMode(mode) {
|
|
432
|
+
try { const r = await request("ui/request-display-mode", { mode }); applyHost({ displayMode: r?.mode || host.displayMode }); } catch {}
|
|
433
|
+
render();
|
|
434
|
+
}
|
|
435
|
+
const canFullScreen = () => (host.availableDisplayModes || []).includes("fullscreen");
|
|
436
|
+
const fullScreen = () => host.displayMode === "fullscreen" && s.phase === "ready" && !s.compact;
|
|
437
|
+
function select(i) {
|
|
438
|
+
sel = Math.max(0, Math.min(s.emails.length - 1, i));
|
|
439
|
+
render();
|
|
440
|
+
document.querySelector('[aria-selected="true"], [aria-current="true"]')?.focus();
|
|
441
|
+
}
|
|
442
|
+
document.addEventListener("keydown", (event) => {
|
|
443
|
+
if (!s || !fullScreen() || s.emails.length < 2 || event.target.closest?.('[role="tab"]')) return;
|
|
444
|
+
if (event.key === "ArrowLeft") select(sel - 1);
|
|
445
|
+
if (event.key === "ArrowRight") select(sel + 1);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// ---- pieces ----
|
|
449
|
+
const series = () => s.emails.length > 1;
|
|
450
|
+
const quoted = (e) => (e.subject ? "“" + e.subject + "”" : "this email");
|
|
451
|
+
const named = (e, i) => (series() ? "email " + (i + 1) + " of the series, " + quoted(e) + "," : quoted(e));
|
|
452
|
+
const chip = (label, text) => button("chip", label, () => ask(text));
|
|
453
|
+
function asks(list) {
|
|
454
|
+
const box = el("div", "", { className: "asks" });
|
|
455
|
+
if (caps.message) box.append(...list.map(([label, text]) => chip(label, text)));
|
|
456
|
+
return box;
|
|
457
|
+
}
|
|
458
|
+
function linkButton(url, primary) {
|
|
459
|
+
if (!url) return el("span", "");
|
|
460
|
+
const b = button(primary ? "primary" : "ghost", primary ? "Edit in Migma" : "Open in Migma", () => openLink(url));
|
|
461
|
+
b.append(icon("out"));
|
|
462
|
+
return b;
|
|
463
|
+
}
|
|
464
|
+
function foot(list, url, primary) {
|
|
465
|
+
const f = el("div", "", { className: "foot" });
|
|
466
|
+
f.append(asks(list), linkButton(url, primary));
|
|
467
|
+
return f;
|
|
468
|
+
}
|
|
469
|
+
function head(title, pre, tools = []) {
|
|
470
|
+
const h = el("div", "", { className: "head" });
|
|
471
|
+
const t = el("div", "", { className: "title" });
|
|
472
|
+
t.append(el("h1", title));
|
|
473
|
+
if (pre) t.append(el("p", pre, { className: "pre", title: pre }));
|
|
474
|
+
h.append(t);
|
|
475
|
+
if (tools.length) { const box = el("div", "", { className: "tools" }); box.append(...tools); h.append(box); }
|
|
476
|
+
return h;
|
|
477
|
+
}
|
|
478
|
+
function statusLine(label, tone) {
|
|
479
|
+
const p = el("p", "", { className: "status" });
|
|
480
|
+
p.append(el("span", "", { className: "dot " + tone }), el("span", label));
|
|
481
|
+
return p;
|
|
482
|
+
}
|
|
483
|
+
function steps(items) {
|
|
484
|
+
const ul = el("ul", "", { className: "steps" });
|
|
485
|
+
ul.setAttribute("aria-live", "polite");
|
|
486
|
+
for (const [label, state] of items) {
|
|
487
|
+
const li = el("li", "", { className: state });
|
|
488
|
+
const mark = el("span", "", { className: "mark" });
|
|
489
|
+
mark.append(state === "done" ? icon("check") : el("span", "", { className: "ring" }));
|
|
490
|
+
li.append(mark, el("span", label));
|
|
491
|
+
if (state === "now") li.append(el("span", elapsed(), { className: "time" }));
|
|
492
|
+
ul.append(li);
|
|
493
|
+
}
|
|
494
|
+
return ul;
|
|
495
|
+
}
|
|
496
|
+
function skeleton() {
|
|
497
|
+
const box = el("div", "", { className: "skel" });
|
|
498
|
+
for (const [h, w, m] of [[14, 30, 0], [56, 85, 16], [56, 60, 0], [200, 100, 8]]) {
|
|
499
|
+
box.append(el("div", "", { className: "sk", style: "height:" + h + "px;width:" + w + "%;margin-top:" + m + "px" }));
|
|
500
|
+
}
|
|
501
|
+
return box;
|
|
502
|
+
}
|
|
503
|
+
function picture(e, dim) {
|
|
504
|
+
const shot = el("div", "", { className: dim ? "shot dim" : "shot" });
|
|
505
|
+
const img = el("img", "", { alt: (e.subject || "Email") + (dim ? ", before the change" : "") });
|
|
506
|
+
img.addEventListener("error", () => { e.picture = ""; render(); if (missingPicture()) retryPicture(); }, { once: true });
|
|
507
|
+
img.src = e.picture;
|
|
508
|
+
shot.append(img);
|
|
509
|
+
return shot;
|
|
510
|
+
}
|
|
511
|
+
function stageNote(iconName, text) {
|
|
512
|
+
const note = el("div", "", { className: "stage-note" });
|
|
513
|
+
note.append(icon(iconName, true), el("p", text));
|
|
514
|
+
return note;
|
|
515
|
+
}
|
|
516
|
+
function stage(e, opts = {}) {
|
|
517
|
+
const box = el("div", "", { className: opts.short ? "stage short" : "stage" });
|
|
518
|
+
if (e?.failed) {
|
|
519
|
+
const ready = s.emails.filter((x) => !x.failed).length;
|
|
520
|
+
box.append(stageNote("alert", "Migma could not create this email." + (ready ? " The other " + (ready === 1 ? "one is" : ready + " are") + " ready." : "")));
|
|
521
|
+
} else if (e?.picture) {
|
|
522
|
+
box.append(picture(e, opts.dim));
|
|
523
|
+
box.tabIndex = 0;
|
|
524
|
+
box.setAttribute("aria-label", (e.subject || "Email") + ", scroll to read");
|
|
525
|
+
} else if (opts.short || !s.noPicture || !e) {
|
|
526
|
+
box.append(skeleton());
|
|
527
|
+
if (e && !opts.short) {
|
|
528
|
+
const note = el("p", "", { className: "stage-note", role: "status" });
|
|
529
|
+
const pill = el("span", "", { className: "pill" });
|
|
530
|
+
pill.append(el("span", "", { className: "dot info" }), el("span", "Preparing the picture"));
|
|
531
|
+
note.append(pill);
|
|
532
|
+
box.append(note);
|
|
533
|
+
}
|
|
534
|
+
} else {
|
|
535
|
+
box.append(stageNote("image", "No picture of this email yet. It is ready in Migma."));
|
|
536
|
+
}
|
|
537
|
+
return box;
|
|
538
|
+
}
|
|
539
|
+
function tabs() {
|
|
540
|
+
const list = el("div", "", { className: "tabs", role: "tablist" });
|
|
541
|
+
list.setAttribute("aria-label", "Emails in this series");
|
|
542
|
+
s.emails.forEach((e, i) => {
|
|
543
|
+
const tab = button("tab", "", () => select(i), { role: "tab" });
|
|
544
|
+
tab.setAttribute("aria-selected", String(i === sel));
|
|
545
|
+
tab.tabIndex = i === sel ? 0 : -1;
|
|
546
|
+
tab.append(el("span", String(i + 1), { className: "n" }), el("span", e.failed ? "Not created" : e.subject || "Email " + (i + 1), { className: "t" }));
|
|
547
|
+
if (e.failed) tab.append(el("span", "", { className: "dot bad" }));
|
|
548
|
+
else if (e.day !== null) tab.append(el("span", "Day " + e.day, { className: "d" }));
|
|
549
|
+
tab.addEventListener("keydown", (event) => {
|
|
550
|
+
if (event.key === "ArrowLeft") select(i - 1);
|
|
551
|
+
if (event.key === "ArrowRight") select(i + 1);
|
|
552
|
+
});
|
|
553
|
+
list.append(tab);
|
|
554
|
+
});
|
|
555
|
+
return list;
|
|
556
|
+
}
|
|
557
|
+
function readyAsks(e, i) {
|
|
558
|
+
if (e.failed) return [["Try this email again", "Try creating email " + (i + 1) + " of the series again."]];
|
|
559
|
+
return [
|
|
560
|
+
["Make it shorter", "Make " + named(e, i) + " shorter."],
|
|
561
|
+
["Try another version", "Make another version of " + named(e, i).replace(/,$/, "") + "."],
|
|
562
|
+
];
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// ---- views ----
|
|
566
|
+
function compactView() {
|
|
567
|
+
const line = el("div", "", { className: "line", role: "status" });
|
|
568
|
+
const many = (s.count || s.slots?.length || s.emails?.length || 1) > 1;
|
|
569
|
+
if (s.phase === "working") {
|
|
570
|
+
line.append(el("span", "", { className: "dot info" }), el("span", many ? "Designing " + (s.count || s.slots.length) + " emails" : "Designing your email", { className: "t" }));
|
|
571
|
+
if (s.now) line.append(el("span", s.now, { className: "s" }));
|
|
572
|
+
line.append(el("span", elapsed(), { className: "time" }));
|
|
573
|
+
} else if (s.phase === "failed") {
|
|
574
|
+
line.append(el("span", "", { className: "dot bad" }), el("span", "Not created", { className: "t" }), el("span", s.error, { className: "s" }));
|
|
575
|
+
} else {
|
|
576
|
+
const first = s.emails.find((e) => e.picture);
|
|
577
|
+
const thumb = el("span", "", { className: "thumb" });
|
|
578
|
+
if (first) thumb.append(el("img", "", { src: first.picture, alt: "" }));
|
|
579
|
+
line.append(thumb, el("span", many ? s.emails.length + " emails" : s.emails[0].subject || "Your email", { className: "t" }), el("span", "Ready", { className: "s" }));
|
|
580
|
+
const show = button("ghost", "Show", () => { s.compact = false; render(); if (missingPicture()) retryPicture(); });
|
|
581
|
+
show.setAttribute("aria-expanded", "false");
|
|
582
|
+
line.append(show, linkButton(s.emails[0].appUrl || s.appUrl, true));
|
|
583
|
+
}
|
|
584
|
+
return [line];
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function workingView() {
|
|
588
|
+
if (s.mode === "edit") {
|
|
589
|
+
const at = Math.max(0, EDIT_STEPS.findIndex(([, stages]) => stages.includes(s.stage)));
|
|
590
|
+
return [
|
|
591
|
+
head(s.before?.subject || "Changing your email", input.prompt),
|
|
592
|
+
steps(EDIT_STEPS.map(([label], i) => [label, i < at ? "done" : i === at ? "now" : "todo"])),
|
|
593
|
+
s.before?.picture ? stage(s.before, { dim: true }) : stage(null, { short: true }),
|
|
594
|
+
foot([], s.before?.appUrl || s.appUrl, false),
|
|
595
|
+
];
|
|
596
|
+
}
|
|
597
|
+
const count = s.count || s.slots?.length || 1;
|
|
598
|
+
const parts = [
|
|
599
|
+
head(count > 1 ? "Designing " + count + " emails" : "Designing your email", input.prompt),
|
|
600
|
+
steps([...(s.steps || []).map((label) => [label, "done"]), [s.now || "Starting", "now"]]),
|
|
601
|
+
];
|
|
602
|
+
if (count > 1) {
|
|
603
|
+
const slots = el("div", "", { className: "slots" });
|
|
604
|
+
for (let i = 0; i < count; i++) {
|
|
605
|
+
const done = s.slots?.[i] && !s.slots[i].pending;
|
|
606
|
+
const slot = el("div", "", { className: done ? "slot done" : "slot" });
|
|
607
|
+
const frame = el("div", "", { className: "frame" });
|
|
608
|
+
frame.append(done ? icon("check", true) : el("span", "", { className: "dot info" }));
|
|
609
|
+
const lab = el("div", "", { className: "lab" });
|
|
610
|
+
lab.append(el("span", "Email " + (i + 1)), el("span", done ? "Done" : "Designing"));
|
|
611
|
+
slot.append(frame, lab);
|
|
612
|
+
slots.append(slot);
|
|
613
|
+
}
|
|
614
|
+
parts.push(slots);
|
|
615
|
+
} else {
|
|
616
|
+
parts.push(stage(null, { short: true }));
|
|
617
|
+
}
|
|
618
|
+
parts.push(foot([], s.appUrl, false));
|
|
619
|
+
return parts;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function failedView() {
|
|
623
|
+
if (s.mode === "edit") {
|
|
624
|
+
const e = s.before;
|
|
625
|
+
const parts = [statusLine("Not changed", "bad"), head(e?.subject || "Your email", input.prompt), el("p", s.error, { className: "note bad" })];
|
|
626
|
+
if (s.mayHaveSaved) parts.push(el("p", "Some changes may have been saved. Check the email in Migma before you try again.", { className: "note warn" }));
|
|
627
|
+
if (e?.picture) parts.push(stage(e));
|
|
628
|
+
parts.push(foot(input.prompt && !s.refused ? [["Try again", "Try that change to " + (e ? quoted(e) : "the email") + " again."]] : [], e?.appUrl || s.appUrl, true));
|
|
629
|
+
return parts;
|
|
630
|
+
}
|
|
631
|
+
if (s.mode === "email") return [statusLine("Could not show this email", "bad"), el("p", s.error, { className: "note bad" })];
|
|
632
|
+
const many = (s.count || 1) > 1;
|
|
633
|
+
return [
|
|
634
|
+
statusLine("Not created", "bad"),
|
|
635
|
+
head(many ? "Your emails" : "Your email", input.prompt),
|
|
636
|
+
el("p", s.error, { className: "note bad" }),
|
|
637
|
+
foot(input.prompt && !s.refused ? [["Try again", many ? "Try creating those emails again." : "Try creating that email again."]] : [], s.appUrl, false),
|
|
638
|
+
];
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function readyView() {
|
|
642
|
+
const e = s.emails[sel];
|
|
643
|
+
const full = canFullScreen() ? [button("icon-btn", "", () => displayMode("fullscreen"), { ariaLabel: "Full screen" })] : [];
|
|
644
|
+
full[0]?.append(icon("expand"));
|
|
645
|
+
const title = e.failed ? "Email " + (sel + 1) + " was not created" : e.subject || "Your email";
|
|
646
|
+
const parts = [head(title, e.failed ? "" : e.preheader, full)];
|
|
647
|
+
if (series()) parts.push(tabs());
|
|
648
|
+
parts.push(stage(e), foot(readyAsks(e, sel), e.appUrl || s.appUrl, true));
|
|
649
|
+
return parts;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function fullScreenView() {
|
|
653
|
+
const e = s.emails[sel];
|
|
654
|
+
const back = button("icon-btn", "", () => displayMode("inline"), { ariaLabel: "Back to the chat" });
|
|
655
|
+
back.append(icon("collapse"));
|
|
656
|
+
const box = el("section", "", { className: "fs" });
|
|
657
|
+
const body = el("div", "", { className: "fs-body" });
|
|
658
|
+
if (series()) {
|
|
659
|
+
const rail = el("nav", "", { className: "rail" });
|
|
660
|
+
rail.setAttribute("aria-label", "Emails in this series");
|
|
661
|
+
s.emails.forEach((x, i) => {
|
|
662
|
+
const item = button("rail-item", "", () => select(i));
|
|
663
|
+
if (i === sel) item.setAttribute("aria-current", "true");
|
|
664
|
+
const thumb = el("div", "", { className: "thumb" });
|
|
665
|
+
thumb.append(x.picture ? el("img", "", { src: x.picture, alt: "" }) : icon(x.failed ? "alert" : "image", true));
|
|
666
|
+
item.append(thumb, el("span", (i + 1) + (x.failed ? " · Not created" : x.day !== null ? " · Day " + x.day : "")));
|
|
667
|
+
rail.append(item);
|
|
668
|
+
});
|
|
669
|
+
body.append(rail);
|
|
670
|
+
}
|
|
671
|
+
const wrap = el("div", "", { className: "fs-wrap" });
|
|
672
|
+
wrap.append(stage(e));
|
|
673
|
+
if (series()) {
|
|
674
|
+
const prev = button("step-btn prev", "", () => select(sel - 1), { ariaLabel: "Previous email", disabled: sel === 0 });
|
|
675
|
+
const next = button("step-btn next", "", () => select(sel + 1), { ariaLabel: "Next email", disabled: sel === s.emails.length - 1 });
|
|
676
|
+
prev.append(icon("prev")); next.append(icon("next"));
|
|
677
|
+
wrap.append(prev, next);
|
|
678
|
+
}
|
|
679
|
+
body.append(wrap);
|
|
680
|
+
box.append(head(e.failed ? "Email " + (sel + 1) + " was not created" : e.subject || "Your email", e.failed ? "" : e.preheader, [back]));
|
|
681
|
+
if (series()) box.append(tabs());
|
|
682
|
+
box.append(body, foot(readyAsks(e, sel), e.appUrl || s.appUrl, true));
|
|
683
|
+
if (s.note) box.append(el("p", s.note, { className: "note small" }));
|
|
684
|
+
return [box];
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function render() {
|
|
688
|
+
const main = $("card");
|
|
689
|
+
main.setAttribute("aria-busy", String(s.phase === "working" && !s.compact));
|
|
690
|
+
let parts;
|
|
691
|
+
if (s.compact) parts = compactView();
|
|
692
|
+
else if (fullScreen()) parts = fullScreenView();
|
|
693
|
+
else parts = s.phase === "working" ? workingView() : s.phase === "failed" ? failedView() : readyView();
|
|
694
|
+
if (s.note && !fullScreen()) parts.push(el("p", s.note, { className: "note small" }));
|
|
695
|
+
main.replaceChildren(...parts);
|
|
696
|
+
// ChatGPT's own "Open in" button in full screen opens this card's page unless told otherwise.
|
|
697
|
+
const link = s.emails?.[sel]?.appUrl || s.before?.appUrl || s.appUrl;
|
|
698
|
+
if (link) window.openai?.setOpenInAppUrl?.({ href: link });
|
|
699
|
+
tick();
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
new ResizeObserver(() => send({ method: "ui/notifications/size-changed", params: { height: Math.ceil(document.documentElement.getBoundingClientRect().height) } }))
|
|
703
|
+
.observe(document.documentElement);
|
|
704
|
+
|
|
705
|
+
const init = await request("ui/initialize", {
|
|
706
|
+
appInfo: { name: "Migma email", version: "1.0.0" },
|
|
707
|
+
appCapabilities: { availableDisplayModes: ["inline", "fullscreen"] },
|
|
708
|
+
protocolVersion: "2026-01-26",
|
|
709
|
+
});
|
|
710
|
+
caps = init?.hostCapabilities ?? {};
|
|
711
|
+
applyHost(init?.hostContext);
|
|
712
|
+
send({ method: "ui/notifications/initialized", params: {} });
|
|
713
|
+
</script>
|
|
714
|
+
</body>
|
|
715
|
+
</html>
|
|
716
|
+
`;
|
|
717
|
+
//# sourceMappingURL=email-card.js.map
|