@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.
- 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 +2135 -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 +177 -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/types.d.ts +86 -0
- package/dist/ui/types.js +63 -0
- package/docs/manifest-routing.md +41 -0
- package/package.json +111 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { CreateSocialPostDraftOptions, PostStatus, RawAnalyticsPayload, SocialAccount as SmrtSocialAccount, SocialPost as SmrtSocialPost, SocialPlatformType } from '@happyvertical/smrt-social';
|
|
2
|
+
import { PostAnalytics as PlatformPostAnalytics, PostResult, SocialConfig, SocialPlatform as PlatformSocialPlatform } from '@happyvertical/social';
|
|
3
|
+
export type GarrulaTargetPlatform = "youtube" | "threads" | "x" | "facebook";
|
|
4
|
+
export type GarrulaPostType = "text" | "link" | "image" | "video";
|
|
5
|
+
export interface GarrulaPostAnalytics extends PlatformPostAnalytics {
|
|
6
|
+
impressions?: number;
|
|
7
|
+
raw?: unknown;
|
|
8
|
+
}
|
|
9
|
+
export type GarrulaSocialAccount = Omit<SmrtSocialAccount, "platform"> & {
|
|
10
|
+
platform: SocialPlatformType;
|
|
11
|
+
tenantId?: string | null;
|
|
12
|
+
defaultHashtags?: string[];
|
|
13
|
+
linkBehavior?: string | null;
|
|
14
|
+
publishMode?: string | null;
|
|
15
|
+
effectivePublishMode?: string | null;
|
|
16
|
+
getCredentials(): Promise<Record<string, unknown> | null>;
|
|
17
|
+
};
|
|
18
|
+
export type GarrulaSocialPost = Omit<SmrtSocialPost, "analytics"> & {
|
|
19
|
+
postType?: GarrulaPostType;
|
|
20
|
+
mediaUrl?: string | null;
|
|
21
|
+
analytics?: GarrulaPostAnalytics | null;
|
|
22
|
+
analyticsLastSyncedAt?: Date | string | null;
|
|
23
|
+
tenantId?: string | null;
|
|
24
|
+
};
|
|
25
|
+
export type GarrulaSocialConfig = SocialConfig;
|
|
26
|
+
export type GarrulaSocialAdapter = Omit<PlatformSocialPlatform, "platform" | "getAnalytics"> & {
|
|
27
|
+
platform: SocialPlatformType;
|
|
28
|
+
publishLink(post: {
|
|
29
|
+
url: string;
|
|
30
|
+
text?: string;
|
|
31
|
+
title?: string;
|
|
32
|
+
tags?: string[];
|
|
33
|
+
}): Promise<PostResult>;
|
|
34
|
+
getAnalytics(postId: string): Promise<GarrulaPostAnalytics>;
|
|
35
|
+
};
|
|
36
|
+
export interface StoryLinkPostRequest {
|
|
37
|
+
contentId: string;
|
|
38
|
+
title: string;
|
|
39
|
+
url: string;
|
|
40
|
+
excerpt?: string;
|
|
41
|
+
hashtags?: string[];
|
|
42
|
+
targets?: GarrulaTargetPlatform[];
|
|
43
|
+
scheduledAt?: Date | null;
|
|
44
|
+
/**
|
|
45
|
+
* Exact tenant id whose ready social accounts should receive drafts. Omit it
|
|
46
|
+
* to use the tenant of the current context (`withTenant`); a value that
|
|
47
|
+
* differs from an active context is refused.
|
|
48
|
+
*/
|
|
49
|
+
tenantId?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The signed-in person posting (smrt-users id), told if a publish fails.
|
|
52
|
+
* Hosts set it from their own session, never from a caller's payload.
|
|
53
|
+
*/
|
|
54
|
+
createdByUserId?: string | null;
|
|
55
|
+
}
|
|
56
|
+
export interface ArticleVideoPostRequest {
|
|
57
|
+
contentId: string;
|
|
58
|
+
/**
|
|
59
|
+
* Only post to these accounts (each must be a ready account of this tenant
|
|
60
|
+
* on one of the target platforms). Omit to post to every ready account.
|
|
61
|
+
*/
|
|
62
|
+
accountIds?: string[];
|
|
63
|
+
videoContentId?: string | null;
|
|
64
|
+
mediaUrl: string;
|
|
65
|
+
title: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
url?: string;
|
|
68
|
+
hashtags?: string[];
|
|
69
|
+
targets?: GarrulaTargetPlatform[];
|
|
70
|
+
scheduledAt?: Date | null;
|
|
71
|
+
/**
|
|
72
|
+
* Exact tenant id whose ready social accounts should receive drafts. Omit it
|
|
73
|
+
* to use the tenant of the current context (`withTenant`); a value that
|
|
74
|
+
* differs from an active context is refused.
|
|
75
|
+
*/
|
|
76
|
+
tenantId?: string;
|
|
77
|
+
/**
|
|
78
|
+
* The signed-in person posting (smrt-users id), told if a publish fails.
|
|
79
|
+
* Hosts set it from their own session, never from a caller's payload.
|
|
80
|
+
*/
|
|
81
|
+
createdByUserId?: string | null;
|
|
82
|
+
}
|
|
83
|
+
export interface PublishPostOptions {
|
|
84
|
+
/**
|
|
85
|
+
* Statuses the post may be claimed from. The claim is one conditional
|
|
86
|
+
* update, so two publishers can never both send the same post. Defaults to
|
|
87
|
+
* every status a post may be published from.
|
|
88
|
+
*/
|
|
89
|
+
claimFrom?: PostStatus[];
|
|
90
|
+
}
|
|
91
|
+
export interface PublishPostResult {
|
|
92
|
+
postId: string;
|
|
93
|
+
platform: SocialPlatformType | "unknown";
|
|
94
|
+
success: boolean;
|
|
95
|
+
platformPostId?: string;
|
|
96
|
+
platformUrl?: string;
|
|
97
|
+
error?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Set when the post was deliberately left untouched (not failed): its tenant
|
|
100
|
+
* may not publish right now, or another publisher already holds it.
|
|
101
|
+
*/
|
|
102
|
+
skipped?: "tenant-blocked" | "post-busy" | "refused";
|
|
103
|
+
/**
|
|
104
|
+
* Set with `skipped: "refused"`: the outbound gate (pause switch, spend cap,
|
|
105
|
+
* missing approval or evidence) stopped the publish before the platform was
|
|
106
|
+
* called. The post keeps its previous status.
|
|
107
|
+
*/
|
|
108
|
+
refusal?: {
|
|
109
|
+
code: string;
|
|
110
|
+
message: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export interface AnalyticsSyncResult {
|
|
114
|
+
checked: number;
|
|
115
|
+
updated: number;
|
|
116
|
+
failed: number;
|
|
117
|
+
skipped: number;
|
|
118
|
+
errors: string[];
|
|
119
|
+
}
|
|
120
|
+
export interface GarrulaListOptions {
|
|
121
|
+
where?: Record<string, unknown>;
|
|
122
|
+
orderBy?: string | string[];
|
|
123
|
+
limit?: number;
|
|
124
|
+
offset?: number;
|
|
125
|
+
include?: string[];
|
|
126
|
+
}
|
|
127
|
+
/** The one database call Garrula makes directly: a conditional update. */
|
|
128
|
+
export interface GarrulaClaimDatabase {
|
|
129
|
+
update(table: string, where: Record<string, unknown>, data: Record<string, unknown>): Promise<{
|
|
130
|
+
affected: number;
|
|
131
|
+
}>;
|
|
132
|
+
}
|
|
133
|
+
export interface GarrulaCollections {
|
|
134
|
+
socialAccounts: {
|
|
135
|
+
findReady(platform?: GarrulaTargetPlatform): Promise<GarrulaSocialAccount[]>;
|
|
136
|
+
get(criteria: {
|
|
137
|
+
id: string;
|
|
138
|
+
}): Promise<GarrulaSocialAccount | null>;
|
|
139
|
+
};
|
|
140
|
+
socialPosts: {
|
|
141
|
+
/** Database and table used for the atomic publish claim. */
|
|
142
|
+
readonly db: GarrulaClaimDatabase;
|
|
143
|
+
readonly tableName: string;
|
|
144
|
+
createDraft(data: CreateSocialPostDraftOptions): Promise<GarrulaSocialPost>;
|
|
145
|
+
/**
|
|
146
|
+
* Read one post fresh from the database. Used after the publish claim so
|
|
147
|
+
* the post's revision matches the row the claim just wrote.
|
|
148
|
+
*/
|
|
149
|
+
get(criteria: {
|
|
150
|
+
id: string;
|
|
151
|
+
}, options?: {
|
|
152
|
+
cache?: false;
|
|
153
|
+
}): Promise<GarrulaSocialPost | null>;
|
|
154
|
+
findDueForPublish(now?: Date): Promise<GarrulaSocialPost[]>;
|
|
155
|
+
list(options?: GarrulaListOptions): Promise<GarrulaSocialPost[]>;
|
|
156
|
+
recordPublishSuccess(post: GarrulaSocialPost, data: {
|
|
157
|
+
platformPostId: string;
|
|
158
|
+
platformUrl: string;
|
|
159
|
+
publishedAt?: Date;
|
|
160
|
+
status?: PostStatus;
|
|
161
|
+
}): Promise<GarrulaSocialPost>;
|
|
162
|
+
recordPublishFailure(post: GarrulaSocialPost, error: Error | string): Promise<GarrulaSocialPost>;
|
|
163
|
+
updateLatestAnalytics(post: GarrulaSocialPost, analytics: GarrulaPostAnalytics, syncedAt?: Date): Promise<GarrulaSocialPost>;
|
|
164
|
+
};
|
|
165
|
+
analyticsSnapshots: {
|
|
166
|
+
recordSnapshot(data: {
|
|
167
|
+
socialPostId: string;
|
|
168
|
+
platform: SocialPlatformType;
|
|
169
|
+
metrics: GarrulaPostAnalytics;
|
|
170
|
+
raw?: RawAnalyticsPayload;
|
|
171
|
+
capturedAt?: Date;
|
|
172
|
+
tenantId?: string | null;
|
|
173
|
+
}): Promise<unknown>;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export type SocialFactory = (account: GarrulaSocialAccount, credentials: Record<string, unknown>) => Promise<GarrulaSocialAdapter>;
|
|
177
|
+
/**
|
|
178
|
+
* Hooks the host application registers so Garrula can publish without knowing
|
|
179
|
+
* the host's media storage or tenant lifecycle rules.
|
|
180
|
+
*/
|
|
181
|
+
export interface GarrulaHost {
|
|
182
|
+
/**
|
|
183
|
+
* Return a URL the platform can fetch right now for the post's media (for
|
|
184
|
+
* example a freshly signed delivery URL), or null to use `post.mediaUrl`.
|
|
185
|
+
* The returned URL is used for this publish only and is never stored.
|
|
186
|
+
*/
|
|
187
|
+
resolveMediaUrl?(post: GarrulaSocialPost): Promise<string | null | undefined>;
|
|
188
|
+
/**
|
|
189
|
+
* Whether the tenant may publish now. Due posts of a tenant that may not
|
|
190
|
+
* publish are left scheduled and retried on a later run.
|
|
191
|
+
*/
|
|
192
|
+
canPublish?(tenantId: string): Promise<boolean>;
|
|
193
|
+
/**
|
|
194
|
+
* Called after a publish failure is recorded on the post, so the host can
|
|
195
|
+
* tell the person who posted it (`post.createdByUserId`). A failing hook is
|
|
196
|
+
* logged and never changes the publish result.
|
|
197
|
+
*/
|
|
198
|
+
onPublishFailed?(post: GarrulaSocialPost, error: string): Promise<void>;
|
|
199
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import { Button, Meter } from "@happyvertical/smrt-ui";
|
|
4
|
+
import {
|
|
5
|
+
SortableHeader,
|
|
6
|
+
sortListRows,
|
|
7
|
+
toggleListSort,
|
|
8
|
+
type ListSort,
|
|
9
|
+
type ListSortSpec,
|
|
10
|
+
} from "@happyvertical/smrt-ui/data";
|
|
11
|
+
import { Input } from "@happyvertical/smrt-ui/forms";
|
|
12
|
+
import { PageHeader } from "@happyvertical/smrt-ui/layout";
|
|
13
|
+
import type { SocialPost } from "@happyvertical/smrt-social";
|
|
14
|
+
import type { SpendEntryView, SpendSummary } from "../../outbound/types.js";
|
|
15
|
+
import type { ActivitySpendPanelProps } from "../types.js";
|
|
16
|
+
import StatusRegion from "./StatusRegion.svelte";
|
|
17
|
+
import { getGarrulaAdminContext, resolveAccess } from "./access.js";
|
|
18
|
+
import { errorMessage, formatDateTime, formatUsd } from "./format.js";
|
|
19
|
+
|
|
20
|
+
let { apiClient, readonly = false, tenant, permissions }: ActivitySpendPanelProps = $props();
|
|
21
|
+
|
|
22
|
+
const context = getGarrulaAdminContext();
|
|
23
|
+
const access = $derived(resolveAccess({ tenant, permissions, readonly }, context));
|
|
24
|
+
// Syncing analytics asks the platform for fresh numbers, so it is a publisher action.
|
|
25
|
+
const canSync = $derived(access.can("publish"));
|
|
26
|
+
|
|
27
|
+
let posts = $state<SocialPost[]>([]);
|
|
28
|
+
let spend = $state<SpendSummary | null>(null);
|
|
29
|
+
let month = $state("");
|
|
30
|
+
let loading = $state(true);
|
|
31
|
+
let error = $state<string | null>(null);
|
|
32
|
+
let message = $state("");
|
|
33
|
+
|
|
34
|
+
// Newest published first (drafts with no date last); headers re-order every post.
|
|
35
|
+
const SORT_SPEC: ListSortSpec = {
|
|
36
|
+
columns: [
|
|
37
|
+
"post",
|
|
38
|
+
"status",
|
|
39
|
+
{ id: "published", firstDirection: "desc" },
|
|
40
|
+
{ id: "cost", firstDirection: "desc" },
|
|
41
|
+
{ id: "views", firstDirection: "desc" },
|
|
42
|
+
{ id: "likes", firstDirection: "desc" },
|
|
43
|
+
{ id: "comments", firstDirection: "desc" },
|
|
44
|
+
{ id: "shares", firstDirection: "desc" },
|
|
45
|
+
{ id: "clicks", firstDirection: "desc" },
|
|
46
|
+
],
|
|
47
|
+
default: { columnId: "published", direction: "desc" },
|
|
48
|
+
};
|
|
49
|
+
let sort = $state<ListSort>(SORT_SPEC.default);
|
|
50
|
+
|
|
51
|
+
function postTitle(post: SocialPost): string {
|
|
52
|
+
return post.title || post.description || post.linkUrl || post.id || "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Cost entries that count (recorded or reserved) for a post, in the selected month. */
|
|
56
|
+
function entriesFor(postId: string | null | undefined): SpendEntryView[] {
|
|
57
|
+
if (!postId || !spend) return [];
|
|
58
|
+
return spend.entries.filter((e) => e.postId === postId && e.status !== "released");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function costMicros(postId: string | null | undefined): number | null {
|
|
62
|
+
const entries = entriesFor(postId);
|
|
63
|
+
return entries.length === 0 ? null : entries.reduce((sum, e) => sum + e.costMicros, 0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function costLabel(postId: string | null | undefined): string {
|
|
67
|
+
const entries = entriesFor(postId);
|
|
68
|
+
if (entries.length === 0) return "-";
|
|
69
|
+
const total = formatUsd(entries.reduce((sum, e) => sum + e.costMicros, 0));
|
|
70
|
+
if (entries.some((e) => e.source === "unpriced")) return `${total} (unpriced platform)`;
|
|
71
|
+
if (entries.some((e) => e.source === "rate-table")) return `${total} (estimated)`;
|
|
72
|
+
return total;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const sortedPosts = $derived(
|
|
76
|
+
sortListRows(posts, sort, (post, columnId) => {
|
|
77
|
+
switch (columnId) {
|
|
78
|
+
case "post":
|
|
79
|
+
return postTitle(post);
|
|
80
|
+
case "status":
|
|
81
|
+
return post.status;
|
|
82
|
+
case "published":
|
|
83
|
+
return post.publishedAt ?? null;
|
|
84
|
+
case "cost":
|
|
85
|
+
return costMicros(post.id);
|
|
86
|
+
case "views":
|
|
87
|
+
return post.analytics?.views ?? post.analytics?.impressions ?? null;
|
|
88
|
+
default:
|
|
89
|
+
return (
|
|
90
|
+
(post.analytics as Record<string, number | undefined> | undefined)?.[columnId] ?? null
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
function sortBy(columnId: string) {
|
|
97
|
+
sort = toggleListSort(sort, columnId, SORT_SPEC);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const percentUsed = $derived(
|
|
101
|
+
spend && spend.capMicros > 0 ? Math.round((spend.spentMicros / spend.capMicros) * 100) : null,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
async function load() {
|
|
105
|
+
loading = true;
|
|
106
|
+
error = null;
|
|
107
|
+
try {
|
|
108
|
+
[posts, spend] = await Promise.all([
|
|
109
|
+
apiClient.listSocialPosts(),
|
|
110
|
+
apiClient.getSpend(month || undefined),
|
|
111
|
+
]);
|
|
112
|
+
month = spend.month;
|
|
113
|
+
} catch (err) {
|
|
114
|
+
error = errorMessage(err);
|
|
115
|
+
} finally {
|
|
116
|
+
loading = false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function syncAnalytics(postId: string) {
|
|
121
|
+
error = null;
|
|
122
|
+
message = "";
|
|
123
|
+
try {
|
|
124
|
+
await apiClient.refreshPostAnalytics(postId);
|
|
125
|
+
posts = await apiClient.listSocialPosts();
|
|
126
|
+
message = "Analytics refreshed.";
|
|
127
|
+
} catch (err) {
|
|
128
|
+
error = errorMessage(err);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function metric(value: unknown): string {
|
|
133
|
+
return typeof value === "number" ? value.toLocaleString() : "-";
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
onMount(load);
|
|
137
|
+
</script>
|
|
138
|
+
|
|
139
|
+
<section class="activity" aria-label="Activity and spend" data-tenant={access.tenant?.id}>
|
|
140
|
+
<PageHeader
|
|
141
|
+
title="Activity and spend"
|
|
142
|
+
subtitle="Every post with what it cost and how it is doing, against this month's cap."
|
|
143
|
+
>
|
|
144
|
+
{#snippet actions()}
|
|
145
|
+
<Button variant="secondary" size="sm" onclick={load} disabled={loading}>Refresh</Button>
|
|
146
|
+
{/snippet}
|
|
147
|
+
</PageHeader>
|
|
148
|
+
|
|
149
|
+
<StatusRegion {message} {error} />
|
|
150
|
+
|
|
151
|
+
{#if !access.can("read")}
|
|
152
|
+
<p class="empty">You do not have permission to view activity.</p>
|
|
153
|
+
{:else if loading}
|
|
154
|
+
<p class="empty">Loading activity...</p>
|
|
155
|
+
{:else}
|
|
156
|
+
{#if spend}
|
|
157
|
+
<div class="spend">
|
|
158
|
+
<div class="month">
|
|
159
|
+
<label for="spend-month">Month (UTC)</label>
|
|
160
|
+
<Input id="spend-month" type="month" bind:value={month} onchange={load} />
|
|
161
|
+
</div>
|
|
162
|
+
{#if spend.capMicros > 0}
|
|
163
|
+
<!-- The native meter has no accessible name in smrt-ui yet; the summary below says the same. -->
|
|
164
|
+
<div aria-hidden="true">
|
|
165
|
+
<Meter
|
|
166
|
+
label="Spend this month"
|
|
167
|
+
value={Math.min(spend.spentMicros, spend.capMicros)}
|
|
168
|
+
max={spend.capMicros}
|
|
169
|
+
low={spend.capMicros * 0.8}
|
|
170
|
+
high={spend.capMicros * 0.9}
|
|
171
|
+
optimum={0}
|
|
172
|
+
formatValue={formatUsd}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
{/if}
|
|
176
|
+
<p class="summary">
|
|
177
|
+
<strong>{formatUsd(spend.spentMicros)}</strong> of
|
|
178
|
+
<strong>{formatUsd(spend.capMicros)}</strong> cap used in {spend.month}
|
|
179
|
+
{#if percentUsed !== null}({percentUsed}%){/if};
|
|
180
|
+
{formatUsd(spend.remainingMicros)} remaining.
|
|
181
|
+
{#if spend.capMicros === 0}
|
|
182
|
+
The cap is $0.00, so publishing is blocked.
|
|
183
|
+
{:else if spend.spentMicros >= spend.capMicros}
|
|
184
|
+
The cap is reached, so publishing is blocked until next month or the cap is raised.
|
|
185
|
+
{/if}
|
|
186
|
+
{#if spend.paused}Publishing is paused.{/if}
|
|
187
|
+
</p>
|
|
188
|
+
</div>
|
|
189
|
+
{/if}
|
|
190
|
+
|
|
191
|
+
{#if posts.length === 0}
|
|
192
|
+
<p class="empty">No posts yet.</p>
|
|
193
|
+
{:else}
|
|
194
|
+
<div class="table-wrap">
|
|
195
|
+
<table>
|
|
196
|
+
<caption class="sr-only">Posts with cost and analytics</caption>
|
|
197
|
+
<thead>
|
|
198
|
+
<tr>
|
|
199
|
+
<SortableHeader columnId="post" label="Post" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
200
|
+
<SortableHeader columnId="status" label="Status" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
201
|
+
<SortableHeader columnId="published" label="Published" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
202
|
+
<SortableHeader columnId="cost" label="Cost" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
203
|
+
<SortableHeader columnId="views" label="Views" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
204
|
+
<SortableHeader columnId="likes" label="Likes" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
205
|
+
<SortableHeader columnId="comments" label="Comments" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
206
|
+
<SortableHeader columnId="shares" label="Shares" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
207
|
+
<SortableHeader columnId="clicks" label="Clicks" {sort} spec={SORT_SPEC} onSort={sortBy} />
|
|
208
|
+
<th scope="col"><span class="sr-only">Actions</span></th>
|
|
209
|
+
</tr>
|
|
210
|
+
</thead>
|
|
211
|
+
<tbody>
|
|
212
|
+
{#each sortedPosts as post (post.id ?? post.platformPostId ?? post.title)}
|
|
213
|
+
<tr>
|
|
214
|
+
<td>
|
|
215
|
+
<strong>{postTitle(post)}</strong>
|
|
216
|
+
{#if post.platformUrl}
|
|
217
|
+
<a href={post.platformUrl} target="_blank" rel="noreferrer">{post.platformUrl}</a>
|
|
218
|
+
{:else if post.linkUrl}
|
|
219
|
+
<a href={post.linkUrl} target="_blank" rel="noreferrer">{post.linkUrl}</a>
|
|
220
|
+
{/if}
|
|
221
|
+
</td>
|
|
222
|
+
<td>{post.status}</td>
|
|
223
|
+
<td>{post.publishedAt ? formatDateTime(post.publishedAt) : "-"}</td>
|
|
224
|
+
<td>{costLabel(post.id)}</td>
|
|
225
|
+
<td>{metric(post.analytics?.views ?? post.analytics?.impressions)}</td>
|
|
226
|
+
<td>{metric(post.analytics?.likes)}</td>
|
|
227
|
+
<td>{metric(post.analytics?.comments)}</td>
|
|
228
|
+
<td>{metric(post.analytics?.shares)}</td>
|
|
229
|
+
<td>{metric(post.analytics?.clicks)}</td>
|
|
230
|
+
<td>
|
|
231
|
+
{#if post.status === "published" && canSync && post.id}
|
|
232
|
+
<Button
|
|
233
|
+
size="sm"
|
|
234
|
+
variant="secondary"
|
|
235
|
+
onclick={() => post.id && syncAnalytics(post.id)}
|
|
236
|
+
aria-label={`Sync analytics for ${postTitle(post)}`}
|
|
237
|
+
>Sync</Button>
|
|
238
|
+
{/if}
|
|
239
|
+
</td>
|
|
240
|
+
</tr>
|
|
241
|
+
{/each}
|
|
242
|
+
</tbody>
|
|
243
|
+
</table>
|
|
244
|
+
</div>
|
|
245
|
+
{/if}
|
|
246
|
+
{/if}
|
|
247
|
+
</section>
|
|
248
|
+
|
|
249
|
+
<style>
|
|
250
|
+
.activity {
|
|
251
|
+
color: var(--smrt-color-on-surface, #111827);
|
|
252
|
+
display: grid;
|
|
253
|
+
gap: 1rem;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.spend {
|
|
257
|
+
display: grid;
|
|
258
|
+
gap: 0.75rem;
|
|
259
|
+
max-width: 40rem;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.month {
|
|
263
|
+
display: grid;
|
|
264
|
+
gap: 0.35rem;
|
|
265
|
+
max-width: 14rem;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
label {
|
|
269
|
+
font-size: 0.85rem;
|
|
270
|
+
font-weight: 600;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.summary {
|
|
274
|
+
margin: 0;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
td,
|
|
278
|
+
table :global(th),
|
|
279
|
+
a {
|
|
280
|
+
font-size: 0.85rem;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
a {
|
|
284
|
+
color: var(--smrt-color-primary, #1d4ed8);
|
|
285
|
+
text-decoration: underline;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.table-wrap {
|
|
289
|
+
background: var(--smrt-color-surface, #ffffff);
|
|
290
|
+
border: 1px solid var(--smrt-color-outline-variant, #6b7280);
|
|
291
|
+
border-radius: var(--smrt-radius-lg, 8px);
|
|
292
|
+
overflow-x: auto;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
table {
|
|
296
|
+
border-collapse: collapse;
|
|
297
|
+
min-width: 100%;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
table :global(th),
|
|
301
|
+
td {
|
|
302
|
+
border-bottom: 1px solid var(--smrt-color-outline-variant, #d1d5db);
|
|
303
|
+
padding: 0.75rem;
|
|
304
|
+
text-align: left;
|
|
305
|
+
vertical-align: top;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
table :global(th) {
|
|
309
|
+
color: var(--smrt-color-on-surface, #111827);
|
|
310
|
+
font-weight: 600;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
td strong,
|
|
314
|
+
td a {
|
|
315
|
+
display: block;
|
|
316
|
+
max-width: 28rem;
|
|
317
|
+
overflow-wrap: anywhere;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.sr-only {
|
|
321
|
+
border: 0;
|
|
322
|
+
clip: rect(0 0 0 0);
|
|
323
|
+
height: 1px;
|
|
324
|
+
margin: -1px;
|
|
325
|
+
overflow: hidden;
|
|
326
|
+
padding: 0;
|
|
327
|
+
position: absolute;
|
|
328
|
+
white-space: nowrap;
|
|
329
|
+
width: 1px;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.empty {
|
|
333
|
+
border: 1px dashed var(--smrt-color-outline-variant, #6b7280);
|
|
334
|
+
border-radius: var(--smrt-radius-lg, 8px);
|
|
335
|
+
color: var(--smrt-color-on-surface-variant, #4b5563);
|
|
336
|
+
margin: 0;
|
|
337
|
+
padding: 1.25rem;
|
|
338
|
+
text-align: center;
|
|
339
|
+
}
|
|
340
|
+
</style>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AgentAdminRootProps } from "@happyvertical/smrt-agents/ui";
|
|
3
|
+
import type { AdminPermissions, AdminTenant, GarrulaAdminClient } from "../types.js";
|
|
4
|
+
import ActivitySpendPanel from "./ActivitySpendPanel.svelte";
|
|
5
|
+
import PersonaPolicyPanel from "./PersonaPolicyPanel.svelte";
|
|
6
|
+
import QueuePanel from "./QueuePanel.svelte";
|
|
7
|
+
import SettingsPanel from "./SettingsPanel.svelte";
|
|
8
|
+
import SourcesPanel from "./SourcesPanel.svelte";
|
|
9
|
+
import { setGarrulaAdminContext } from "./access.js";
|
|
10
|
+
import { navItems } from "./nav.js";
|
|
11
|
+
import { Tabs } from "@happyvertical/smrt-ui";
|
|
12
|
+
|
|
13
|
+
const DEFAULT_PANEL = "queue";
|
|
14
|
+
|
|
15
|
+
interface Props extends AgentAdminRootProps {
|
|
16
|
+
tenant?: AdminTenant;
|
|
17
|
+
permissions?: AdminPermissions;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
apiClient,
|
|
22
|
+
activePanel = DEFAULT_PANEL,
|
|
23
|
+
onNavigate,
|
|
24
|
+
readonly = false,
|
|
25
|
+
tenant,
|
|
26
|
+
permissions,
|
|
27
|
+
}: Props = $props();
|
|
28
|
+
|
|
29
|
+
// Panels read tenant and permissions from this context, so they follow the props.
|
|
30
|
+
const shared = {
|
|
31
|
+
get tenant() {
|
|
32
|
+
return tenant;
|
|
33
|
+
},
|
|
34
|
+
get permissions() {
|
|
35
|
+
return permissions;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
setGarrulaAdminContext(shared);
|
|
39
|
+
|
|
40
|
+
const client = $derived(apiClient as GarrulaAdminClient);
|
|
41
|
+
const panels = {
|
|
42
|
+
queue: QueuePanel,
|
|
43
|
+
persona: PersonaPolicyPanel,
|
|
44
|
+
sources: SourcesPanel,
|
|
45
|
+
activity: ActivitySpendPanel,
|
|
46
|
+
settings: SettingsPanel,
|
|
47
|
+
} as const;
|
|
48
|
+
type PanelId = keyof typeof panels;
|
|
49
|
+
|
|
50
|
+
const resolvedPanel = $derived<PanelId>(
|
|
51
|
+
activePanel in panels ? (activePanel as PanelId) : DEFAULT_PANEL,
|
|
52
|
+
);
|
|
53
|
+
const CurrentPanel = $derived(panels[resolvedPanel]);
|
|
54
|
+
const tabs = navItems.map((item) => ({ id: item.id, label: item.label }));
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<div class="admin-root" data-tenant={tenant?.id}>
|
|
58
|
+
<Tabs {tabs} active={resolvedPanel} aria-label="Social media sections" onchange={(id) => onNavigate?.(id)}>
|
|
59
|
+
{#key `${tenant?.id ?? ""}:${resolvedPanel}`}
|
|
60
|
+
<CurrentPanel apiClient={client} {readonly} />
|
|
61
|
+
{/key}
|
|
62
|
+
</Tabs>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<style>
|
|
66
|
+
.admin-root {
|
|
67
|
+
display: grid;
|
|
68
|
+
gap: 1rem;
|
|
69
|
+
}
|
|
70
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AgentAdminRootProps } from "@happyvertical/smrt-agents/ui";
|
|
2
|
+
import type { AdminPermissions, AdminTenant } from "../types.js";
|
|
3
|
+
interface Props extends AgentAdminRootProps {
|
|
4
|
+
tenant?: AdminTenant;
|
|
5
|
+
permissions?: AdminPermissions;
|
|
6
|
+
}
|
|
7
|
+
declare const AdminRoot: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type AdminRoot = ReturnType<typeof AdminRoot>;
|
|
9
|
+
export default AdminRoot;
|