@happyvertical/garrula 0.0.0-stage → 0.1.1

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.
Files changed (47) hide show
  1. package/AGENTS.md +71 -0
  2. package/CLAUDE.md +1 -0
  3. package/README.md +117 -2
  4. package/dist/Garrula.d.ts +240 -0
  5. package/dist/config.d.ts +49 -0
  6. package/dist/credentials.d.ts +57 -0
  7. package/dist/index.d.ts +10 -0
  8. package/dist/index.js +2135 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/manifest.json +2217 -0
  11. package/dist/outbound/drafting.d.ts +23 -0
  12. package/dist/outbound/models.d.ts +108 -0
  13. package/dist/outbound/rates.d.ts +35 -0
  14. package/dist/outbound/service.d.ts +127 -0
  15. package/dist/outbound/sources.d.ts +20 -0
  16. package/dist/outbound/state.d.ts +6 -0
  17. package/dist/outbound/types.d.ts +165 -0
  18. package/dist/smrt-knowledge.json +1161 -0
  19. package/dist/types.d.ts +199 -0
  20. package/dist/ui/admin/ActivitySpendPanel.svelte +340 -0
  21. package/dist/ui/admin/ActivitySpendPanel.svelte.d.ts +3 -0
  22. package/dist/ui/admin/AdminRoot.svelte +70 -0
  23. package/dist/ui/admin/AdminRoot.svelte.d.ts +9 -0
  24. package/dist/ui/admin/DraftCard.svelte +359 -0
  25. package/dist/ui/admin/DraftCard.svelte.d.ts +17 -0
  26. package/dist/ui/admin/PersonaPolicyPanel.svelte +177 -0
  27. package/dist/ui/admin/PersonaPolicyPanel.svelte.d.ts +3 -0
  28. package/dist/ui/admin/QueuePanel.svelte +192 -0
  29. package/dist/ui/admin/QueuePanel.svelte.d.ts +3 -0
  30. package/dist/ui/admin/SettingsPanel.svelte +338 -0
  31. package/dist/ui/admin/SettingsPanel.svelte.d.ts +4 -0
  32. package/dist/ui/admin/SourcesPanel.svelte +196 -0
  33. package/dist/ui/admin/SourcesPanel.svelte.d.ts +3 -0
  34. package/dist/ui/admin/StatusRegion.svelte +41 -0
  35. package/dist/ui/admin/StatusRegion.svelte.d.ts +7 -0
  36. package/dist/ui/admin/access.d.ts +23 -0
  37. package/dist/ui/admin/access.js +30 -0
  38. package/dist/ui/admin/format.d.ts +9 -0
  39. package/dist/ui/admin/format.js +39 -0
  40. package/dist/ui/admin/index.d.ts +12 -0
  41. package/dist/ui/admin/index.js +17 -0
  42. package/dist/ui/admin/nav.d.ts +2 -0
  43. package/dist/ui/admin/nav.js +7 -0
  44. package/dist/ui/types.d.ts +86 -0
  45. package/dist/ui/types.js +63 -0
  46. package/docs/manifest-routing.md +41 -0
  47. package/package.json +111 -4
@@ -0,0 +1,192 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import { Button, Tabs } from "@happyvertical/smrt-ui";
4
+ import { PageHeader } from "@happyvertical/smrt-ui/layout";
5
+ import { Select } from "@happyvertical/smrt-ui/forms";
6
+ import type { OutboundDraft, OutboundState } from "../../outbound/types.js";
7
+ import type { QueuePanelProps } from "../types.js";
8
+ import DraftCard from "./DraftCard.svelte";
9
+ import StatusRegion from "./StatusRegion.svelte";
10
+ import { getGarrulaAdminContext, resolveAccess } from "./access.js";
11
+ import { errorMessage } from "./format.js";
12
+
13
+ let { apiClient, readonly = false, tenant, permissions }: QueuePanelProps = $props();
14
+
15
+ const context = getGarrulaAdminContext();
16
+ const access = $derived(resolveAccess({ tenant, permissions, readonly }, context));
17
+
18
+ const STATES: { id: OutboundState; label: string }[] = [
19
+ { id: "draft", label: "Drafts" },
20
+ { id: "approved", label: "Approved" },
21
+ { id: "scheduled", label: "Scheduled" },
22
+ { id: "published", label: "Published" },
23
+ { id: "failed", label: "Failed" },
24
+ { id: "rejected", label: "Rejected" },
25
+ ];
26
+
27
+ let drafts = $state<OutboundDraft[]>([]);
28
+ let active = $state<OutboundState>("draft");
29
+ let kind = $state("");
30
+ let loading = $state(true);
31
+ let busyId = $state<string | null>(null);
32
+ let error = $state<string | null>(null);
33
+ let message = $state("");
34
+
35
+ const visible = $derived(
36
+ drafts.filter((draft) => draft.state === active && (kind === "" || draft.kind === kind)),
37
+ );
38
+ const tabs = $derived(
39
+ STATES.map((state) => ({
40
+ id: state.id,
41
+ label: state.label,
42
+ count: drafts.filter(
43
+ (draft) => draft.state === state.id && (kind === "" || draft.kind === kind),
44
+ ).length,
45
+ })),
46
+ );
47
+
48
+ async function load() {
49
+ loading = true;
50
+ error = null;
51
+ try {
52
+ drafts = await apiClient.listDrafts();
53
+ } catch (err) {
54
+ error = errorMessage(err);
55
+ } finally {
56
+ loading = false;
57
+ }
58
+ }
59
+
60
+ /** Run one action on a draft, fold the returned view into the list, announce the result. */
61
+ async function act(
62
+ id: string,
63
+ run: () => Promise<OutboundDraft>,
64
+ done: (updated: OutboundDraft) => string,
65
+ ): Promise<boolean> {
66
+ busyId = id;
67
+ error = null;
68
+ message = "";
69
+ try {
70
+ const updated = await run();
71
+ drafts = drafts.map((draft) => (draft.id === id ? updated : draft));
72
+ message = done(updated);
73
+ return true;
74
+ } catch (err) {
75
+ error = errorMessage(err);
76
+ return false;
77
+ } finally {
78
+ busyId = null;
79
+ }
80
+ }
81
+
82
+ const moved = (verb: string) => (updated: OutboundDraft) =>
83
+ `${verb}. It is now in ${STATES.find((s) => s.id === updated.state)?.label ?? updated.state}.`;
84
+
85
+ const edit = (id: string, text: string) =>
86
+ act(
87
+ id,
88
+ () => apiClient.editDraft(id, { text }),
89
+ (u) => `Text saved. It is now in ${STATES.find((s) => s.id === u.state)?.label}.`,
90
+ );
91
+ const approve = (id: string) => act(id, () => apiClient.approveDraft(id), moved("Approved"));
92
+ const reject = (id: string, reason: string) =>
93
+ act(id, () => apiClient.rejectDraft(id, reason || undefined), moved("Rejected"));
94
+ const retry = (id: string) => act(id, () => apiClient.retryDraft(id), moved("Retry queued"));
95
+ const schedule = (id: string, at: Date) =>
96
+ act(id, () => apiClient.scheduleDraft(id, at), moved("Scheduled"));
97
+
98
+ onMount(load);
99
+ </script>
100
+
101
+ <section class="queue-panel" aria-label="Post queue" data-tenant={access.tenant?.id}>
102
+ <PageHeader
103
+ title="Post queue"
104
+ subtitle={access.tenant?.name
105
+ ? `Drafts for ${access.tenant.name}. Nothing publishes until every claim is cited and a person approves it, unless autonomy allows.`
106
+ : "Nothing publishes until every claim is cited and a person approves it, unless autonomy allows."}
107
+ >
108
+ {#snippet actions()}
109
+ <Button variant="secondary" size="sm" onclick={load} disabled={loading}>Refresh</Button>
110
+ {/snippet}
111
+ </PageHeader>
112
+
113
+ {#if !access.can("read")}
114
+ <p class="empty">You do not have permission to view the queue.</p>
115
+ {:else}
116
+ {#if !access.can("approve")}
117
+ <p class="note">View only: you can read drafts but not change them.</p>
118
+ {/if}
119
+
120
+ <div class="filters">
121
+ <label for="queue-kind">Post type</label>
122
+ <Select id="queue-kind" bind:value={kind}>
123
+ <option value="">All types</option>
124
+ <option value="release">Release</option>
125
+ <option value="feature">Feature</option>
126
+ <option value="docs">Docs</option>
127
+ </Select>
128
+ </div>
129
+
130
+ <StatusRegion {message} {error} />
131
+
132
+ <Tabs {tabs} {active} aria-label="Post state" onchange={(id) => (active = id as OutboundState)}>
133
+ {#if loading}
134
+ <p class="empty">Loading drafts...</p>
135
+ {:else if visible.length === 0}
136
+ <p class="empty">No {STATES.find((s) => s.id === active)?.label.toLowerCase()} posts.</p>
137
+ {:else}
138
+ <ul class="list">
139
+ {#each visible as draft (draft.id)}
140
+ <li>
141
+ <DraftCard
142
+ {draft}
143
+ can={access.can}
144
+ busy={busyId === draft.id}
145
+ onedit={edit}
146
+ onapprove={approve}
147
+ onreject={reject}
148
+ onretry={retry}
149
+ onschedule={schedule}
150
+ />
151
+ </li>
152
+ {/each}
153
+ </ul>
154
+ {/if}
155
+ </Tabs>
156
+ {/if}
157
+ </section>
158
+
159
+ <style>
160
+ .queue-panel {
161
+ display: grid;
162
+ gap: 1rem;
163
+ }
164
+
165
+ .filters {
166
+ align-items: center;
167
+ display: flex;
168
+ gap: 0.5rem;
169
+ }
170
+
171
+ label {
172
+ font-size: 0.85rem;
173
+ font-weight: 600;
174
+ }
175
+
176
+ .list {
177
+ display: grid;
178
+ gap: 1rem;
179
+ list-style: none;
180
+ margin: 1rem 0 0;
181
+ padding: 0;
182
+ }
183
+
184
+ .note,
185
+ .empty {
186
+ border: 1px dashed var(--smrt-color-outline-variant, #6b7280);
187
+ border-radius: var(--smrt-radius-lg, 8px);
188
+ color: var(--smrt-color-on-surface-variant, #4b5563);
189
+ margin: 0;
190
+ padding: 1rem;
191
+ }
192
+ </style>
@@ -0,0 +1,3 @@
1
+ declare const QueuePanel: import("svelte").Component<import("./index.js").AdminPanelBaseProps, {}, "">;
2
+ type QueuePanel = ReturnType<typeof QueuePanel>;
3
+ export default QueuePanel;
@@ -0,0 +1,338 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import { Alert, Button } from "@happyvertical/smrt-ui";
4
+ import { Checkbox, Input, Select, Switch } from "@happyvertical/smrt-ui/forms";
5
+ import { SocialAccountSettings } from "@happyvertical/smrt-social/svelte";
6
+ import type { SocialAccountSettingsItem } from "@happyvertical/smrt-social/svelte";
7
+ import type { LinkPolicy, OutboundSettings } from "../../outbound/types.js";
8
+ import type { SettingsPanelProps } from "../types.js";
9
+ import StatusRegion from "./StatusRegion.svelte";
10
+ import { getGarrulaAdminContext, resolveAccess } from "./access.js";
11
+ import { errorMessage, formatUsd, microsToUsdInput, usdToMicros } from "./format.js";
12
+
13
+ let {
14
+ apiClient,
15
+ readonly = false,
16
+ tenant,
17
+ permissions,
18
+ socialSettingsBasePath = "/settings/social",
19
+ }: SettingsPanelProps = $props();
20
+
21
+ const context = getGarrulaAdminContext();
22
+ const access = $derived(resolveAccess({ tenant, permissions, readonly }, context));
23
+ const canConfigure = $derived(access.can("configure"));
24
+ // Pause is a safety control, so a publisher or a configurer may flip it.
25
+ const canPause = $derived(access.can("publish") || access.can("configure"));
26
+
27
+ let accounts = $state<SocialAccountSettingsItem[]>([]);
28
+ let settings = $state<OutboundSettings | null>(null);
29
+ let loading = $state(true);
30
+ let error = $state<string | null>(null);
31
+ let message = $state("");
32
+ let saving = $state(false);
33
+ let pausing = $state(false);
34
+
35
+ // Form state for the publishing section, seeded from `settings` on every load.
36
+ let capInput = $state("0.00");
37
+ let defaultLink = $state<LinkPolicy>("none");
38
+ let linkByAccount = $state<Record<string, LinkPolicy>>({});
39
+ let receives = $state<Record<string, boolean>>({});
40
+
41
+ function seed(next: OutboundSettings) {
42
+ capInput = microsToUsdInput(next.monthlyCapMicros);
43
+ defaultLink = next.defaultLinkPolicy;
44
+ linkByAccount = { ...next.linkPolicy };
45
+ const chosen = new Set(next.accountIds);
46
+ receives = Object.fromEntries(accounts.map((a) => [a.id, chosen.size === 0 || chosen.has(a.id)]));
47
+ }
48
+
49
+ async function load() {
50
+ loading = true;
51
+ error = null;
52
+ try {
53
+ [accounts, settings] = await Promise.all([
54
+ apiClient.listSocialAccounts(),
55
+ apiClient.getSettings(),
56
+ ]);
57
+ seed(settings);
58
+ } catch (err) {
59
+ error = errorMessage(err);
60
+ } finally {
61
+ loading = false;
62
+ }
63
+ }
64
+
65
+ async function reloadAccounts() {
66
+ try {
67
+ accounts = await apiClient.listSocialAccounts();
68
+ if (settings) seed(settings);
69
+ } catch (err) {
70
+ error = errorMessage(err);
71
+ }
72
+ }
73
+
74
+ async function testAccount(account: SocialAccountSettingsItem) {
75
+ await apiClient.testSocialAccount(account.id);
76
+ await reloadAccounts();
77
+ }
78
+
79
+ async function deactivateAccount(account: SocialAccountSettingsItem) {
80
+ await apiClient.deactivateSocialAccount(account.id);
81
+ await reloadAccounts();
82
+ }
83
+
84
+ async function setPaused(paused: boolean) {
85
+ pausing = true;
86
+ error = null;
87
+ message = "";
88
+ try {
89
+ settings = await apiClient.updateSettings({ paused });
90
+ message = paused ? "Publishing paused. Nothing will be sent." : "Publishing resumed.";
91
+ } catch (err) {
92
+ error = errorMessage(err);
93
+ } finally {
94
+ pausing = false;
95
+ }
96
+ }
97
+
98
+ async function save(event: SubmitEvent) {
99
+ event.preventDefault();
100
+ error = null;
101
+ message = "";
102
+ const cap = usdToMicros(capInput);
103
+ if (cap === null) {
104
+ error = "Enter the monthly cap as a dollar amount of zero or more.";
105
+ return;
106
+ }
107
+ const chosen = accounts.filter((a) => receives[a.id]).map((a) => a.id);
108
+ if (accounts.length > 0 && chosen.length === 0) {
109
+ error = "Select at least one account to receive drafts.";
110
+ return;
111
+ }
112
+ const changedLinks: Record<string, LinkPolicy> = {};
113
+ for (const account of accounts) {
114
+ const next = linkByAccount[account.id] ?? defaultLink;
115
+ if (next !== (settings?.linkPolicy[account.id] ?? settings?.defaultLinkPolicy)) {
116
+ changedLinks[account.id] = next;
117
+ }
118
+ }
119
+ saving = true;
120
+ try {
121
+ settings = await apiClient.updateSettings({
122
+ monthlyCapMicros: cap,
123
+ defaultLinkPolicy: defaultLink,
124
+ linkPolicy: changedLinks,
125
+ // Every account selected is stored as "no restriction" (the empty list).
126
+ accountIds: chosen.length === accounts.length ? [] : chosen,
127
+ });
128
+ seed(settings);
129
+ message = "Publishing settings saved.";
130
+ } catch (err) {
131
+ error = errorMessage(err);
132
+ } finally {
133
+ saving = false;
134
+ }
135
+ }
136
+
137
+ onMount(load);
138
+ </script>
139
+
140
+ <section class="settings-panel" aria-label="Settings" data-tenant={access.tenant?.id}>
141
+ <StatusRegion {message} {error} />
142
+
143
+ {#if !access.can("read")}
144
+ <p class="note">You do not have permission to view settings.</p>
145
+ {:else if settings}
146
+ <div class="pause" class:paused={settings.paused}>
147
+ <Switch
148
+ label="Pause all publishing"
149
+ checked={settings.paused}
150
+ disabled={!canPause || pausing}
151
+ size="lg"
152
+ onchange={(event: Event) => setPaused((event.currentTarget as HTMLInputElement).checked)}
153
+ />
154
+ <p>
155
+ <strong>{settings.paused ? "Publishing is paused." : "Publishing is on."}</strong>
156
+ {settings.paused
157
+ ? "Nothing is sent to any platform until you resume. Takes effect immediately."
158
+ : "Approved and due posts are sent. Switch this on to stop everything immediately."}
159
+ </p>
160
+ </div>
161
+ {/if}
162
+
163
+ <h2 class="heading">Platforms and accounts</h2>
164
+ <SocialAccountSettings
165
+ {accounts}
166
+ {loading}
167
+ readonly={!canConfigure}
168
+ connectHrefs={{
169
+ youtube: `${socialSettingsBasePath}/connect/youtube`,
170
+ facebook: `${socialSettingsBasePath}/connect/facebook`,
171
+ threads: `${socialSettingsBasePath}/connect/threads`,
172
+ x: `${socialSettingsBasePath}/connect/x`,
173
+ }}
174
+ onRefresh={load}
175
+ onTest={testAccount}
176
+ onDeactivate={deactivateAccount}
177
+ />
178
+
179
+ {#if settings}
180
+ <form class="publishing" onsubmit={save}>
181
+ <h2 class="heading">Publishing</h2>
182
+
183
+ <div class="field">
184
+ <label for="settings-cap">Monthly spend cap (USD)</label>
185
+ <Input id="settings-cap" bind:value={capInput} inputmode="decimal" disabled={!canConfigure} />
186
+ <p class="hint">
187
+ Publishing stops for the rest of the UTC month when the cap is reached. A cap of $0.00
188
+ blocks all publishing. Current cap: {formatUsd(settings.monthlyCapMicros)}.
189
+ </p>
190
+ </div>
191
+
192
+ <div class="field">
193
+ <label for="settings-default-link">Default link policy</label>
194
+ <Select id="settings-default-link" bind:value={defaultLink} disabled={!canConfigure}>
195
+ <option value="none">No link (default)</option>
196
+ <option value="include">Include the source link</option>
197
+ </Select>
198
+ </div>
199
+
200
+ {#if accounts.length > 0}
201
+ <fieldset class="accounts" disabled={!canConfigure}>
202
+ <legend>Per account</legend>
203
+ <table>
204
+ <thead>
205
+ <tr>
206
+ <th scope="col">Account</th>
207
+ <th scope="col">Receives drafts</th>
208
+ <th scope="col">Link in post</th>
209
+ </tr>
210
+ </thead>
211
+ <tbody>
212
+ {#each accounts as account (account.id)}
213
+ <tr>
214
+ <th scope="row">{account.name} <span class="platform">({account.platform})</span></th>
215
+ <td>
216
+ <Checkbox
217
+ aria-label={`${account.name} receives drafts`}
218
+ checked={receives[account.id] ?? false}
219
+ onchange={(event: Event) =>
220
+ (receives[account.id] = (event.currentTarget as HTMLInputElement).checked)}
221
+ disabled={!canConfigure}
222
+ />
223
+ </td>
224
+ <td>
225
+ <Select
226
+ aria-label={`Link policy for ${account.name}`}
227
+ value={linkByAccount[account.id] ?? defaultLink}
228
+ onchange={(event: Event) =>
229
+ (linkByAccount[account.id] = (event.currentTarget as HTMLSelectElement)
230
+ .value as LinkPolicy)}
231
+ disabled={!canConfigure}
232
+ >
233
+ <option value="none">No link</option>
234
+ <option value="include">Include link</option>
235
+ </Select>
236
+ </td>
237
+ </tr>
238
+ {/each}
239
+ </tbody>
240
+ </table>
241
+ </fieldset>
242
+ {/if}
243
+
244
+ <p class="hint">
245
+ Posting cadence is set by how often the host runs the publish job; Garrula has no
246
+ per-account cadence setting yet.
247
+ </p>
248
+
249
+ {#if canConfigure}
250
+ <div class="actions">
251
+ <Button type="submit" variant="primary" disabled={saving}>Save publishing settings</Button>
252
+ </div>
253
+ {:else}
254
+ <Alert variant="info">View only: you do not have permission to change these settings.</Alert>
255
+ {/if}
256
+ </form>
257
+ {/if}
258
+ </section>
259
+
260
+ <style>
261
+ .settings-panel {
262
+ color: var(--smrt-color-on-surface, #111827);
263
+ display: grid;
264
+ gap: 1.25rem;
265
+ }
266
+
267
+ .heading {
268
+ font-size: 1.1rem;
269
+ margin: 0;
270
+ }
271
+
272
+ .pause {
273
+ align-items: center;
274
+ border: 2px solid var(--smrt-color-outline, #4b5563);
275
+ border-radius: var(--smrt-radius-lg, 8px);
276
+ display: grid;
277
+ gap: 0.5rem 1.5rem;
278
+ grid-template-columns: auto 1fr;
279
+ padding: 1rem 1.25rem;
280
+ }
281
+
282
+ .pause.paused {
283
+ border-color: var(--smrt-color-error, #b91c1c);
284
+ border-width: 3px;
285
+ }
286
+
287
+ .pause p {
288
+ margin: 0;
289
+ }
290
+
291
+ .publishing {
292
+ display: grid;
293
+ gap: 1rem;
294
+ }
295
+
296
+ .field {
297
+ display: grid;
298
+ gap: 0.35rem;
299
+ max-width: 28rem;
300
+ }
301
+
302
+ label,
303
+ legend {
304
+ font-size: 0.85rem;
305
+ font-weight: 600;
306
+ }
307
+
308
+ .hint,
309
+ .note {
310
+ color: var(--smrt-color-on-surface-variant, #4b5563);
311
+ font-size: 0.85rem;
312
+ margin: 0;
313
+ }
314
+
315
+ fieldset {
316
+ border: 1px solid var(--smrt-color-outline-variant, #6b7280);
317
+ border-radius: var(--smrt-radius-lg, 8px);
318
+ margin: 0;
319
+ overflow-x: auto;
320
+ padding: 0.75rem;
321
+ }
322
+
323
+ table {
324
+ border-collapse: collapse;
325
+ width: 100%;
326
+ }
327
+
328
+ th,
329
+ td {
330
+ padding: 0.5rem;
331
+ text-align: left;
332
+ }
333
+
334
+ .platform {
335
+ color: var(--smrt-color-on-surface-variant, #4b5563);
336
+ font-weight: 400;
337
+ }
338
+ </style>
@@ -0,0 +1,4 @@
1
+ import type { SettingsPanelProps } from "../types.js";
2
+ declare const SettingsPanel: import("svelte").Component<SettingsPanelProps, {}, "">;
3
+ type SettingsPanel = ReturnType<typeof SettingsPanel>;
4
+ export default SettingsPanel;