@happyvertical/garrula 0.0.0-stage → 0.1.2
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/AGENTS.md +71 -0
- package/CLAUDE.md +1 -0
- package/README.md +117 -2
- package/dist/Garrula.d.ts +240 -0
- package/dist/config.d.ts +49 -0
- package/dist/credentials.d.ts +57 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +2137 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.json +2217 -0
- package/dist/outbound/drafting.d.ts +23 -0
- package/dist/outbound/models.d.ts +108 -0
- package/dist/outbound/rates.d.ts +35 -0
- package/dist/outbound/service.d.ts +127 -0
- package/dist/outbound/sources.d.ts +20 -0
- package/dist/outbound/state.d.ts +6 -0
- package/dist/outbound/types.d.ts +165 -0
- package/dist/smrt-knowledge.json +1161 -0
- package/dist/types.d.ts +199 -0
- package/dist/ui/admin/ActivitySpendPanel.svelte +340 -0
- package/dist/ui/admin/ActivitySpendPanel.svelte.d.ts +3 -0
- package/dist/ui/admin/AdminRoot.svelte +70 -0
- package/dist/ui/admin/AdminRoot.svelte.d.ts +9 -0
- package/dist/ui/admin/DraftCard.svelte +359 -0
- package/dist/ui/admin/DraftCard.svelte.d.ts +17 -0
- package/dist/ui/admin/PersonaPolicyPanel.svelte +173 -0
- package/dist/ui/admin/PersonaPolicyPanel.svelte.d.ts +3 -0
- package/dist/ui/admin/QueuePanel.svelte +192 -0
- package/dist/ui/admin/QueuePanel.svelte.d.ts +3 -0
- package/dist/ui/admin/SettingsPanel.svelte +338 -0
- package/dist/ui/admin/SettingsPanel.svelte.d.ts +4 -0
- package/dist/ui/admin/SourcesPanel.svelte +196 -0
- package/dist/ui/admin/SourcesPanel.svelte.d.ts +3 -0
- package/dist/ui/admin/StatusRegion.svelte +41 -0
- package/dist/ui/admin/StatusRegion.svelte.d.ts +7 -0
- package/dist/ui/admin/access.d.ts +23 -0
- package/dist/ui/admin/access.js +30 -0
- package/dist/ui/admin/format.d.ts +9 -0
- package/dist/ui/admin/format.js +39 -0
- package/dist/ui/admin/index.d.ts +12 -0
- package/dist/ui/admin/index.js +17 -0
- package/dist/ui/admin/nav.d.ts +2 -0
- package/dist/ui/admin/nav.js +7 -0
- package/dist/ui/post-kinds.d.ts +8 -0
- package/dist/ui/post-kinds.js +1 -0
- package/dist/ui/types.d.ts +86 -0
- package/dist/ui/types.js +63 -0
- package/docs/manifest-routing.md +41 -0
- package/package.json +111 -4
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick } from "svelte";
|
|
3
|
+
import { Badge, Button } from "@happyvertical/smrt-ui";
|
|
4
|
+
import { Input, Textarea } from "@happyvertical/smrt-ui/forms";
|
|
5
|
+
import type { OutboundDraft, OutboundState } from "../../outbound/types.js";
|
|
6
|
+
import type { AdminPermission } from "../types.js";
|
|
7
|
+
import { formatDateTime } from "./format.js";
|
|
8
|
+
|
|
9
|
+
type Variant = "default" | "primary" | "success" | "warning" | "error" | "info" | "neutral";
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
draft: OutboundDraft;
|
|
13
|
+
accountLabel?: string;
|
|
14
|
+
can: (permission: AdminPermission) => boolean;
|
|
15
|
+
/** True while any action on this draft is in flight. */
|
|
16
|
+
busy?: boolean;
|
|
17
|
+
onedit: (id: string, text: string) => Promise<boolean>;
|
|
18
|
+
onapprove: (id: string) => Promise<boolean>;
|
|
19
|
+
onreject: (id: string, reason: string) => Promise<boolean>;
|
|
20
|
+
onretry: (id: string) => Promise<boolean>;
|
|
21
|
+
onschedule: (id: string, at: Date) => Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let {
|
|
25
|
+
draft,
|
|
26
|
+
accountLabel,
|
|
27
|
+
can,
|
|
28
|
+
busy = false,
|
|
29
|
+
onedit,
|
|
30
|
+
onapprove,
|
|
31
|
+
onreject,
|
|
32
|
+
onretry,
|
|
33
|
+
onschedule,
|
|
34
|
+
}: Props = $props();
|
|
35
|
+
|
|
36
|
+
const STATE_VARIANT: Record<OutboundState, Variant> = {
|
|
37
|
+
draft: "neutral",
|
|
38
|
+
approved: "info",
|
|
39
|
+
scheduled: "info",
|
|
40
|
+
published: "success",
|
|
41
|
+
failed: "error",
|
|
42
|
+
rejected: "warning",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let root = $state<HTMLElement | null>(null);
|
|
46
|
+
let mode = $state<"view" | "edit" | "reject">("view");
|
|
47
|
+
let editText = $state("");
|
|
48
|
+
let reason = $state("");
|
|
49
|
+
let scheduleAt = $state("");
|
|
50
|
+
|
|
51
|
+
const uid = $props.id();
|
|
52
|
+
|
|
53
|
+
const uncitedClaims = $derived(
|
|
54
|
+
draft.claims.filter(
|
|
55
|
+
(claim) =>
|
|
56
|
+
claim.evidence.length === 0 || claim.evidence.some((item) => item.ref.trim().length === 0),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
const uncited = $derived(
|
|
60
|
+
!draft.publishable || draft.claims.length === 0 || uncitedClaims.length > 0,
|
|
61
|
+
);
|
|
62
|
+
const editable = $derived(["draft", "approved", "scheduled", "failed"].includes(draft.state));
|
|
63
|
+
const canReject = $derived(["draft", "approved", "scheduled", "failed"].includes(draft.state));
|
|
64
|
+
const needsApproval = $derived(draft.state === "draft");
|
|
65
|
+
const canRetry = $derived(draft.state === "failed");
|
|
66
|
+
const canSchedule = $derived(draft.state === "approved" || draft.state === "scheduled");
|
|
67
|
+
|
|
68
|
+
function focusAction(name: string) {
|
|
69
|
+
tick().then(() => root?.querySelector<HTMLElement>(`[data-action="${name}"]`)?.focus());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function startEdit() {
|
|
73
|
+
editText = draft.text;
|
|
74
|
+
mode = "edit";
|
|
75
|
+
tick().then(() => root?.querySelector<HTMLElement>(`#${CSS.escape(`${uid}-text`)}`)?.focus());
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function saveEdit() {
|
|
79
|
+
if (await onedit(draft.id, editText)) {
|
|
80
|
+
mode = "view";
|
|
81
|
+
focusAction("edit");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function startReject() {
|
|
86
|
+
reason = "";
|
|
87
|
+
mode = "reject";
|
|
88
|
+
tick().then(() => root?.querySelector<HTMLElement>(`#${CSS.escape(`${uid}-reason`)}`)?.focus());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function confirmReject() {
|
|
92
|
+
if (await onreject(draft.id, reason.trim())) mode = "view";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function cancel(returnTo: string) {
|
|
96
|
+
mode = "view";
|
|
97
|
+
focusAction(returnTo);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function schedule() {
|
|
101
|
+
// The input is a UTC wall-clock time; "Z" keeps it independent of the browser zone.
|
|
102
|
+
const at = new Date(`${scheduleAt}:00Z`);
|
|
103
|
+
if (Number.isNaN(at.getTime())) return;
|
|
104
|
+
await onschedule(draft.id, at);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function onEditKeydown(event: KeyboardEvent, cancelTo: string) {
|
|
108
|
+
if (event.key === "Escape") {
|
|
109
|
+
event.stopPropagation();
|
|
110
|
+
cancel(cancelTo);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<article class="draft" bind:this={root} aria-labelledby="{uid}-title" data-draft-id={draft.id} data-state={draft.state}>
|
|
116
|
+
<header class="head">
|
|
117
|
+
<h2 id="{uid}-title" class="title">
|
|
118
|
+
{draft.kind} post{accountLabel ? ` for ${accountLabel}` : ""}
|
|
119
|
+
</h2>
|
|
120
|
+
<Badge variant={STATE_VARIANT[draft.state]} size="sm">State: {draft.state}</Badge>
|
|
121
|
+
{#if uncited}
|
|
122
|
+
<Badge variant="error" size="sm">Uncited claim</Badge>
|
|
123
|
+
{/if}
|
|
124
|
+
</header>
|
|
125
|
+
|
|
126
|
+
{#if mode === "edit"}
|
|
127
|
+
<div class="field">
|
|
128
|
+
<label for="{uid}-text">Post text</label>
|
|
129
|
+
<Textarea id="{uid}-text" bind:value={editText} rows={4} onkeydown={(e) => onEditKeydown(e, "edit")} />
|
|
130
|
+
{#if draft.state !== "draft"}
|
|
131
|
+
<p class="hint">Saving withdraws the current approval; approve it again afterwards.</p>
|
|
132
|
+
{/if}
|
|
133
|
+
</div>
|
|
134
|
+
<div class="actions">
|
|
135
|
+
<Button size="sm" variant="primary" data-action="save" onclick={saveEdit} disabled={busy || editText.trim() === ""}>Save text</Button>
|
|
136
|
+
<Button size="sm" variant="secondary" onclick={() => cancel("edit")} disabled={busy}>Cancel</Button>
|
|
137
|
+
</div>
|
|
138
|
+
{:else}
|
|
139
|
+
<p class="text">{draft.text}</p>
|
|
140
|
+
{#if draft.linkUrl}
|
|
141
|
+
<p class="meta">Link in post: <a href={draft.linkUrl} target="_blank" rel="noreferrer">{draft.linkUrl}</a></p>
|
|
142
|
+
{/if}
|
|
143
|
+
{/if}
|
|
144
|
+
|
|
145
|
+
<div class="evidence">
|
|
146
|
+
<h3>Evidence</h3>
|
|
147
|
+
{#if draft.claims.length === 0}
|
|
148
|
+
<p class="uncited-note">This draft has no claims, so nothing is cited.</p>
|
|
149
|
+
{:else}
|
|
150
|
+
<ul>
|
|
151
|
+
{#each draft.claims as claim, index (index)}
|
|
152
|
+
{@const cited = claim.evidence.length > 0 && claim.evidence.every((item) => item.ref.trim() !== "")}
|
|
153
|
+
<li class:flagged={!cited}>
|
|
154
|
+
<p class="claim">
|
|
155
|
+
{#if !cited}<strong class="flag">Uncited:</strong>{/if}
|
|
156
|
+
{claim.text}
|
|
157
|
+
</p>
|
|
158
|
+
{#if cited}
|
|
159
|
+
<ul class="refs">
|
|
160
|
+
{#each claim.evidence as item, itemIndex (itemIndex)}
|
|
161
|
+
<li>
|
|
162
|
+
{#if item.type === "url"}
|
|
163
|
+
<span class="ref-kind">Pull request or release:</span>
|
|
164
|
+
<a href={item.ref} target="_blank" rel="noreferrer">{item.ref}</a>
|
|
165
|
+
{:else}
|
|
166
|
+
<span class="ref-kind">Changelog line:</span>
|
|
167
|
+
<q>{item.ref}</q>
|
|
168
|
+
{/if}
|
|
169
|
+
</li>
|
|
170
|
+
{/each}
|
|
171
|
+
</ul>
|
|
172
|
+
{:else}
|
|
173
|
+
<p class="uncited-note">No evidence is attached. Add a citation or reject this draft.</p>
|
|
174
|
+
{/if}
|
|
175
|
+
</li>
|
|
176
|
+
{/each}
|
|
177
|
+
</ul>
|
|
178
|
+
{/if}
|
|
179
|
+
</div>
|
|
180
|
+
|
|
181
|
+
{#if draft.state === "failed" && draft.error}
|
|
182
|
+
<p class="failure"><strong>Failed:</strong> {draft.error}</p>
|
|
183
|
+
{/if}
|
|
184
|
+
{#if draft.state === "rejected" && draft.rejectedReason}
|
|
185
|
+
<p class="meta"><strong>Rejected:</strong> {draft.rejectedReason}</p>
|
|
186
|
+
{/if}
|
|
187
|
+
{#if draft.state === "published" && draft.publishedUrl}
|
|
188
|
+
<p class="meta"><a href={draft.publishedUrl} target="_blank" rel="noreferrer">View published post</a></p>
|
|
189
|
+
{/if}
|
|
190
|
+
{#if draft.scheduledAt && (draft.state === "scheduled" || draft.state === "approved")}
|
|
191
|
+
<p class="meta">Scheduled for {formatDateTime(draft.scheduledAt)}</p>
|
|
192
|
+
{/if}
|
|
193
|
+
{#if draft.approvedBy && draft.state !== "draft" && draft.state !== "rejected"}
|
|
194
|
+
<p class="meta">Approved by {draft.approvedBy}</p>
|
|
195
|
+
{/if}
|
|
196
|
+
|
|
197
|
+
{#if mode === "reject"}
|
|
198
|
+
<div class="field">
|
|
199
|
+
<label for="{uid}-reason">Reason for rejecting (optional)</label>
|
|
200
|
+
<Input id="{uid}-reason" bind:value={reason} onkeydown={(e) => onEditKeydown(e, "reject")} />
|
|
201
|
+
</div>
|
|
202
|
+
<div class="actions">
|
|
203
|
+
<Button size="sm" variant="danger" data-action="confirm-reject" onclick={confirmReject} disabled={busy}>Confirm reject</Button>
|
|
204
|
+
<Button size="sm" variant="secondary" onclick={() => cancel("reject")} disabled={busy}>Cancel</Button>
|
|
205
|
+
</div>
|
|
206
|
+
{:else if mode === "view"}
|
|
207
|
+
<div class="actions">
|
|
208
|
+
{#if can("approve") && needsApproval}
|
|
209
|
+
<Button
|
|
210
|
+
size="sm"
|
|
211
|
+
variant="primary"
|
|
212
|
+
data-action="approve"
|
|
213
|
+
onclick={() => onapprove(draft.id)}
|
|
214
|
+
disabled={busy || uncited}
|
|
215
|
+
aria-describedby={uncited ? `${uid}-blocked` : undefined}
|
|
216
|
+
>Approve</Button>
|
|
217
|
+
{/if}
|
|
218
|
+
{#if can("approve") && canRetry}
|
|
219
|
+
<Button
|
|
220
|
+
size="sm"
|
|
221
|
+
variant="primary"
|
|
222
|
+
data-action="retry"
|
|
223
|
+
onclick={() => onretry(draft.id)}
|
|
224
|
+
disabled={busy || uncited}
|
|
225
|
+
aria-describedby={uncited ? `${uid}-blocked` : undefined}
|
|
226
|
+
>Retry</Button>
|
|
227
|
+
{/if}
|
|
228
|
+
{#if can("approve") && editable}
|
|
229
|
+
<Button size="sm" variant="secondary" data-action="edit" onclick={startEdit} disabled={busy}>Edit text</Button>
|
|
230
|
+
{/if}
|
|
231
|
+
{#if can("approve") && canReject}
|
|
232
|
+
<Button size="sm" variant="danger" data-action="reject" onclick={startReject} disabled={busy}>Reject</Button>
|
|
233
|
+
{/if}
|
|
234
|
+
</div>
|
|
235
|
+
{#if can("publish") && canSchedule}
|
|
236
|
+
<div class="schedule">
|
|
237
|
+
<label for="{uid}-at">Publish at (UTC)</label>
|
|
238
|
+
<Input id="{uid}-at" type="datetime-local" bind:value={scheduleAt} />
|
|
239
|
+
<Button size="sm" variant="secondary" data-action="schedule" onclick={schedule} disabled={busy || scheduleAt === ""}>Schedule</Button>
|
|
240
|
+
</div>
|
|
241
|
+
{/if}
|
|
242
|
+
{#if uncited && can("approve") && (needsApproval || canRetry)}
|
|
243
|
+
<p id="{uid}-blocked" class="uncited-note">
|
|
244
|
+
{needsApproval ? "Approve" : "Retry"} is unavailable until every claim cites a pull request or changelog line.
|
|
245
|
+
</p>
|
|
246
|
+
{/if}
|
|
247
|
+
{/if}
|
|
248
|
+
</article>
|
|
249
|
+
|
|
250
|
+
<style>
|
|
251
|
+
.draft {
|
|
252
|
+
background: var(--smrt-color-surface, #ffffff);
|
|
253
|
+
border: 1px solid var(--smrt-color-outline-variant, #6b7280);
|
|
254
|
+
border-radius: var(--smrt-radius-lg, 8px);
|
|
255
|
+
color: var(--smrt-color-on-surface, #111827);
|
|
256
|
+
display: grid;
|
|
257
|
+
gap: 0.75rem;
|
|
258
|
+
padding: 1rem;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.head {
|
|
262
|
+
align-items: center;
|
|
263
|
+
display: flex;
|
|
264
|
+
flex-wrap: wrap;
|
|
265
|
+
gap: 0.5rem;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.title {
|
|
269
|
+
font-size: 1rem;
|
|
270
|
+
margin: 0;
|
|
271
|
+
margin-inline-end: auto;
|
|
272
|
+
text-transform: capitalize;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.text {
|
|
276
|
+
margin: 0;
|
|
277
|
+
overflow-wrap: anywhere;
|
|
278
|
+
white-space: pre-wrap;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.meta,
|
|
282
|
+
.hint {
|
|
283
|
+
color: var(--smrt-color-on-surface-variant, #4b5563);
|
|
284
|
+
font-size: 0.85rem;
|
|
285
|
+
margin: 0;
|
|
286
|
+
overflow-wrap: anywhere;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
a {
|
|
290
|
+
color: var(--smrt-color-primary, #1d4ed8);
|
|
291
|
+
text-decoration: underline;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
.evidence h3 {
|
|
295
|
+
font-size: 0.85rem;
|
|
296
|
+
margin: 0 0 0.35rem;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.evidence ul {
|
|
300
|
+
display: grid;
|
|
301
|
+
gap: 0.5rem;
|
|
302
|
+
list-style: none;
|
|
303
|
+
margin: 0;
|
|
304
|
+
padding: 0;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.evidence > ul > li {
|
|
308
|
+
border-inline-start: 3px solid var(--smrt-color-outline, #4b5563);
|
|
309
|
+
padding-inline-start: 0.75rem;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.evidence > ul > li.flagged {
|
|
313
|
+
border-inline-start-color: var(--smrt-color-error, #b91c1c);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.claim {
|
|
317
|
+
font-size: 0.9rem;
|
|
318
|
+
margin: 0;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.flag,
|
|
322
|
+
.uncited-note,
|
|
323
|
+
.failure {
|
|
324
|
+
color: var(--smrt-color-error, #b91c1c);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.uncited-note,
|
|
328
|
+
.failure {
|
|
329
|
+
font-size: 0.85rem;
|
|
330
|
+
margin: 0;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.refs {
|
|
334
|
+
font-size: 0.85rem;
|
|
335
|
+
margin-top: 0.25rem;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.ref-kind {
|
|
339
|
+
color: var(--smrt-color-on-surface-variant, #4b5563);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.field {
|
|
343
|
+
display: grid;
|
|
344
|
+
gap: 0.35rem;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
label {
|
|
348
|
+
font-size: 0.85rem;
|
|
349
|
+
font-weight: 600;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
.actions,
|
|
353
|
+
.schedule {
|
|
354
|
+
align-items: center;
|
|
355
|
+
display: flex;
|
|
356
|
+
flex-wrap: wrap;
|
|
357
|
+
gap: 0.5rem;
|
|
358
|
+
}
|
|
359
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { OutboundDraft } from "../../outbound/types.js";
|
|
2
|
+
import type { AdminPermission } from "../types.js";
|
|
3
|
+
interface Props {
|
|
4
|
+
draft: OutboundDraft;
|
|
5
|
+
accountLabel?: string;
|
|
6
|
+
can: (permission: AdminPermission) => boolean;
|
|
7
|
+
/** True while any action on this draft is in flight. */
|
|
8
|
+
busy?: boolean;
|
|
9
|
+
onedit: (id: string, text: string) => Promise<boolean>;
|
|
10
|
+
onapprove: (id: string) => Promise<boolean>;
|
|
11
|
+
onreject: (id: string, reason: string) => Promise<boolean>;
|
|
12
|
+
onretry: (id: string) => Promise<boolean>;
|
|
13
|
+
onschedule: (id: string, at: Date) => Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
declare const DraftCard: import("svelte").Component<Props, {}, "">;
|
|
16
|
+
type DraftCard = ReturnType<typeof DraftCard>;
|
|
17
|
+
export default DraftCard;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Alert, Button } from "@happyvertical/smrt-ui";
|
|
3
|
+
import { Select, Textarea } from "@happyvertical/smrt-ui/forms";
|
|
4
|
+
import { PageHeader } from "@happyvertical/smrt-ui/layout";
|
|
5
|
+
import { onMount } from "svelte";
|
|
6
|
+
import type { AutonomyMode, OutboundSettings } from "../../outbound/types.js";
|
|
7
|
+
import { OUTBOUND_POST_KINDS, type OutboundPostKind } from "../post-kinds.js";
|
|
8
|
+
import type { PersonaPolicyPanelProps } from "../types.js";
|
|
9
|
+
import { getGarrulaAdminContext, resolveAccess } from "./access.js";
|
|
10
|
+
import { errorMessage, parseLines } from "./format.js";
|
|
11
|
+
import StatusRegion from "./StatusRegion.svelte";
|
|
12
|
+
|
|
13
|
+
let { apiClient, readonly = false, tenant, permissions }: PersonaPolicyPanelProps = $props();
|
|
14
|
+
|
|
15
|
+
const context = getGarrulaAdminContext();
|
|
16
|
+
const access = $derived(resolveAccess({ tenant, permissions, readonly }, context));
|
|
17
|
+
const canConfigure = $derived(access.can("configure"));
|
|
18
|
+
|
|
19
|
+
const KIND_LABELS: Record<OutboundPostKind, string> = {
|
|
20
|
+
release: "Release posts (package publishes)",
|
|
21
|
+
feature: "Feature posts (merged pull requests)",
|
|
22
|
+
docs: "Docs posts (documentation changes)",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
let loaded = $state(false);
|
|
26
|
+
let persona = $state("");
|
|
27
|
+
let topics = $state("");
|
|
28
|
+
let autonomy = $state<Record<OutboundPostKind, AutonomyMode>>({
|
|
29
|
+
release: "require-approval",
|
|
30
|
+
feature: "require-approval",
|
|
31
|
+
docs: "require-approval",
|
|
32
|
+
});
|
|
33
|
+
let error = $state<string | null>(null);
|
|
34
|
+
let message = $state("");
|
|
35
|
+
let saving = $state(false);
|
|
36
|
+
|
|
37
|
+
function seed(settings: OutboundSettings) {
|
|
38
|
+
persona = settings.persona;
|
|
39
|
+
topics = settings.deferTopics.join("\n");
|
|
40
|
+
autonomy = { ...settings.autonomy };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function load() {
|
|
44
|
+
error = null;
|
|
45
|
+
try {
|
|
46
|
+
seed(await apiClient.getSettings());
|
|
47
|
+
loaded = true;
|
|
48
|
+
} catch (err) {
|
|
49
|
+
error = errorMessage(err);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function save(event: SubmitEvent) {
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
saving = true;
|
|
56
|
+
error = null;
|
|
57
|
+
message = "";
|
|
58
|
+
try {
|
|
59
|
+
seed(
|
|
60
|
+
await apiClient.updateSettings({
|
|
61
|
+
persona: persona.trim(),
|
|
62
|
+
deferTopics: parseLines(topics),
|
|
63
|
+
autonomy,
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
message = "Persona and policy saved.";
|
|
67
|
+
} catch (err) {
|
|
68
|
+
error = errorMessage(err);
|
|
69
|
+
} finally {
|
|
70
|
+
saving = false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
onMount(load);
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<section class="persona" aria-label="Persona and policy" data-tenant={access.tenant?.id}>
|
|
78
|
+
<PageHeader
|
|
79
|
+
title="Persona and policy"
|
|
80
|
+
subtitle="How the agent sounds, what it leaves to a person, and when it may approve its own drafts."
|
|
81
|
+
/>
|
|
82
|
+
<StatusRegion {message} {error} />
|
|
83
|
+
|
|
84
|
+
{#if !access.can("read")}
|
|
85
|
+
<p class="hint">You do not have permission to view this.</p>
|
|
86
|
+
{:else if loaded}
|
|
87
|
+
<form onsubmit={save}>
|
|
88
|
+
<div class="field">
|
|
89
|
+
<label for="persona-voice">Voice and persona</label>
|
|
90
|
+
<Textarea id="persona-voice" bind:value={persona} rows={6} disabled={!canConfigure} />
|
|
91
|
+
<p class="hint">
|
|
92
|
+
Written to the model for every draft. Claims still need a pull request or changelog line
|
|
93
|
+
as evidence, whatever the voice.
|
|
94
|
+
</p>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div class="field">
|
|
98
|
+
<label for="persona-topics">Topics the agent defers on</label>
|
|
99
|
+
<Textarea id="persona-topics" bind:value={topics} rows={4} disabled={!canConfigure} />
|
|
100
|
+
<p class="hint">
|
|
101
|
+
One per line. An event whose title, summary or labels mention one is drafted but never
|
|
102
|
+
approved automatically, even when its post type is set to auto.
|
|
103
|
+
</p>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<fieldset disabled={!canConfigure}>
|
|
107
|
+
<legend>Autonomy per post type</legend>
|
|
108
|
+
{#each OUTBOUND_POST_KINDS as kind (kind)}
|
|
109
|
+
<div class="row">
|
|
110
|
+
<label for="autonomy-{kind}">{KIND_LABELS[kind]}</label>
|
|
111
|
+
<Select id="autonomy-{kind}" bind:value={autonomy[kind]}>
|
|
112
|
+
<option value="require-approval">Require approval</option>
|
|
113
|
+
<option value="auto">Approve automatically when fully cited</option>
|
|
114
|
+
</Select>
|
|
115
|
+
</div>
|
|
116
|
+
{/each}
|
|
117
|
+
<p class="hint">
|
|
118
|
+
Automatic approval still obeys the pause switch, the monthly cap, and the evidence rule.
|
|
119
|
+
</p>
|
|
120
|
+
</fieldset>
|
|
121
|
+
|
|
122
|
+
{#if canConfigure}
|
|
123
|
+
<div class="actions">
|
|
124
|
+
<Button type="submit" variant="primary" disabled={saving}>Save persona and policy</Button>
|
|
125
|
+
</div>
|
|
126
|
+
{:else}
|
|
127
|
+
<Alert variant="info">View only: you do not have permission to change the persona or policy.</Alert>
|
|
128
|
+
{/if}
|
|
129
|
+
</form>
|
|
130
|
+
{/if}
|
|
131
|
+
</section>
|
|
132
|
+
|
|
133
|
+
<style>
|
|
134
|
+
.persona,
|
|
135
|
+
form {
|
|
136
|
+
color: var(--smrt-color-on-surface, #111827);
|
|
137
|
+
display: grid;
|
|
138
|
+
gap: 1rem;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.field {
|
|
142
|
+
display: grid;
|
|
143
|
+
gap: 0.35rem;
|
|
144
|
+
max-width: 40rem;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
label,
|
|
148
|
+
legend {
|
|
149
|
+
font-size: 0.85rem;
|
|
150
|
+
font-weight: 600;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.hint {
|
|
154
|
+
color: var(--smrt-color-on-surface-variant, #4b5563);
|
|
155
|
+
font-size: 0.85rem;
|
|
156
|
+
margin: 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
fieldset {
|
|
160
|
+
border: 1px solid var(--smrt-color-outline-variant, #6b7280);
|
|
161
|
+
border-radius: var(--smrt-radius-lg, 8px);
|
|
162
|
+
display: grid;
|
|
163
|
+
gap: 0.75rem;
|
|
164
|
+
margin: 0;
|
|
165
|
+
max-width: 40rem;
|
|
166
|
+
padding: 0.75rem;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.row {
|
|
170
|
+
display: grid;
|
|
171
|
+
gap: 0.35rem;
|
|
172
|
+
}
|
|
173
|
+
</style>
|