@framers/agentos 0.1.52 → 0.1.53

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 (98) hide show
  1. package/dist/api/AgentOS.d.ts +10 -10
  2. package/dist/api/AgentOS.d.ts.map +1 -1
  3. package/dist/channels/index.d.ts +2 -1
  4. package/dist/channels/index.d.ts.map +1 -1
  5. package/dist/channels/index.js +2 -1
  6. package/dist/channels/index.js.map +1 -1
  7. package/dist/core/agency/index.d.ts +1 -2
  8. package/dist/core/agency/index.d.ts.map +1 -1
  9. package/dist/core/agency/index.js +1 -2
  10. package/dist/core/agency/index.js.map +1 -1
  11. package/dist/core/agents/AgentCore.d.ts +8 -19
  12. package/dist/core/agents/AgentCore.d.ts.map +1 -1
  13. package/dist/core/agents/AgentCore.js +7 -15
  14. package/dist/core/agents/AgentCore.js.map +1 -1
  15. package/dist/core/agents/AgentFactory.d.ts +9 -13
  16. package/dist/core/agents/AgentFactory.d.ts.map +1 -1
  17. package/dist/core/agents/AgentFactory.js +9 -13
  18. package/dist/core/agents/AgentFactory.js.map +1 -1
  19. package/dist/core/audio/SilenceDetector.d.ts +5 -5
  20. package/dist/core/audio/SilenceDetector.js +5 -5
  21. package/dist/core/evaluation/index.d.ts +2 -2
  22. package/dist/core/evaluation/index.js +2 -2
  23. package/dist/core/hitl/index.d.ts +1 -2
  24. package/dist/core/hitl/index.d.ts.map +1 -1
  25. package/dist/core/hitl/index.js +1 -2
  26. package/dist/core/hitl/index.js.map +1 -1
  27. package/dist/core/index.d.ts +1 -1
  28. package/dist/core/index.js +1 -1
  29. package/dist/core/llm/IPromptEngine.d.ts +13 -8
  30. package/dist/core/llm/IPromptEngine.d.ts.map +1 -1
  31. package/dist/core/llm/IPromptEngine.js.map +1 -1
  32. package/dist/core/marketplace/index.d.ts +2 -2
  33. package/dist/core/marketplace/index.js +2 -2
  34. package/dist/core/observability/index.d.ts +2 -2
  35. package/dist/core/observability/index.js +2 -2
  36. package/dist/core/planning/index.d.ts +1 -2
  37. package/dist/core/planning/index.d.ts.map +1 -1
  38. package/dist/core/planning/index.js +1 -2
  39. package/dist/core/planning/index.js.map +1 -1
  40. package/dist/core/provenance/index.d.ts +2 -2
  41. package/dist/core/provenance/index.js +2 -2
  42. package/dist/core/safety/index.d.ts +3 -2
  43. package/dist/core/safety/index.d.ts.map +1 -1
  44. package/dist/core/safety/index.js +3 -2
  45. package/dist/core/safety/index.js.map +1 -1
  46. package/dist/core/sandbox/index.d.ts +2 -2
  47. package/dist/core/sandbox/index.js +2 -2
  48. package/dist/core/structured/index.d.ts +1 -2
  49. package/dist/core/structured/index.d.ts.map +1 -1
  50. package/dist/core/structured/index.js +1 -2
  51. package/dist/core/structured/index.js.map +1 -1
  52. package/dist/core/tools/index.d.ts +2 -1
  53. package/dist/core/tools/index.d.ts.map +1 -1
  54. package/dist/core/tools/index.js +2 -1
  55. package/dist/core/tools/index.js.map +1 -1
  56. package/dist/discovery/index.d.ts +2 -1
  57. package/dist/discovery/index.d.ts.map +1 -1
  58. package/dist/discovery/index.js +2 -1
  59. package/dist/discovery/index.js.map +1 -1
  60. package/dist/memory/index.d.ts +2 -1
  61. package/dist/memory/index.d.ts.map +1 -1
  62. package/dist/memory/index.js +2 -1
  63. package/dist/memory/index.js.map +1 -1
  64. package/dist/rag/audit/index.d.ts +5 -2
  65. package/dist/rag/audit/index.d.ts.map +1 -1
  66. package/dist/rag/audit/index.js +5 -2
  67. package/dist/rag/audit/index.js.map +1 -1
  68. package/dist/rag/implementations/vector_stores/InMemoryVectorStore.d.ts +1 -2
  69. package/dist/rag/implementations/vector_stores/InMemoryVectorStore.d.ts.map +1 -1
  70. package/dist/rag/implementations/vector_stores/InMemoryVectorStore.js +1 -2
  71. package/dist/rag/implementations/vector_stores/InMemoryVectorStore.js.map +1 -1
  72. package/dist/rag/reranking/index.d.ts +2 -2
  73. package/dist/rag/reranking/index.js +2 -2
  74. package/dist/rag/reranking/providers/index.d.ts +3 -2
  75. package/dist/rag/reranking/providers/index.d.ts.map +1 -1
  76. package/dist/rag/reranking/providers/index.js +3 -2
  77. package/dist/rag/reranking/providers/index.js.map +1 -1
  78. package/dist/social-posting/ContentAdaptationEngine.d.ts +148 -0
  79. package/dist/social-posting/ContentAdaptationEngine.d.ts.map +1 -0
  80. package/dist/social-posting/ContentAdaptationEngine.js +445 -0
  81. package/dist/social-posting/ContentAdaptationEngine.js.map +1 -0
  82. package/dist/social-posting/SocialAbstractService.d.ts +52 -0
  83. package/dist/social-posting/SocialAbstractService.d.ts.map +1 -0
  84. package/dist/social-posting/SocialAbstractService.js +127 -0
  85. package/dist/social-posting/SocialAbstractService.js.map +1 -0
  86. package/dist/social-posting/SocialPostManager.d.ts +252 -0
  87. package/dist/social-posting/SocialPostManager.d.ts.map +1 -0
  88. package/dist/social-posting/SocialPostManager.js +344 -0
  89. package/dist/social-posting/SocialPostManager.js.map +1 -0
  90. package/dist/social-posting/index.d.ts +12 -0
  91. package/dist/social-posting/index.d.ts.map +1 -0
  92. package/dist/social-posting/index.js +15 -0
  93. package/dist/social-posting/index.js.map +1 -0
  94. package/dist/voice/index.d.ts +2 -1
  95. package/dist/voice/index.d.ts.map +1 -1
  96. package/dist/voice/index.js +2 -1
  97. package/dist/voice/index.js.map +1 -1
  98. package/package.json +6 -3
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @fileoverview Shared HTTP primitives for social channel services.
3
+ * @module @framers/agentos/social-posting/SocialAbstractService
4
+ */
5
+ export interface SocialRequestOptions {
6
+ /** Retry attempts after the initial request. */
7
+ maxRetries?: number;
8
+ /** Base delay for exponential backoff (ms). */
9
+ retryDelayMs?: number;
10
+ /** Max delay cap for backoff (ms). */
11
+ maxRetryDelayMs?: number;
12
+ /** Request timeout (ms). */
13
+ timeoutMs?: number;
14
+ /** Optional override for retryable HTTP status logic. */
15
+ shouldRetryStatus?: (status: number) => boolean;
16
+ }
17
+ export interface SocialServiceConfig {
18
+ /** Minimum spacing between outbound API requests. */
19
+ minRequestIntervalMs?: number;
20
+ /** Default retry attempts after initial request. */
21
+ defaultMaxRetries?: number;
22
+ /** Default base retry delay (ms). */
23
+ defaultRetryDelayMs?: number;
24
+ /** Default request timeout (ms). */
25
+ defaultTimeoutMs?: number;
26
+ }
27
+ /**
28
+ * Base class for social channel service layers.
29
+ *
30
+ * Adds:
31
+ * - request rate-limiting
32
+ * - retry with exponential backoff on retryable failures
33
+ * - JSON request/response helpers
34
+ * - OAuth scope assertion helper
35
+ */
36
+ export declare abstract class SocialAbstractService {
37
+ private readonly minRequestIntervalMs;
38
+ private readonly defaultMaxRetries;
39
+ private readonly defaultRetryDelayMs;
40
+ private readonly defaultTimeoutMs;
41
+ private lastRequestAt;
42
+ private rateLimiter;
43
+ protected constructor(config?: SocialServiceConfig);
44
+ protected fetchJson<T>(url: string, init?: RequestInit, options?: SocialRequestOptions): Promise<T>;
45
+ protected fetchText(url: string, init?: RequestInit, options?: SocialRequestOptions): Promise<string>;
46
+ protected fetchWithRetry(url: string, init?: RequestInit, options?: SocialRequestOptions): Promise<Response>;
47
+ protected assertScopes(requiredScopes: string[], grantedScopes?: string[]): void;
48
+ private fetchOnce;
49
+ private waitForRateLimit;
50
+ private computeBackoff;
51
+ }
52
+ //# sourceMappingURL=SocialAbstractService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialAbstractService.d.ts","sourceRoot":"","sources":["../../src/social-posting/SocialAbstractService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CACjD;AAED,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qCAAqC;IACrC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAYD;;;;;;;;GAQG;AACH,8BAAsB,qBAAqB;IACzC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAC9C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,WAAW,CAAoC;IAEvD,SAAS,aAAa,MAAM,GAAE,mBAAwB;cAOtC,SAAS,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,WAAgB,EACtB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,CAAC,CAAC;cAWG,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,WAAgB,EACtB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,MAAM,CAAC;cAKF,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,WAAgB,EACtB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,QAAQ,CAAC;IAoCpB,SAAS,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,aAAa,GAAE,MAAM,EAAO,GAAG,IAAI;YAQtE,SAAS;YAgCT,gBAAgB;IAkB9B,OAAO,CAAC,cAAc;CAIvB"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @fileoverview Shared HTTP primitives for social channel services.
3
+ * @module @framers/agentos/social-posting/SocialAbstractService
4
+ */
5
+ const DEFAULT_MAX_RETRIES = 2;
6
+ const DEFAULT_RETRY_DELAY_MS = 300;
7
+ const DEFAULT_MAX_RETRY_DELAY_MS = 5000;
8
+ const DEFAULT_TIMEOUT_MS = 15000;
9
+ const defaultRetryStatus = (status) => status === 429 || status >= 500;
10
+ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
11
+ /**
12
+ * Base class for social channel service layers.
13
+ *
14
+ * Adds:
15
+ * - request rate-limiting
16
+ * - retry with exponential backoff on retryable failures
17
+ * - JSON request/response helpers
18
+ * - OAuth scope assertion helper
19
+ */
20
+ export class SocialAbstractService {
21
+ constructor(config = {}) {
22
+ this.lastRequestAt = 0;
23
+ this.rateLimiter = Promise.resolve();
24
+ this.minRequestIntervalMs = Math.max(0, config.minRequestIntervalMs ?? 0);
25
+ this.defaultMaxRetries = Math.max(0, config.defaultMaxRetries ?? DEFAULT_MAX_RETRIES);
26
+ this.defaultRetryDelayMs = Math.max(1, config.defaultRetryDelayMs ?? DEFAULT_RETRY_DELAY_MS);
27
+ this.defaultTimeoutMs = Math.max(1, config.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS);
28
+ }
29
+ async fetchJson(url, init = {}, options = {}) {
30
+ const res = await this.fetchWithRetry(url, init, options);
31
+ const contentType = (res.headers.get('content-type') ?? '').toLowerCase();
32
+ if (contentType.includes('application/json')) {
33
+ return (await res.json());
34
+ }
35
+ const text = await res.text();
36
+ return text;
37
+ }
38
+ async fetchText(url, init = {}, options = {}) {
39
+ const res = await this.fetchWithRetry(url, init, options);
40
+ return res.text();
41
+ }
42
+ async fetchWithRetry(url, init = {}, options = {}) {
43
+ const maxRetries = options.maxRetries ?? this.defaultMaxRetries;
44
+ const retryDelayMs = options.retryDelayMs ?? this.defaultRetryDelayMs;
45
+ const maxRetryDelayMs = options.maxRetryDelayMs ?? DEFAULT_MAX_RETRY_DELAY_MS;
46
+ const timeoutMs = options.timeoutMs ?? this.defaultTimeoutMs;
47
+ const shouldRetryStatus = options.shouldRetryStatus ?? defaultRetryStatus;
48
+ for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
49
+ let response = null;
50
+ try {
51
+ await this.waitForRateLimit();
52
+ response = await this.fetchOnce(url, init, timeoutMs);
53
+ }
54
+ catch (err) {
55
+ if (attempt >= maxRetries) {
56
+ throw err instanceof Error ? err : new Error(String(err));
57
+ }
58
+ await wait(this.computeBackoff(attempt, retryDelayMs, maxRetryDelayMs));
59
+ continue;
60
+ }
61
+ if (response.ok)
62
+ return response;
63
+ if (attempt < maxRetries && shouldRetryStatus(response.status)) {
64
+ await wait(this.computeBackoff(attempt, retryDelayMs, maxRetryDelayMs));
65
+ continue;
66
+ }
67
+ const body = await response.text().catch(() => '');
68
+ throw new Error(`HTTP ${response.status} ${response.statusText}${body ? `: ${body}` : ''}`);
69
+ }
70
+ throw new Error('Request failed after retry attempts were exhausted.');
71
+ }
72
+ assertScopes(requiredScopes, grantedScopes = []) {
73
+ const granted = new Set(grantedScopes);
74
+ const missing = requiredScopes.filter((scope) => !granted.has(scope));
75
+ if (missing.length === 0)
76
+ return;
77
+ throw new Error(`Missing required OAuth scopes: ${missing.join(', ')}`);
78
+ }
79
+ async fetchOnce(url, init, timeoutMs) {
80
+ const controller = new AbortController();
81
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
82
+ try {
83
+ const normalizedInit = {
84
+ ...init,
85
+ signal: controller.signal,
86
+ };
87
+ if (normalizedInit.body &&
88
+ typeof normalizedInit.body === 'object' &&
89
+ !(normalizedInit.body instanceof URLSearchParams) &&
90
+ !(normalizedInit.body instanceof FormData) &&
91
+ !(normalizedInit.body instanceof Blob) &&
92
+ !(normalizedInit.body instanceof ArrayBuffer)) {
93
+ normalizedInit.body = JSON.stringify(normalizedInit.body);
94
+ const headers = new Headers(normalizedInit.headers ?? {});
95
+ if (!headers.has('content-type')) {
96
+ headers.set('content-type', 'application/json');
97
+ }
98
+ normalizedInit.headers = headers;
99
+ }
100
+ return await fetch(url, normalizedInit);
101
+ }
102
+ finally {
103
+ clearTimeout(timeout);
104
+ }
105
+ }
106
+ async waitForRateLimit() {
107
+ this.rateLimiter = this.rateLimiter.then(async () => {
108
+ if (this.minRequestIntervalMs <= 0) {
109
+ this.lastRequestAt = Date.now();
110
+ return;
111
+ }
112
+ const now = Date.now();
113
+ const delta = now - this.lastRequestAt;
114
+ const waitMs = Math.max(0, this.minRequestIntervalMs - delta);
115
+ if (waitMs > 0) {
116
+ await wait(waitMs);
117
+ }
118
+ this.lastRequestAt = Date.now();
119
+ });
120
+ return this.rateLimiter;
121
+ }
122
+ computeBackoff(attempt, baseMs, capMs) {
123
+ const raw = baseMs * 2 ** attempt;
124
+ return Math.min(capMs, raw);
125
+ }
126
+ }
127
+ //# sourceMappingURL=SocialAbstractService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialAbstractService.js","sourceRoot":"","sources":["../../src/social-posting/SocialAbstractService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AACxC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAEjC,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAW,EAAE,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC;AAExF,MAAM,IAAI,GAAG,CAAC,EAAU,EAAiB,EAAE,CACzC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,OAAgB,qBAAqB;IAQzC,YAAsB,SAA8B,EAAE;QAH9C,kBAAa,GAAG,CAAC,CAAC;QAClB,gBAAW,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;QAGrD,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAA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AAC,MAAM,CAAC,CAAC;YACrB,CAAC;YACD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAClC,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEO,cAAc,CAAC,OAAe,EAAE,MAAc,EAAE,KAAa;QACnE,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,252 @@
1
+ /**
2
+ * @fileoverview Social Post Manager — post lifecycle engine.
3
+ * @module @framers/agentos/social-posting/SocialPostManager
4
+ *
5
+ * Manages the full lifecycle of social media posts through a state machine:
6
+ *
7
+ * DRAFT --> SCHEDULED --> PUBLISHING --> PUBLISHED
8
+ * |
9
+ * ERROR --> RETRY --> PUBLISHING
10
+ *
11
+ * Storage is in-memory (Map<string, SocialPost>). The backend module will
12
+ * layer on DB persistence via IStorageAdapter when this is wired into
13
+ * the NestJS service layer.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { SocialPostManager } from '../social-posting';
18
+ *
19
+ * const manager = new SocialPostManager();
20
+ *
21
+ * const post = manager.createDraft({
22
+ * seedId: 'agent-alpha',
23
+ * content: 'Hello world!',
24
+ * platforms: ['twitter', 'bluesky'],
25
+ * });
26
+ *
27
+ * manager.schedulePost(post.id, '2026-03-05T12:00:00Z');
28
+ * ```
29
+ */
30
+ /**
31
+ * State machine states for a social post.
32
+ *
33
+ * Valid transitions:
34
+ * - draft --> scheduled | publishing
35
+ * - scheduled --> publishing
36
+ * - publishing --> published | error
37
+ * - error --> retry
38
+ * - retry --> publishing
39
+ */
40
+ export type SocialPostStatus = 'draft' | 'scheduled' | 'publishing' | 'published' | 'error' | 'retry';
41
+ /**
42
+ * Per-platform publishing result tracked on a SocialPost.
43
+ */
44
+ export interface SocialPostPlatformResult {
45
+ /** Target platform identifier (e.g. 'twitter', 'bluesky'). */
46
+ platform: string;
47
+ /** Platform-assigned post ID after successful publish. */
48
+ postId?: string;
49
+ /** Canonical URL of the published post. */
50
+ url?: string;
51
+ /** Current status for this platform leg. */
52
+ status: 'pending' | 'success' | 'error';
53
+ /** Error message if status is 'error'. */
54
+ error?: string;
55
+ /** ISO 8601 timestamp of successful publish. */
56
+ publishedAt?: string;
57
+ }
58
+ /**
59
+ * A social post managed by the SocialPostManager.
60
+ *
61
+ * `adaptations` maps platform names to platform-specific content variants
62
+ * produced by the ContentAdaptationEngine (or by the LLM skill layer).
63
+ */
64
+ export interface SocialPost {
65
+ /** Unique post identifier (UUID v4). */
66
+ id: string;
67
+ /** The agent seed this post belongs to. */
68
+ seedId: string;
69
+ /** The original, platform-agnostic content. */
70
+ baseContent: string;
71
+ /** Platform-specific content adaptations (platform --> adapted text). */
72
+ adaptations: Record<string, string>;
73
+ /** Target platforms for this post. */
74
+ platforms: string[];
75
+ /** Optional media attachment URLs. */
76
+ mediaUrls?: string[];
77
+ /** ISO 8601 timestamp when the post should be published. */
78
+ scheduledAt?: string;
79
+ /** Current lifecycle status. */
80
+ status: SocialPostStatus;
81
+ /** Per-platform publishing results. */
82
+ results: Record<string, SocialPostPlatformResult>;
83
+ /** Number of retry attempts so far. */
84
+ retryCount: number;
85
+ /** Maximum retry attempts before permanent failure. */
86
+ maxRetries: number;
87
+ /** ISO 8601 creation timestamp. */
88
+ createdAt: string;
89
+ /** ISO 8601 last-update timestamp. */
90
+ updatedAt: string;
91
+ }
92
+ /**
93
+ * Input for creating a new draft post.
94
+ */
95
+ export interface CreateDraftInput {
96
+ /** The agent seed this post belongs to. */
97
+ seedId: string;
98
+ /** The base content for the post. */
99
+ content: string;
100
+ /** Target platforms (e.g. ['twitter', 'linkedin']). */
101
+ platforms: string[];
102
+ /** Optional media attachment URLs. */
103
+ mediaUrls?: string[];
104
+ /** Pre-computed platform adaptations (platform --> adapted text). */
105
+ adaptations?: Record<string, string>;
106
+ /** ISO 8601 scheduled publish time. If omitted, the post stays as a draft. */
107
+ schedule?: string;
108
+ }
109
+ /**
110
+ * Manages the lifecycle of social media posts.
111
+ *
112
+ * Provides create, schedule, publish, retry, and query operations over an
113
+ * in-memory store. Platform-specific publishing is delegated to callers
114
+ * (typically the ToolExecutor / skill layer) via the {@link publishNow}
115
+ * callback mechanism.
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const manager = new SocialPostManager();
120
+ * const draft = manager.createDraft({
121
+ * seedId: 'my-agent',
122
+ * content: 'Big announcement!',
123
+ * platforms: ['twitter', 'linkedin'],
124
+ * });
125
+ *
126
+ * // Schedule for later
127
+ * manager.schedulePost(draft.id, '2026-03-10T15:00:00Z');
128
+ *
129
+ * // Or publish immediately
130
+ * await manager.publishNow(draft.id);
131
+ * ```
132
+ */
133
+ export declare class SocialPostManager {
134
+ /** In-memory post store keyed by post ID. */
135
+ private readonly posts;
136
+ /**
137
+ * Optional publish handler injected by the consuming layer.
138
+ * Called for each platform when {@link publishNow} is invoked.
139
+ *
140
+ * When not provided, publishNow will mark all platforms as 'pending'
141
+ * and transition the post to 'publishing', leaving actual delivery
142
+ * to the caller.
143
+ */
144
+ private publishHandler?;
145
+ /**
146
+ * Register a platform publish handler.
147
+ *
148
+ * The handler receives the full post and a single platform string and must
149
+ * return a {@link SocialPostPlatformResult}. It is called once per platform
150
+ * during {@link publishNow}.
151
+ *
152
+ * @param handler - Async function that publishes content to a platform
153
+ */
154
+ setPublishHandler(handler: (post: SocialPost, platform: string) => Promise<SocialPostPlatformResult>): void;
155
+ /**
156
+ * Create a new draft post.
157
+ *
158
+ * If `input.schedule` is provided, the post is automatically transitioned
159
+ * to 'scheduled' status.
160
+ *
161
+ * @param input - Draft creation parameters
162
+ * @returns The newly created SocialPost in 'draft' (or 'scheduled') status
163
+ */
164
+ createDraft(input: CreateDraftInput): SocialPost;
165
+ /**
166
+ * Schedule a draft post for future publishing.
167
+ *
168
+ * @param postId - ID of the post to schedule
169
+ * @param timestamp - ISO 8601 timestamp for desired publish time
170
+ * @returns The updated SocialPost in 'scheduled' status
171
+ * @throws {Error} If the post is not found or the transition is invalid
172
+ */
173
+ schedulePost(postId: string, timestamp: string): SocialPost;
174
+ /**
175
+ * Publish a post immediately.
176
+ *
177
+ * Transitions the post to 'publishing' and, if a publish handler is
178
+ * registered, invokes it for each target platform. After all platform
179
+ * results are collected, the post is transitioned to either 'published'
180
+ * (all succeeded) or 'error' (any failure).
181
+ *
182
+ * If no publish handler is registered, the post remains in 'publishing'
183
+ * status with all platform results set to 'pending'.
184
+ *
185
+ * @param postId - ID of the post to publish
186
+ * @returns The updated SocialPost after publish attempts
187
+ * @throws {Error} If the post is not found or the transition is invalid
188
+ */
189
+ publishNow(postId: string): Promise<SocialPost>;
190
+ /**
191
+ * Record a platform-specific publish result.
192
+ *
193
+ * Used by external publish handlers to report results asynchronously
194
+ * (e.g. webhook callbacks).
195
+ *
196
+ * @param postId - ID of the post
197
+ * @param platform - Platform identifier
198
+ * @param result - The platform result to record
199
+ * @returns The updated SocialPost
200
+ * @throws {Error} If the post is not found
201
+ */
202
+ markPlatformResult(postId: string, platform: string, result: SocialPostPlatformResult): SocialPost;
203
+ /**
204
+ * Retry a failed post.
205
+ *
206
+ * Transitions the post from 'error' to 'retry', increments the retry
207
+ * counter, and resets failed platform results to 'pending'.
208
+ *
209
+ * @param postId - ID of the post to retry
210
+ * @returns The updated SocialPost in 'retry' status
211
+ * @throws {Error} If the post is not found, the transition is invalid,
212
+ * or the maximum retry count has been reached
213
+ */
214
+ retryFailed(postId: string): SocialPost;
215
+ /**
216
+ * Retrieve a post by ID.
217
+ *
218
+ * @param postId - ID of the post to retrieve
219
+ * @returns The SocialPost if found, otherwise undefined
220
+ */
221
+ getPost(postId: string): SocialPost | undefined;
222
+ /**
223
+ * List posts with optional filtering by seed ID and/or status.
224
+ *
225
+ * @param seedId - Optional seed ID filter
226
+ * @param status - Optional status filter
227
+ * @returns Array of matching SocialPost objects
228
+ */
229
+ listPosts(seedId?: string, status?: SocialPostStatus): SocialPost[];
230
+ /**
231
+ * Get all scheduled posts whose scheduledAt timestamp has passed.
232
+ *
233
+ * Used by a polling loop or scheduler to find posts that are due for
234
+ * publishing.
235
+ *
236
+ * @returns Array of SocialPost objects that are due for publishing
237
+ */
238
+ getDuePosts(): SocialPost[];
239
+ /**
240
+ * Retrieve a post or throw if not found.
241
+ */
242
+ private requirePost;
243
+ /**
244
+ * Assert that a state transition is valid.
245
+ */
246
+ private assertTransition;
247
+ /**
248
+ * Initialize platform results with 'pending' status for each platform.
249
+ */
250
+ private initPlatformResults;
251
+ }
252
+ //# sourceMappingURL=SocialPostManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SocialPostManager.d.ts","sourceRoot":"","sources":["../../src/social-posting/SocialPostManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAQH;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GACxB,OAAO,GACP,WAAW,GACX,YAAY,GACZ,WAAW,GACX,OAAO,GACP,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;IACxC,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,wCAAwC;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAA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