@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,23 @@
1
+ import { DraftClaim, DraftingAI, OutboundPostKind, SourceEvent } from './types.js';
2
+ export interface DraftOutput {
3
+ text: string;
4
+ claims: DraftClaim[];
5
+ }
6
+ export declare class DraftingError extends Error {
7
+ constructor(message: string);
8
+ }
9
+ /** Every reference the drafter may cite for an event, nothing else. */
10
+ export declare function allowedEvidence(event: SourceEvent): {
11
+ urls: Set<string>;
12
+ lines: Set<string>;
13
+ };
14
+ export declare function buildDraftPrompt(persona: string, kind: OutboundPostKind, event: SourceEvent, maxLength: number): string;
15
+ /**
16
+ * Parse a model reply into a draft. Evidence that is not one of the event's
17
+ * own URLs or changelog lines is dropped, so a made-up citation leaves the
18
+ * claim uncited (and the draft unpublishable) rather than looking supported.
19
+ */
20
+ export declare function parseDraft(raw: string, event: SourceEvent): DraftOutput;
21
+ export declare function draftPost(ai: DraftingAI, persona: string, kind: OutboundPostKind, event: SourceEvent, maxLength: number): Promise<DraftOutput>;
22
+ /** A post is publishable only with at least one claim, every claim with evidence. */
23
+ export declare function isFullyCited(claims: DraftClaim[] | null | undefined): boolean;
@@ -0,0 +1,108 @@
1
+ import { SmrtObjectOptions, SmrtCollection, SmrtObject } from '@happyvertical/smrt-core';
2
+ import { AutonomyMode, DraftClaim, LinkPolicy, OutboundPostKind, OutboundState, SourceEventKind, SourceRule } from './types.js';
3
+ export interface GarrulaOutboundSettingsOptions extends SmrtObjectOptions {
4
+ tenantId?: string | null;
5
+ paused?: boolean;
6
+ monthlyCapMicros?: number;
7
+ persona?: string;
8
+ sources?: SourceRule[];
9
+ autonomy?: Record<OutboundPostKind, AutonomyMode>;
10
+ linkPolicy?: Record<string, LinkPolicy>;
11
+ defaultLinkPolicy?: LinkPolicy;
12
+ accountIds?: string[];
13
+ deferTopics?: string[];
14
+ }
15
+ /** One row per tenant: pause switch, cap, persona, source rules, autonomy, links. */
16
+ export declare class GarrulaOutboundSettings extends SmrtObject {
17
+ tenantId: string | null;
18
+ paused: boolean;
19
+ monthlyCapMicros: number;
20
+ persona: string;
21
+ sources: SourceRule[];
22
+ autonomy: Record<string, string>;
23
+ linkPolicy: Record<string, string>;
24
+ defaultLinkPolicy: string;
25
+ accountIds: string[];
26
+ deferTopics: string[];
27
+ constructor(options?: GarrulaOutboundSettingsOptions);
28
+ }
29
+ export declare class GarrulaOutboundSettingsCollection extends SmrtCollection<GarrulaOutboundSettings> {
30
+ static readonly _itemClass: typeof GarrulaOutboundSettings;
31
+ }
32
+ export interface GarrulaOutboundPostOptions extends SmrtObjectOptions {
33
+ tenantId?: string | null;
34
+ socialPostId?: string | null;
35
+ state?: OutboundState;
36
+ kind?: OutboundPostKind;
37
+ sourceEventId?: string;
38
+ sourceKind?: SourceEventKind;
39
+ sourceUrl?: string | null;
40
+ claims?: DraftClaim[];
41
+ approvedBy?: string | null;
42
+ rejectedReason?: string | null;
43
+ }
44
+ /**
45
+ * The outbound lifecycle of one `smrt-social` SocialPost: state, kind, source
46
+ * and cited claims. The text, account, schedule and publish result stay on the
47
+ * SocialPost itself; `state` here is authoritative and mirrored onto it.
48
+ * (smrt-social has no `rejected` status or claims field yet; see
49
+ * docs/upstream-followups.md.)
50
+ */
51
+ export declare class GarrulaOutboundPost extends SmrtObject {
52
+ tenantId: string | null;
53
+ socialPostId: string | null;
54
+ state: string;
55
+ kind: string;
56
+ sourceEventId: string;
57
+ sourceKind: string;
58
+ sourceUrl: string | null;
59
+ claims: DraftClaim[];
60
+ approvedBy: string | null;
61
+ rejectedReason: string | null;
62
+ constructor(options?: GarrulaOutboundPostOptions);
63
+ }
64
+ export declare class GarrulaOutboundPostCollection extends SmrtCollection<GarrulaOutboundPost> {
65
+ static readonly _itemClass: typeof GarrulaOutboundPost;
66
+ }
67
+ export interface GarrulaSpendEntryOptions extends SmrtObjectOptions {
68
+ tenantId?: string | null;
69
+ month?: string;
70
+ socialPostId?: string | null;
71
+ costMicros?: number;
72
+ source?: string;
73
+ status?: string;
74
+ }
75
+ /** Spend ledger: one entry per publish attempt, per tenant per month. */
76
+ export declare class GarrulaSpendEntry extends SmrtObject {
77
+ tenantId: string | null;
78
+ month: string;
79
+ socialPostId: string | null;
80
+ costMicros: number;
81
+ /** `adapter` | `rate-table` | `unpriced` */
82
+ source: string;
83
+ /** `reserved` | `recorded` | `released` */
84
+ status: string;
85
+ constructor(options?: GarrulaSpendEntryOptions);
86
+ }
87
+ export declare class GarrulaSpendEntryCollection extends SmrtCollection<GarrulaSpendEntry> {
88
+ static readonly _itemClass: typeof GarrulaSpendEntry;
89
+ }
90
+ export interface GarrulaSourceEventOptions extends SmrtObjectOptions {
91
+ tenantId?: string | null;
92
+ eventKey?: string;
93
+ outcome?: string;
94
+ outboundPostIds?: string[];
95
+ }
96
+ /** Dedupe ledger: an event id seen once never yields a second candidate. */
97
+ export declare class GarrulaSourceEvent extends SmrtObject {
98
+ tenantId: string | null;
99
+ /** `<kind>:<id>` */
100
+ eventKey: string;
101
+ /** `drafted` | `ignored` */
102
+ outcome: string;
103
+ outboundPostIds: string[];
104
+ constructor(options?: GarrulaSourceEventOptions);
105
+ }
106
+ export declare class GarrulaSourceEventCollection extends SmrtCollection<GarrulaSourceEvent> {
107
+ static readonly _itemClass: typeof GarrulaSourceEvent;
108
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Fallback publish prices, used only when the social adapter's publish result
3
+ * carries no cost of its own.
4
+ *
5
+ * TEMPORARY: X's published API prices. Remove once happyvertical.com#518 lands
6
+ * (the social SDK reports the real cost per publish); the host can override
7
+ * these per platform with `GarrulaConfig.outboundRates`.
8
+ */
9
+ export interface PlatformRates {
10
+ /** A plain post, in USD. */
11
+ post: number;
12
+ /** A post that contains a URL, in USD. */
13
+ postWithUrl: number;
14
+ /** A reply to a mention, in USD (inbound is out of scope; kept for the table). */
15
+ reply: number;
16
+ }
17
+ export declare const FALLBACK_X_RATES: Readonly<PlatformRates>;
18
+ export declare const DEFAULT_OUTBOUND_RATES: Readonly<Record<string, PlatformRates>>;
19
+ export declare const MICROS_PER_USD = 1000000;
20
+ export declare function usdToMicros(usd: number): number;
21
+ export type CostSource = "adapter" | "rate-table" | "unpriced";
22
+ export interface CostEstimate {
23
+ micros: number;
24
+ source: CostSource;
25
+ }
26
+ /** Estimate a publish from the rate table; unknown platforms are unpriced (0). */
27
+ export declare function estimateCost(rates: Readonly<Record<string, PlatformRates>>, platform: string, hasUrl: boolean): CostEstimate;
28
+ /**
29
+ * Read a cost the adapter reported on its publish result. The social SDK does
30
+ * not report one yet (happyvertical.com#518); this accepts the shapes it is
31
+ * expected to use: `cost` as USD number, or `{ usd }` / `{ amountUsd }`.
32
+ */
33
+ export declare function adapterCostMicros(result: unknown): number | null;
34
+ /** `YYYY-MM` in UTC. */
35
+ export declare function monthKey(date: Date): string;
@@ -0,0 +1,127 @@
1
+ import { GarrulaConfig } from '../config.js';
2
+ import { GarrulaCollections, GarrulaSocialPost } from '../types.js';
3
+ import { GarrulaOutboundPostCollection, GarrulaOutboundSettingsCollection, GarrulaSourceEventCollection, GarrulaSpendEntryCollection } from './models.js';
4
+ import { CostSource } from './rates.js';
5
+ import { DraftClaim, DraftingAI, IngestResult, OutboundDraft, OutboundPostKind, OutboundRefusal, OutboundSettings, OutboundSettingsPatch, OutboundState, SourceEvent, SpendSummary } from './types.js';
6
+ export interface OutboundStores {
7
+ settings: GarrulaOutboundSettingsCollection;
8
+ posts: GarrulaOutboundPostCollection;
9
+ spend: GarrulaSpendEntryCollection;
10
+ events: GarrulaSourceEventCollection;
11
+ }
12
+ export declare function createOutboundStores(options: {
13
+ db?: unknown;
14
+ ai?: unknown;
15
+ }): Promise<OutboundStores>;
16
+ type SocialAccess = Pick<GarrulaCollections, "socialAccounts" | "socialPosts">;
17
+ export interface OutboundServiceOptions {
18
+ stores: OutboundStores;
19
+ social: SocialAccess;
20
+ config: () => GarrulaConfig;
21
+ /** The model client used to draft; resolved lazily so tests inject a fake. */
22
+ ai: () => DraftingAI;
23
+ now?: () => Date;
24
+ }
25
+ /** A reservation held between the gate and the publish outcome. */
26
+ export interface SpendReservation {
27
+ tenantId: string;
28
+ entryId: string;
29
+ month: string;
30
+ estimateMicros: number;
31
+ estimateSource: CostSource;
32
+ outboundId: string | null;
33
+ }
34
+ export type GateDecision = {
35
+ ok: true;
36
+ reservation: SpendReservation;
37
+ linkUrl: string | null;
38
+ } | {
39
+ ok: false;
40
+ refusal: OutboundRefusal;
41
+ };
42
+ export interface SentOutcome {
43
+ /** The adapter's publish result when the platform was reached. */
44
+ result: {
45
+ status?: string;
46
+ cost?: unknown;
47
+ } | null;
48
+ success: boolean;
49
+ error?: string;
50
+ }
51
+ /** Title prefix on social posts created by outbound drafting. */
52
+ export declare const OUTBOUND_POST_MARKER = "garrula-outbound:";
53
+ /** True for a social post that outbound drafting created. */
54
+ export declare function isOutboundMarked(post: GarrulaSocialPost): boolean;
55
+ export declare class OutboundService {
56
+ private readonly stores;
57
+ private readonly social;
58
+ private readonly configFn;
59
+ private readonly aiFn;
60
+ private readonly nowFn;
61
+ constructor(options: OutboundServiceOptions);
62
+ /** The default cap; a non-finite or negative configured value falls back to the shipped default. */
63
+ private defaultCapMicros;
64
+ private defaults;
65
+ private findSettingsRow;
66
+ private toSettings;
67
+ /** Read fresh settings (never cached), defaults when the tenant has none. */
68
+ getSettings(tenantId: string): Promise<OutboundSettings>;
69
+ updateSettings(tenantId: string, patch: OutboundSettingsPatch): Promise<OutboundSettings>;
70
+ ingestSourceEvent(tenantId: string, event: SourceEvent): Promise<IngestResult>;
71
+ private targetAccounts;
72
+ private requireRow;
73
+ private loadPost;
74
+ private view;
75
+ listDrafts(tenantId: string, filter?: {
76
+ state?: OutboundState;
77
+ kind?: OutboundPostKind;
78
+ limit?: number;
79
+ }): Promise<OutboundDraft[]>;
80
+ getDraft(tenantId: string, id: string): Promise<OutboundDraft>;
81
+ editDraft(tenantId: string, id: string, patch: {
82
+ text?: string;
83
+ claims?: DraftClaim[];
84
+ linkUrl?: string | null;
85
+ }): Promise<OutboundDraft>;
86
+ approve(tenantId: string, id: string, approvedBy?: string): Promise<OutboundDraft>;
87
+ reject(tenantId: string, id: string, reason?: string): Promise<OutboundDraft>;
88
+ /** A failed post goes back to approved so the next run publishes it again. */
89
+ retry(tenantId: string, id: string): Promise<OutboundDraft>;
90
+ schedule(tenantId: string, id: string, at: Date): Promise<OutboundDraft>;
91
+ /** Approved or scheduled posts of the tenant whose time has come. */
92
+ dueForPublish(tenantId: string, now: Date): Promise<GarrulaSocialPost[]>;
93
+ /** The tenant's post to publish now: it must be approved or scheduled. */
94
+ postForPublish(tenantId: string, id: string): Promise<GarrulaSocialPost>;
95
+ outboundIdForPost(tenantId: string, socialPostId: string): Promise<string | null>;
96
+ private discardSocialDraft;
97
+ private findRowForPost;
98
+ private transition;
99
+ /**
100
+ * Mirror onto the SocialPost with a conditional update: it never overwrites
101
+ * a post a publisher has claimed (`publishing`). A refused write throws
102
+ * `in-flight` (claimed) or `not-found` (missing) and changes nothing.
103
+ */
104
+ private updateSocialPost;
105
+ /**
106
+ * Record a publish that failed before the gate (account, credentials, token
107
+ * refresh, media) so no spend reservation exists to settle it: the approved
108
+ * or scheduled post becomes `failed` and can be retried after repair.
109
+ */
110
+ failUnreserved(tenantId: string, socialPostId: string): Promise<void>;
111
+ private monthEntries;
112
+ getSpend(tenantId: string, month?: string): Promise<SpendSummary>;
113
+ /**
114
+ * The server-side checks every publish passes immediately before the
115
+ * adapter call: tenant, approval state, evidence, pause, link policy and
116
+ * the monthly cap. On success a spend reservation is held (atomically with
117
+ * the cap check) until {@link finish}.
118
+ */
119
+ beforeSend(post: GarrulaSocialPost, platform: string): Promise<GateDecision>;
120
+ /**
121
+ * Settle a reservation after the publish. Spend is recorded whenever the
122
+ * platform was reached (adapter cost, else the rate table; a dry run costs
123
+ * nothing) and released otherwise; the outbound state follows the outcome.
124
+ */
125
+ finish(reservation: SpendReservation, outcome: SentOutcome): Promise<void>;
126
+ }
127
+ export {};
@@ -0,0 +1,20 @@
1
+ import { AutonomyMode, OutboundPostKind, OutboundSettings, SourceEvent, SourceRule } from './types.js';
2
+ /**
3
+ * Default source rules: package publishes always post, merged pull requests
4
+ * only when they are a `feat`/`perf` change, docs changes are off. Chores,
5
+ * dependency bumps and internal work never produce a candidate.
6
+ */
7
+ export declare const DEFAULT_SOURCE_RULES: readonly SourceRule[];
8
+ export declare const DEFAULT_AUTONOMY: Readonly<Record<OutboundPostKind, AutonomyMode>>;
9
+ export type RuleDecision = {
10
+ match: true;
11
+ rule: SourceRule;
12
+ } | {
13
+ match: false;
14
+ reason: "no-rule" | "rule-disabled" | "filtered";
15
+ };
16
+ /** Decide whether an event produces a candidate under the tenant's rules. */
17
+ export declare function evaluateSourceEvent(settings: Pick<OutboundSettings, "sources">, event: SourceEvent): RuleDecision;
18
+ export declare function eventKey(event: Pick<SourceEvent, "kind" | "id">): string;
19
+ /** True when the event mentions a topic the tenant leaves to a person. */
20
+ export declare function isDeferred(topics: readonly string[], event: Pick<SourceEvent, "title" | "summary" | "labels">): boolean;
@@ -0,0 +1,6 @@
1
+ import { OutboundState } from './types.js';
2
+ /** Legal outbound transitions. Anything else is refused. */
3
+ export declare const OUTBOUND_TRANSITIONS: Readonly<Record<OutboundState, readonly OutboundState[]>>;
4
+ export declare function canTransition(from: OutboundState, to: OutboundState): boolean;
5
+ /** The `smrt-social` post status that mirrors an outbound state. */
6
+ export declare function socialStatusFor(state: OutboundState): string;
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Outbound pipeline types: release/changelog source events become cited
3
+ * drafts, which are approved, published under a spend cap, and recorded.
4
+ * Outbound only: nothing here reads mentions, replies, or any inbound feed.
5
+ */
6
+ /** What kind of upstream event a host hands in. */
7
+ export type SourceEventKind = "package-publish" | "merged-pr" | "docs-change";
8
+ /** Post types with their own autonomy setting. */
9
+ export type OutboundPostKind = "release" | "feature" | "docs";
10
+ export declare const OUTBOUND_POST_KINDS: readonly OutboundPostKind[];
11
+ /**
12
+ * Plain data describing one upstream event. The host (a webhook, a job, a CLI)
13
+ * builds it; Garrula never polls GitHub or any registry.
14
+ */
15
+ export interface SourceEvent {
16
+ kind: SourceEventKind;
17
+ /** Stable id of the event (a PR URL, `pkg@version`, a commit sha). Dedupe key. */
18
+ id: string;
19
+ title: string;
20
+ /** Canonical URL of the event (the PR, the release, the docs page). */
21
+ url: string;
22
+ summary?: string;
23
+ /** The changelog line that describes this event, when there is one. */
24
+ changelogLine?: string;
25
+ /** Further changelog lines that may be cited. */
26
+ changelog?: string[];
27
+ /** Further URLs (pull requests) that may be cited as evidence. */
28
+ evidenceUrls?: string[];
29
+ labels?: string[];
30
+ version?: string;
31
+ repo?: string;
32
+ }
33
+ /** One per-tenant rule saying which events of a kind become candidates. */
34
+ export interface SourceRule {
35
+ kind: SourceEventKind;
36
+ postKind: OutboundPostKind;
37
+ enabled?: boolean;
38
+ /** Regular expressions (case-insensitive); when set, the title must match one. */
39
+ includeTitle?: string[];
40
+ /** Regular expressions; a title matching one is ignored. */
41
+ excludeTitle?: string[];
42
+ /** When set, the event needs one of these labels. */
43
+ includeLabels?: string[];
44
+ /** An event with one of these labels is ignored. */
45
+ excludeLabels?: string[];
46
+ }
47
+ export type AutonomyMode = "require-approval" | "auto";
48
+ /** Whether the URL of the source is part of the published text. */
49
+ export type LinkPolicy = "none" | "include";
50
+ /** Evidence behind one claim: a pull request / release URL or a changelog line. */
51
+ export interface ClaimEvidence {
52
+ type: "url" | "changelog";
53
+ ref: string;
54
+ }
55
+ export interface DraftClaim {
56
+ text: string;
57
+ evidence: ClaimEvidence[];
58
+ }
59
+ export type OutboundState = "draft" | "approved" | "scheduled" | "published" | "failed" | "rejected";
60
+ export declare const OUTBOUND_STATES: readonly OutboundState[];
61
+ /** Per-tenant outbound settings (the stored row, with defaults applied). */
62
+ export interface OutboundSettings {
63
+ tenantId: string;
64
+ paused: boolean;
65
+ /** Monthly spend cap in micro-dollars (1 USD = 1_000_000). Always set. */
66
+ monthlyCapMicros: number;
67
+ /** The tenant's voice; the drafter writes in it. */
68
+ persona: string;
69
+ sources: SourceRule[];
70
+ autonomy: Record<OutboundPostKind, AutonomyMode>;
71
+ /** Link policy per social account id; accounts not listed use `defaultLinkPolicy`. */
72
+ linkPolicy: Record<string, LinkPolicy>;
73
+ defaultLinkPolicy: LinkPolicy;
74
+ /** Accounts that receive drafts; empty means every ready account of the tenant. */
75
+ accountIds: string[];
76
+ /**
77
+ * Topics the agent leaves to a person: an event whose title, summary or labels
78
+ * mention one (case-insensitive) is never auto-approved, whatever the
79
+ * autonomy setting says.
80
+ */
81
+ deferTopics: string[];
82
+ }
83
+ export type OutboundSettingsPatch = Partial<Omit<OutboundSettings, "tenantId" | "autonomy" | "linkPolicy">> & {
84
+ autonomy?: Partial<Record<OutboundPostKind, AutonomyMode>>;
85
+ linkPolicy?: Record<string, LinkPolicy>;
86
+ };
87
+ /** What the host and the UI see of one outbound post. */
88
+ export interface OutboundDraft {
89
+ id: string;
90
+ tenantId: string;
91
+ socialPostId: string;
92
+ accountId: string | null;
93
+ state: OutboundState;
94
+ kind: OutboundPostKind;
95
+ text: string;
96
+ hashtags: string[];
97
+ claims: DraftClaim[];
98
+ /** The URL that may be published, depending on the account's link policy. */
99
+ linkUrl: string | null;
100
+ sourceEventId: string;
101
+ sourceKind: SourceEventKind;
102
+ scheduledAt: Date | null;
103
+ publishedUrl: string | null;
104
+ error: string | null;
105
+ rejectedReason: string | null;
106
+ approvedBy: string | null;
107
+ /** False when a claim lacks evidence, so the post cannot be published. */
108
+ publishable: boolean;
109
+ createdAt: Date | null;
110
+ }
111
+ export type IngestResult = {
112
+ outcome: "drafted";
113
+ drafts: OutboundDraft[];
114
+ } | {
115
+ outcome: "ignored";
116
+ reason: "no-rule" | "rule-disabled" | "filtered" | "no-accounts";
117
+ } | {
118
+ outcome: "duplicate";
119
+ } | {
120
+ outcome: "draft-failed";
121
+ error: string;
122
+ };
123
+ /** Typed reasons the pipeline refuses to publish or change a post. */
124
+ export type OutboundRefusalCode = "paused" | "cap-reached" | "uncited" | "not-approved" | "illegal-transition" | "not-found" | "in-flight" | "invalid";
125
+ export interface OutboundRefusal {
126
+ code: OutboundRefusalCode;
127
+ message: string;
128
+ }
129
+ /** Thrown by the public API for refused changes (never for a publish). */
130
+ export declare class OutboundError extends Error {
131
+ readonly code: OutboundRefusalCode;
132
+ constructor(code: OutboundRefusalCode, message: string);
133
+ }
134
+ export interface SpendEntryView {
135
+ id: string;
136
+ month: string;
137
+ postId: string | null;
138
+ costMicros: number;
139
+ source: "adapter" | "rate-table" | "unpriced";
140
+ status: "reserved" | "recorded" | "released";
141
+ createdAt: Date | null;
142
+ }
143
+ export interface SpendSummary {
144
+ tenantId: string;
145
+ /** `YYYY-MM` (UTC). */
146
+ month: string;
147
+ capMicros: number;
148
+ /** Recorded plus currently reserved spend. */
149
+ spentMicros: number;
150
+ remainingMicros: number;
151
+ paused: boolean;
152
+ entries: SpendEntryView[];
153
+ }
154
+ export interface PublishDueResult {
155
+ postId: string;
156
+ outboundId: string | null;
157
+ success: boolean;
158
+ skipped?: string;
159
+ refusal?: OutboundRefusal;
160
+ error?: string;
161
+ }
162
+ /** The model call the drafter needs; `Agent.ai` satisfies it. */
163
+ export interface DraftingAI {
164
+ message(text: string, options?: Record<string, unknown>): Promise<string>;
165
+ }