@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,196 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import { Alert, Button } from "@happyvertical/smrt-ui";
4
+ import { Switch, Textarea } from "@happyvertical/smrt-ui/forms";
5
+ import { PageHeader } from "@happyvertical/smrt-ui/layout";
6
+ import type { SourceEventKind, SourceRule } from "../../outbound/types.js";
7
+ import type { SourcesPanelProps } from "../types.js";
8
+ import StatusRegion from "./StatusRegion.svelte";
9
+ import { getGarrulaAdminContext, resolveAccess } from "./access.js";
10
+ import { errorMessage, parseLines } from "./format.js";
11
+
12
+ let { apiClient, readonly = false, tenant, permissions }: SourcesPanelProps = $props();
13
+
14
+ const context = getGarrulaAdminContext();
15
+ const access = $derived(resolveAccess({ tenant, permissions, readonly }, context));
16
+ const canConfigure = $derived(access.can("configure"));
17
+
18
+ const KIND_LABELS: Record<SourceEventKind, string> = {
19
+ "package-publish": "Package publishes",
20
+ "merged-pr": "Merged pull requests",
21
+ "docs-change": "Documentation changes",
22
+ };
23
+
24
+ interface RuleForm {
25
+ kind: SourceEventKind;
26
+ postKind: SourceRule["postKind"];
27
+ enabled: boolean;
28
+ includeTitle: string;
29
+ excludeTitle: string;
30
+ includeLabels: string;
31
+ excludeLabels: string;
32
+ }
33
+
34
+ let rules = $state<RuleForm[]>([]);
35
+ let loaded = $state(false);
36
+ let error = $state<string | null>(null);
37
+ let message = $state("");
38
+ let saving = $state(false);
39
+
40
+ const toForm = (rule: SourceRule): RuleForm => ({
41
+ kind: rule.kind,
42
+ postKind: rule.postKind,
43
+ enabled: rule.enabled !== false,
44
+ includeTitle: (rule.includeTitle ?? []).join("\n"),
45
+ excludeTitle: (rule.excludeTitle ?? []).join("\n"),
46
+ includeLabels: (rule.includeLabels ?? []).join("\n"),
47
+ excludeLabels: (rule.excludeLabels ?? []).join("\n"),
48
+ });
49
+
50
+ function toRule(form: RuleForm): SourceRule {
51
+ const rule: SourceRule = { kind: form.kind, postKind: form.postKind, enabled: form.enabled };
52
+ for (const key of ["includeTitle", "excludeTitle", "includeLabels", "excludeLabels"] as const) {
53
+ const lines = parseLines(form[key]);
54
+ if (lines.length > 0) rule[key] = lines;
55
+ }
56
+ return rule;
57
+ }
58
+
59
+ async function load() {
60
+ error = null;
61
+ try {
62
+ rules = (await apiClient.getSettings()).sources.map(toForm);
63
+ loaded = true;
64
+ } catch (err) {
65
+ error = errorMessage(err);
66
+ }
67
+ }
68
+
69
+ /** Title patterns are regular expressions; the server ignores a bad one silently, so refuse here. */
70
+ function firstBadPattern(): string | null {
71
+ for (const form of rules) {
72
+ for (const pattern of [...parseLines(form.includeTitle), ...parseLines(form.excludeTitle)]) {
73
+ try {
74
+ new RegExp(pattern, "i");
75
+ } catch {
76
+ return `${KIND_LABELS[form.kind]}: "${pattern}" is not a valid regular expression.`;
77
+ }
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+
83
+ async function save(event: SubmitEvent) {
84
+ event.preventDefault();
85
+ error = null;
86
+ message = "";
87
+ const bad = firstBadPattern();
88
+ if (bad) {
89
+ error = bad;
90
+ return;
91
+ }
92
+ saving = true;
93
+ try {
94
+ rules = (await apiClient.updateSettings({ sources: rules.map(toRule) })).sources.map(toForm);
95
+ message = "Sources saved.";
96
+ } catch (err) {
97
+ error = errorMessage(err);
98
+ } finally {
99
+ saving = false;
100
+ }
101
+ }
102
+
103
+ onMount(load);
104
+ </script>
105
+
106
+ <section class="sources" aria-label="Sources" data-tenant={access.tenant?.id}>
107
+ <PageHeader
108
+ title="Sources"
109
+ subtitle="Which release and changelog events become draft candidates. An event that matches no enabled rule produces nothing."
110
+ />
111
+ <StatusRegion {message} {error} />
112
+
113
+ {#if !access.can("read")}
114
+ <p class="hint">You do not have permission to view this.</p>
115
+ {:else if loaded}
116
+ <form onsubmit={save}>
117
+ {#each rules as rule, index (index)}
118
+ <fieldset disabled={!canConfigure}>
119
+ <legend>{KIND_LABELS[rule.kind]} (posts as {rule.postKind})</legend>
120
+ <Switch label="Produce draft candidates" bind:checked={rule.enabled} />
121
+ <div class="grid">
122
+ <div class="field">
123
+ <label for="src-{index}-it">Title must match one of (regular expressions, one per line)</label>
124
+ <Textarea id="src-{index}-it" bind:value={rule.includeTitle} rows={3} />
125
+ </div>
126
+ <div class="field">
127
+ <label for="src-{index}-et">Ignore titles matching (regular expressions)</label>
128
+ <Textarea id="src-{index}-et" bind:value={rule.excludeTitle} rows={3} />
129
+ </div>
130
+ <div class="field">
131
+ <label for="src-{index}-il">Require one of these labels</label>
132
+ <Textarea id="src-{index}-il" bind:value={rule.includeLabels} rows={3} />
133
+ </div>
134
+ <div class="field">
135
+ <label for="src-{index}-el">Ignore events with these labels</label>
136
+ <Textarea id="src-{index}-el" bind:value={rule.excludeLabels} rows={3} />
137
+ </div>
138
+ </div>
139
+ </fieldset>
140
+ {:else}
141
+ <p class="hint">No source rules are configured, so no event produces a draft.</p>
142
+ {/each}
143
+
144
+ {#if canConfigure}
145
+ {#if rules.length > 0}
146
+ <div class="actions">
147
+ <Button type="submit" variant="primary" disabled={saving}>Save sources</Button>
148
+ </div>
149
+ {/if}
150
+ {:else}
151
+ <Alert variant="info">View only: you do not have permission to change sources.</Alert>
152
+ {/if}
153
+ </form>
154
+ {/if}
155
+ </section>
156
+
157
+ <style>
158
+ .sources,
159
+ form {
160
+ color: var(--smrt-color-on-surface, #111827);
161
+ display: grid;
162
+ gap: 1rem;
163
+ }
164
+
165
+ fieldset {
166
+ border: 1px solid var(--smrt-color-outline-variant, #6b7280);
167
+ border-radius: var(--smrt-radius-lg, 8px);
168
+ display: grid;
169
+ gap: 0.75rem;
170
+ margin: 0;
171
+ padding: 0.75rem;
172
+ }
173
+
174
+ .grid {
175
+ display: grid;
176
+ gap: 0.75rem;
177
+ grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
178
+ }
179
+
180
+ .field {
181
+ display: grid;
182
+ gap: 0.35rem;
183
+ }
184
+
185
+ label,
186
+ legend {
187
+ font-size: 0.85rem;
188
+ font-weight: 600;
189
+ }
190
+
191
+ .hint {
192
+ color: var(--smrt-color-on-surface-variant, #4b5563);
193
+ font-size: 0.85rem;
194
+ margin: 0;
195
+ }
196
+ </style>
@@ -0,0 +1,3 @@
1
+ declare const SourcesPanel: import("svelte").Component<import("./index.js").AdminPanelBaseProps, {}, "">;
2
+ type SourcesPanel = ReturnType<typeof SourcesPanel>;
3
+ export default SourcesPanel;
@@ -0,0 +1,41 @@
1
+ <script lang="ts">
2
+ /**
3
+ * One live region per panel: polite status text for what just happened and an
4
+ * assertive alert for failures. Always rendered so screen readers register the
5
+ * region before its text changes.
6
+ */
7
+ let { message = "", error = null }: { message?: string; error?: string | null } = $props();
8
+ </script>
9
+
10
+ <div class="status-region">
11
+ <p class="status" role="status" aria-live="polite">{message}</p>
12
+ <p class="alert" role="alert">{error ?? ""}</p>
13
+ </div>
14
+
15
+ <style>
16
+ .status-region p {
17
+ margin: 0;
18
+ }
19
+
20
+ .status:not(:empty),
21
+ .alert:not(:empty) {
22
+ border-radius: var(--smrt-radius-md, 8px);
23
+ font-size: 0.9rem;
24
+ padding: 0.5rem 0.75rem;
25
+ }
26
+
27
+ .status:not(:empty) {
28
+ border: 1px solid var(--smrt-color-outline-variant, #6b7280);
29
+ color: var(--smrt-color-on-surface, #111827);
30
+ }
31
+
32
+ .alert:not(:empty) {
33
+ border: 1px solid var(--smrt-color-error, #b91c1c);
34
+ color: var(--smrt-color-error, #b91c1c);
35
+ }
36
+
37
+ .alert:not(:empty)::before {
38
+ content: "Error: ";
39
+ font-weight: 600;
40
+ }
41
+ </style>
@@ -0,0 +1,7 @@
1
+ type $$ComponentProps = {
2
+ message?: string;
3
+ error?: string | null;
4
+ };
5
+ declare const StatusRegion: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type StatusRegion = ReturnType<typeof StatusRegion>;
7
+ export default StatusRegion;
@@ -0,0 +1,23 @@
1
+ import { type AdminPermission, type AdminPermissions, type AdminTenant } from "../types.js";
2
+ export interface GarrulaAdminContext {
3
+ tenant?: AdminTenant;
4
+ permissions?: AdminPermissions;
5
+ }
6
+ /** Hosts (and AdminRoot) call this once; every panel below reads it. */
7
+ export declare function setGarrulaAdminContext(context: GarrulaAdminContext): void;
8
+ /** Read the shared context. Call during component initialisation. */
9
+ export declare function getGarrulaAdminContext(): GarrulaAdminContext;
10
+ export interface AdminAccess {
11
+ tenant: AdminTenant | undefined;
12
+ can(permission: AdminPermission): boolean;
13
+ }
14
+ /**
15
+ * Props win over context. No permissions anywhere means everything is allowed
16
+ * (the server still enforces); `readonly` always narrows to `read`.
17
+ * Pause (publish) is also allowed to `configure`: it is a safety control.
18
+ */
19
+ export declare function resolveAccess(props: {
20
+ tenant?: AdminTenant;
21
+ permissions?: AdminPermissions;
22
+ readonly?: boolean;
23
+ }, context: GarrulaAdminContext): AdminAccess;
@@ -0,0 +1,30 @@
1
+ import { getContext, setContext } from "svelte";
2
+ import { ADMIN_PERMISSIONS, } from "../types.js";
3
+ const CONTEXT_KEY = Symbol.for("@happyvertical/garrula/admin");
4
+ /** Hosts (and AdminRoot) call this once; every panel below reads it. */
5
+ export function setGarrulaAdminContext(context) {
6
+ setContext(CONTEXT_KEY, context);
7
+ }
8
+ /** Read the shared context. Call during component initialisation. */
9
+ export function getGarrulaAdminContext() {
10
+ return getContext(CONTEXT_KEY) ?? {};
11
+ }
12
+ /**
13
+ * Props win over context. No permissions anywhere means everything is allowed
14
+ * (the server still enforces); `readonly` always narrows to `read`.
15
+ * Pause (publish) is also allowed to `configure`: it is a safety control.
16
+ */
17
+ export function resolveAccess(props, context) {
18
+ const supplied = props.permissions ?? context.permissions;
19
+ const granted = new Set(supplied ?? ADMIN_PERMISSIONS);
20
+ if (props.readonly) {
21
+ for (const permission of [...granted])
22
+ if (permission !== "read")
23
+ granted.delete(permission);
24
+ granted.add("read");
25
+ }
26
+ return {
27
+ tenant: props.tenant ?? context.tenant,
28
+ can: (permission) => granted.has(permission),
29
+ };
30
+ }
@@ -0,0 +1,9 @@
1
+ export declare function formatUsd(micros: number): string;
2
+ /** Dollars typed by a person to whole micro-dollars; null when not a number >= 0. */
3
+ export declare function usdToMicros(input: string): number | null;
4
+ export declare function microsToUsdInput(micros: number): string;
5
+ /** Dates may arrive as ISO strings from the host's transport. */
6
+ export declare function formatDateTime(value: Date | string | null | undefined): string;
7
+ export declare function errorMessage(error: unknown): string;
8
+ /** One entry per line to a list, blanks dropped. */
9
+ export declare function parseLines(text: string): string[];
@@ -0,0 +1,39 @@
1
+ const MICROS = 1_000_000;
2
+ export function formatUsd(micros) {
3
+ const dollars = micros / MICROS;
4
+ return dollars.toLocaleString("en-US", {
5
+ style: "currency",
6
+ currency: "USD",
7
+ minimumFractionDigits: 2,
8
+ maximumFractionDigits: dollars !== 0 && Math.abs(dollars) < 1 ? 4 : 2,
9
+ });
10
+ }
11
+ /** Dollars typed by a person to whole micro-dollars; null when not a number >= 0. */
12
+ export function usdToMicros(input) {
13
+ const value = Number(input.trim().replace(/^\$/, ""));
14
+ if (input.trim() === "" || !Number.isFinite(value) || value < 0)
15
+ return null;
16
+ return Math.round(value * MICROS);
17
+ }
18
+ export function microsToUsdInput(micros) {
19
+ return (micros / MICROS).toFixed(2);
20
+ }
21
+ /** Dates may arrive as ISO strings from the host's transport. */
22
+ export function formatDateTime(value) {
23
+ if (!value)
24
+ return "-";
25
+ const date = value instanceof Date ? value : new Date(value);
26
+ return Number.isNaN(date.getTime())
27
+ ? "-"
28
+ : date.toLocaleString("en-US", { timeZone: "UTC" }) + " UTC";
29
+ }
30
+ export function errorMessage(error) {
31
+ return error instanceof Error ? error.message : String(error);
32
+ }
33
+ /** One entry per line to a list, blanks dropped. */
34
+ export function parseLines(text) {
35
+ return text
36
+ .split("\n")
37
+ .map((line) => line.trim())
38
+ .filter(Boolean);
39
+ }
@@ -0,0 +1,12 @@
1
+ import ActivitySpendPanel from "./ActivitySpendPanel.svelte";
2
+ import AdminRoot from "./AdminRoot.svelte";
3
+ import PersonaPolicyPanel from "./PersonaPolicyPanel.svelte";
4
+ import QueuePanel from "./QueuePanel.svelte";
5
+ import SettingsPanel from "./SettingsPanel.svelte";
6
+ import SourcesPanel from "./SourcesPanel.svelte";
7
+ export default AdminRoot;
8
+ export { navItems } from "./nav.js";
9
+ export { getGarrulaAdminContext, resolveAccess, setGarrulaAdminContext, type AdminAccess, type GarrulaAdminContext, } from "./access.js";
10
+ export { ActivitySpendPanel, AdminRoot, PersonaPolicyPanel, QueuePanel, SettingsPanel, SourcesPanel, };
11
+ export { ADMIN_PERMISSIONS, createAPIClient } from "../types.js";
12
+ export type { ActivitySpendPanelProps, AdminPanelBaseProps, AdminPermission, AdminPermissions, AdminTenant, GarrulaAdminClient, GarrulaOutboundAdminClient, GarrulaSocialAdminClient, PersonaPolicyPanelProps, QueuePanelProps, SettingsPanelProps, SourcesPanelProps, } from "../types.js";
@@ -0,0 +1,17 @@
1
+ import { AgentUIRegistry } from "@happyvertical/smrt-agents/ui";
2
+ import ActivitySpendPanel from "./ActivitySpendPanel.svelte";
3
+ import AdminRoot from "./AdminRoot.svelte";
4
+ import PersonaPolicyPanel from "./PersonaPolicyPanel.svelte";
5
+ import QueuePanel from "./QueuePanel.svelte";
6
+ import SettingsPanel from "./SettingsPanel.svelte";
7
+ import SourcesPanel from "./SourcesPanel.svelte";
8
+ export default AdminRoot;
9
+ export { navItems } from "./nav.js";
10
+ export { getGarrulaAdminContext, resolveAccess, setGarrulaAdminContext, } from "./access.js";
11
+ export { ActivitySpendPanel, AdminRoot, PersonaPolicyPanel, QueuePanel, SettingsPanel, SourcesPanel, };
12
+ export { ADMIN_PERMISSIONS, createAPIClient } from "../types.js";
13
+ AgentUIRegistry.register("Garrula", "queue", QueuePanel);
14
+ AgentUIRegistry.register("Garrula", "persona", PersonaPolicyPanel);
15
+ AgentUIRegistry.register("Garrula", "sources", SourcesPanel);
16
+ AgentUIRegistry.register("Garrula", "activity", ActivitySpendPanel);
17
+ AgentUIRegistry.register("Garrula", "settings", SettingsPanel);
@@ -0,0 +1,2 @@
1
+ import type { AgentAdminNavItem } from "@happyvertical/smrt-agents/ui";
2
+ export declare const navItems: AgentAdminNavItem[];
@@ -0,0 +1,7 @@
1
+ export const navItems = [
2
+ { id: "queue", label: "Queue", icon: "list-checks", order: 1 },
3
+ { id: "persona", label: "Persona and policy", icon: "user-round", order: 2 },
4
+ { id: "sources", label: "Sources", icon: "rss", order: 3 },
5
+ { id: "activity", label: "Activity and spend", icon: "chart-line", order: 4 },
6
+ { id: "settings", label: "Settings", icon: "settings", order: 5 },
7
+ ];
@@ -0,0 +1,86 @@
1
+ import type { SocialPost } from "@happyvertical/smrt-social";
2
+ import type { SocialAccountSettingsItem } from "@happyvertical/smrt-social/svelte";
3
+ import type { OutboundDraft, OutboundPostKind, OutboundSettings, OutboundSettingsPatch, OutboundState, SpendSummary } from "../outbound/types.js";
4
+ /**
5
+ * What the signed-in person may do. UI gating is a convenience only: the host
6
+ * (and Garrula's server API) enforce the same rules on every call.
7
+ *
8
+ * - `read`: see drafts, settings, activity and spend.
9
+ * - `approve`: edit, approve, reject and retry drafts.
10
+ * - `publish`: schedule approved posts; flip the pause switch.
11
+ * - `configure`: change accounts, link policy, cap, persona, autonomy, sources.
12
+ */
13
+ export type AdminPermission = "read" | "approve" | "publish" | "configure";
14
+ export declare const ADMIN_PERMISSIONS: readonly AdminPermission[];
15
+ export type AdminPermissions = ReadonlySet<AdminPermission> | readonly AdminPermission[];
16
+ /** The tenant the panels act for. The host's client is already bound to it. */
17
+ export interface AdminTenant {
18
+ id: string;
19
+ name?: string;
20
+ }
21
+ /**
22
+ * The outbound half of the client: the Garrula public API (`listDrafts`,
23
+ * `approve`, ...), tenant-bound by the host. The host supplies the
24
+ * implementation (route handlers, remote functions, fetch); this package owns
25
+ * no endpoints for it. Dates may arrive as ISO strings.
26
+ */
27
+ export interface GarrulaOutboundAdminClient {
28
+ listDrafts(filter?: {
29
+ state?: OutboundState;
30
+ kind?: OutboundPostKind;
31
+ limit?: number;
32
+ }): Promise<OutboundDraft[]>;
33
+ editDraft(id: string, patch: {
34
+ text?: string;
35
+ }): Promise<OutboundDraft>;
36
+ approveDraft(id: string): Promise<OutboundDraft>;
37
+ rejectDraft(id: string, reason?: string): Promise<OutboundDraft>;
38
+ retryDraft(id: string): Promise<OutboundDraft>;
39
+ scheduleDraft(id: string, at: Date): Promise<OutboundDraft>;
40
+ getSettings(): Promise<OutboundSettings>;
41
+ updateSettings(patch: OutboundSettingsPatch): Promise<OutboundSettings>;
42
+ /** `month` is `YYYY-MM` (UTC); default this month. */
43
+ getSpend(month?: string): Promise<SpendSummary>;
44
+ }
45
+ export interface GarrulaSocialAdminClient {
46
+ listSocialPosts(filter?: {
47
+ status?: string;
48
+ }): Promise<SocialPost[]>;
49
+ listSocialAccounts(filter?: {
50
+ platform?: string;
51
+ isActive?: boolean;
52
+ }): Promise<SocialAccountSettingsItem[]>;
53
+ refreshPostAnalytics(postId: string): Promise<SocialPost>;
54
+ testSocialAccount(accountId: string): Promise<{
55
+ ok: boolean;
56
+ message: string;
57
+ }>;
58
+ deactivateSocialAccount(accountId: string): Promise<SocialAccountSettingsItem>;
59
+ }
60
+ export interface GarrulaAdminClient extends GarrulaOutboundAdminClient, GarrulaSocialAdminClient {
61
+ }
62
+ export interface AdminPanelBaseProps {
63
+ apiClient: GarrulaAdminClient;
64
+ /** Shorthand for `permissions: ["read"]`. */
65
+ readonly?: boolean;
66
+ /** Overrides the tenant from context. */
67
+ tenant?: AdminTenant;
68
+ /**
69
+ * Overrides the permissions from context. With neither supplied, everything
70
+ * is allowed (the host's server still enforces); `readonly` narrows to `read`.
71
+ */
72
+ permissions?: AdminPermissions;
73
+ }
74
+ export type QueuePanelProps = AdminPanelBaseProps;
75
+ export type PersonaPolicyPanelProps = AdminPanelBaseProps;
76
+ export type SourcesPanelProps = AdminPanelBaseProps;
77
+ export type ActivitySpendPanelProps = AdminPanelBaseProps;
78
+ export interface SettingsPanelProps extends AdminPanelBaseProps {
79
+ socialSettingsBasePath?: string;
80
+ }
81
+ /**
82
+ * Builds a client from the social REST routes at `baseUrl` (accounts, posts,
83
+ * analytics) plus the host's own outbound implementation, because outbound
84
+ * routing belongs to the host (see docs/manifest-routing.md).
85
+ */
86
+ export declare function createAPIClient(baseUrl: string, outbound: GarrulaOutboundAdminClient): GarrulaAdminClient;
@@ -0,0 +1,63 @@
1
+ export const ADMIN_PERMISSIONS = [
2
+ "read",
3
+ "approve",
4
+ "publish",
5
+ "configure",
6
+ ];
7
+ /**
8
+ * Builds a client from the social REST routes at `baseUrl` (accounts, posts,
9
+ * analytics) plus the host's own outbound implementation, because outbound
10
+ * routing belongs to the host (see docs/manifest-routing.md).
11
+ */
12
+ export function createAPIClient(baseUrl, outbound) {
13
+ async function request(endpoint, options) {
14
+ const res = await fetch(`${baseUrl}${endpoint}`, {
15
+ method: options?.method ?? "GET",
16
+ headers: options?.body ? { "Content-Type": "application/json" } : {},
17
+ body: options?.body ? JSON.stringify(options.body) : undefined,
18
+ });
19
+ if (!res.ok) {
20
+ const errorData = (await res
21
+ .json()
22
+ .catch(() => ({ error: { message: res.statusText } })));
23
+ throw new Error(errorData.error?.message ?? errorData.message ?? "API request failed");
24
+ }
25
+ if (res.status === 204) {
26
+ return undefined;
27
+ }
28
+ return res.json();
29
+ }
30
+ return {
31
+ ...outbound,
32
+ async listSocialPosts(filter) {
33
+ const params = new URLSearchParams();
34
+ if (filter?.status)
35
+ params.set("status", filter.status);
36
+ const qs = params.toString();
37
+ const res = await request(`/social-posts${qs ? `?${qs}` : ""}`);
38
+ return res.data;
39
+ },
40
+ async listSocialAccounts(filter) {
41
+ const params = new URLSearchParams();
42
+ if (filter?.platform)
43
+ params.set("platform", filter.platform);
44
+ if (filter?.isActive !== undefined)
45
+ params.set("isActive", String(filter.isActive));
46
+ const qs = params.toString();
47
+ const res = await request(`/social-accounts${qs ? `?${qs}` : ""}`);
48
+ return res.data;
49
+ },
50
+ async refreshPostAnalytics(postId) {
51
+ const res = await request(`/social-posts/${encodeURIComponent(postId)}/analytics`, { method: "POST" });
52
+ return res.data;
53
+ },
54
+ async testSocialAccount(accountId) {
55
+ const res = await request(`/social-accounts/${encodeURIComponent(accountId)}/test`, { method: "POST" });
56
+ return res.data;
57
+ },
58
+ async deactivateSocialAccount(accountId) {
59
+ const res = await request(`/social-accounts/${encodeURIComponent(accountId)}/deactivate`, { method: "POST" });
60
+ return res.data;
61
+ },
62
+ };
63
+ }
@@ -0,0 +1,41 @@
1
+ # Can a host route Garrula's actions from the SMRT manifest?
2
+
3
+ Short answer: partly. Checked against `@happyvertical/smrt-core`/`smrt-agents`/
4
+ `smrt-social` 0.60.16 and the `dist/manifest.json` this package builds.
5
+
6
+ **What the manifest does expose.** `dist/manifest.json` (exported as
7
+ `@happyvertical/garrula/manifest`) lists `Garrula`'s methods (`run`,
8
+ `syncAnalytics`, `createStoryLinkPosts`, `createArticleVideoPosts`,
9
+ `publishPost`), its `agent` block (UI slots, `adminRoutes`, `menuItems`, one
10
+ `execute:<method>` permission per action, and the `./admin` component export
11
+ paths), and the generated surfaces: `mcp.include` produces MCP tools for the two
12
+ `create*Posts` methods, and `cli.include` produces CLI commands for `run` and
13
+ `syncAnalytics` (both in-process, hence `cli.skipApiCheck`).
14
+
15
+ **What it does not expose: REST.** `Garrula` sets no `api` config, so it inherits
16
+ the `Agent` base's closed `api: false` (`decoratorConfig.api === false` in the
17
+ manifest). No route is generated for any Garrula action; a host cannot reach them
18
+ over HTTP from the manifest alone. In smrt-agents the route map
19
+ (`buildRouteMap`) is built only from objects whose `decoratorConfig.api.include`
20
+ is set, and the `AgentActionHandler` map used for custom actions is hand-written
21
+ by the host.
22
+
23
+ **Admin UI endpoints.** The admin client (`createAPIClient`) needs
24
+ `/social-posts` and `/social-accounts` list/get: those exist as generated CRUD
25
+ because `smrt-social`'s `SocialPost`/`SocialAccount` declare
26
+ `api.include: [list, get, create, update, delete]`. The three action endpoints
27
+ (`POST /social-posts/:id/analytics`, `POST /social-accounts/:id/test`, `POST
28
+ /social-accounts/:id/deactivate`) are not in `smrt-social`'s manifest (its
29
+ `SocialPost` has no public methods and `SocialAccount` only credential
30
+ accessors), so the host must still provide them.
31
+
32
+ **Path to no hand-written endpoints (not done here).** `@smrt({ api: { include:
33
+ [...], routes: { createStoryLinkPosts: { scope: 'collection', effect: 'write' } }
34
+ } })` is accepted by the scanner and lands in the manifest (verified by a
35
+ throwaway build), but I did not verify that a host's generated routes can
36
+ construct and run an `Agent` instance with injected collections and tenant
37
+ context, so Garrula keeps `api: false` and this package changes no behaviour.
38
+ Until that is proven upstream (smrt), hosts call `new Garrula({...})` in process
39
+ from their own routes or jobs; tenant comes from `withTenant` context or the
40
+ request's `tenantId`, and the host-supplied `GarrulaConfig` is registered with
41
+ `setGarrulaConfig`.