@hasna/microservices 0.0.15 → 0.0.17
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/README.md +120 -138
- package/bin/index.js +703 -12728
- package/bin/mcp.js +250 -9726
- package/dist/index.js +170 -9407
- package/package.json +25 -25
- package/microservices/microservice-ads/package.json +0 -27
- package/microservices/microservice-ads/src/cli/index.ts +0 -605
- package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
- package/microservices/microservice-ads/src/db/database.ts +0 -93
- package/microservices/microservice-ads/src/db/migrations.ts +0 -60
- package/microservices/microservice-ads/src/index.ts +0 -39
- package/microservices/microservice-ads/src/mcp/index.ts +0 -480
- package/microservices/microservice-analytics/package.json +0 -27
- package/microservices/microservice-analytics/src/cli/index.ts +0 -373
- package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
- package/microservices/microservice-analytics/src/db/database.ts +0 -93
- package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
- package/microservices/microservice-analytics/src/index.ts +0 -37
- package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
- package/microservices/microservice-assets/package.json +0 -27
- package/microservices/microservice-assets/src/cli/index.ts +0 -375
- package/microservices/microservice-assets/src/db/assets.ts +0 -370
- package/microservices/microservice-assets/src/db/database.ts +0 -93
- package/microservices/microservice-assets/src/db/migrations.ts +0 -51
- package/microservices/microservice-assets/src/index.ts +0 -32
- package/microservices/microservice-assets/src/mcp/index.ts +0 -346
- package/microservices/microservice-bookkeeping/package.json +0 -27
- package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
- package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
- package/microservices/microservice-bookkeeping/src/db/database.ts +0 -93
- package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
- package/microservices/microservice-bookkeeping/src/index.ts +0 -32
- package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
- package/microservices/microservice-calendar/package.json +0 -27
- package/microservices/microservice-calendar/src/cli/index.ts +0 -287
- package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
- package/microservices/microservice-calendar/src/db/database.ts +0 -82
- package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
- package/microservices/microservice-calendar/src/index.ts +0 -24
- package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
- package/microservices/microservice-company/package.json +0 -27
- package/microservices/microservice-company/src/cli/index.ts +0 -1126
- package/microservices/microservice-company/src/db/company.ts +0 -854
- package/microservices/microservice-company/src/db/database.ts +0 -93
- package/microservices/microservice-company/src/db/migrations.ts +0 -214
- package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
- package/microservices/microservice-company/src/index.ts +0 -60
- package/microservices/microservice-company/src/lib/audit.ts +0 -168
- package/microservices/microservice-company/src/lib/finance.ts +0 -299
- package/microservices/microservice-company/src/lib/settings.ts +0 -85
- package/microservices/microservice-company/src/lib/workflows.ts +0 -698
- package/microservices/microservice-company/src/mcp/index.ts +0 -991
- package/microservices/microservice-compliance/package.json +0 -27
- package/microservices/microservice-compliance/src/cli/index.ts +0 -467
- package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
- package/microservices/microservice-compliance/src/db/database.ts +0 -93
- package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
- package/microservices/microservice-compliance/src/index.ts +0 -46
- package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
- package/microservices/microservice-contacts/package.json +0 -27
- package/microservices/microservice-contacts/src/cli/index.ts +0 -393
- package/microservices/microservice-contacts/src/db/companies.ts +0 -167
- package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
- package/microservices/microservice-contacts/src/db/database.ts +0 -93
- package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
- package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
- package/microservices/microservice-contacts/src/index.ts +0 -42
- package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
- package/microservices/microservice-contracts/package.json +0 -27
- package/microservices/microservice-contracts/src/cli/index.ts +0 -770
- package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
- package/microservices/microservice-contracts/src/db/database.ts +0 -93
- package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
- package/microservices/microservice-contracts/src/index.ts +0 -43
- package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
- package/microservices/microservice-crm/package.json +0 -27
- package/microservices/microservice-crm/src/cli/index.ts +0 -396
- package/microservices/microservice-crm/src/db/database.ts +0 -82
- package/microservices/microservice-crm/src/db/migrations.ts +0 -66
- package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
- package/microservices/microservice-crm/src/index.ts +0 -34
- package/microservices/microservice-crm/src/mcp/index.ts +0 -294
- package/microservices/microservice-documents/package.json +0 -27
- package/microservices/microservice-documents/src/cli/index.ts +0 -246
- package/microservices/microservice-documents/src/db/database.ts +0 -82
- package/microservices/microservice-documents/src/db/documents.ts +0 -316
- package/microservices/microservice-documents/src/db/migrations.ts +0 -49
- package/microservices/microservice-documents/src/index.ts +0 -24
- package/microservices/microservice-documents/src/mcp/index.ts +0 -202
- package/microservices/microservice-domains/package.json +0 -27
- package/microservices/microservice-domains/src/cli/index.ts +0 -1111
- package/microservices/microservice-domains/src/db/database.ts +0 -93
- package/microservices/microservice-domains/src/db/domains.ts +0 -1164
- package/microservices/microservice-domains/src/db/migrations.ts +0 -60
- package/microservices/microservice-domains/src/index.ts +0 -65
- package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
- package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
- package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
- package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
- package/microservices/microservice-domains/src/mcp/index.ts +0 -781
- package/microservices/microservice-expenses/package.json +0 -27
- package/microservices/microservice-expenses/src/cli/index.ts +0 -267
- package/microservices/microservice-expenses/src/db/database.ts +0 -82
- package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
- package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
- package/microservices/microservice-expenses/src/index.ts +0 -25
- package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
- package/microservices/microservice-habits/package.json +0 -27
- package/microservices/microservice-habits/src/cli/index.ts +0 -315
- package/microservices/microservice-habits/src/db/database.ts +0 -93
- package/microservices/microservice-habits/src/db/habits.ts +0 -451
- package/microservices/microservice-habits/src/db/migrations.ts +0 -46
- package/microservices/microservice-habits/src/index.ts +0 -31
- package/microservices/microservice-habits/src/mcp/index.ts +0 -313
- package/microservices/microservice-health/package.json +0 -27
- package/microservices/microservice-health/src/cli/index.ts +0 -484
- package/microservices/microservice-health/src/db/database.ts +0 -93
- package/microservices/microservice-health/src/db/health.ts +0 -708
- package/microservices/microservice-health/src/db/migrations.ts +0 -70
- package/microservices/microservice-health/src/index.ts +0 -63
- package/microservices/microservice-health/src/mcp/index.ts +0 -437
- package/microservices/microservice-hiring/package.json +0 -27
- package/microservices/microservice-hiring/src/cli/index.ts +0 -741
- package/microservices/microservice-hiring/src/db/database.ts +0 -93
- package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
- package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
- package/microservices/microservice-hiring/src/index.ts +0 -80
- package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
- package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
- package/microservices/microservice-inventory/package.json +0 -27
- package/microservices/microservice-inventory/src/cli/index.ts +0 -365
- package/microservices/microservice-inventory/src/db/database.ts +0 -82
- package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
- package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
- package/microservices/microservice-inventory/src/index.ts +0 -28
- package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
- package/microservices/microservice-invoices/dashboard/dist/assets/index-Bngq7FNM.css +0 -1
- package/microservices/microservice-invoices/dashboard/dist/assets/index-aHW4ARZR.js +0 -124
- package/microservices/microservice-invoices/dashboard/dist/index.html +0 -13
- package/microservices/microservice-invoices/dashboard/index.html +0 -12
- package/microservices/microservice-invoices/dashboard/package.json +0 -29
- package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
- package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
- package/microservices/microservice-invoices/package.json +0 -30
- package/microservices/microservice-invoices/src/cli/index.ts +0 -308
- package/microservices/microservice-invoices/src/db/business.ts +0 -241
- package/microservices/microservice-invoices/src/db/clients.ts +0 -127
- package/microservices/microservice-invoices/src/db/database.ts +0 -82
- package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
- package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
- package/microservices/microservice-invoices/src/index.ts +0 -56
- package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
- package/microservices/microservice-invoices/src/server/index.ts +0 -162
- package/microservices/microservice-leads/package.json +0 -27
- package/microservices/microservice-leads/src/cli/index.ts +0 -596
- package/microservices/microservice-leads/src/db/database.ts +0 -93
- package/microservices/microservice-leads/src/db/leads.ts +0 -520
- package/microservices/microservice-leads/src/db/lists.ts +0 -151
- package/microservices/microservice-leads/src/db/migrations.ts +0 -93
- package/microservices/microservice-leads/src/index.ts +0 -65
- package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
- package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
- package/microservices/microservice-leads/src/mcp/index.ts +0 -533
- package/microservices/microservice-notes/package.json +0 -27
- package/microservices/microservice-notes/src/cli/index.ts +0 -63
- package/microservices/microservice-notes/src/db/database.ts +0 -93
- package/microservices/microservice-notes/src/db/migrations.ts +0 -40
- package/microservices/microservice-notes/src/db/notes.ts +0 -114
- package/microservices/microservice-notes/src/index.ts +0 -2
- package/microservices/microservice-notes/src/mcp/index.ts +0 -37
- package/microservices/microservice-notifications/package.json +0 -27
- package/microservices/microservice-notifications/src/cli/index.ts +0 -349
- package/microservices/microservice-notifications/src/db/database.ts +0 -93
- package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
- package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
- package/microservices/microservice-notifications/src/index.ts +0 -41
- package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
- package/microservices/microservice-payments/package.json +0 -27
- package/microservices/microservice-payments/src/cli/index.ts +0 -609
- package/microservices/microservice-payments/src/db/database.ts +0 -93
- package/microservices/microservice-payments/src/db/migrations.ts +0 -81
- package/microservices/microservice-payments/src/db/payments.ts +0 -1204
- package/microservices/microservice-payments/src/index.ts +0 -51
- package/microservices/microservice-payments/src/mcp/index.ts +0 -683
- package/microservices/microservice-payroll/package.json +0 -27
- package/microservices/microservice-payroll/src/cli/index.ts +0 -643
- package/microservices/microservice-payroll/src/db/database.ts +0 -93
- package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
- package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
- package/microservices/microservice-payroll/src/index.ts +0 -48
- package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
- package/microservices/microservice-products/package.json +0 -27
- package/microservices/microservice-products/src/cli/index.ts +0 -416
- package/microservices/microservice-products/src/db/categories.ts +0 -154
- package/microservices/microservice-products/src/db/database.ts +0 -93
- package/microservices/microservice-products/src/db/migrations.ts +0 -58
- package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
- package/microservices/microservice-products/src/db/products.ts +0 -452
- package/microservices/microservice-products/src/index.ts +0 -53
- package/microservices/microservice-products/src/mcp/index.ts +0 -453
- package/microservices/microservice-projects/package.json +0 -27
- package/microservices/microservice-projects/src/cli/index.ts +0 -480
- package/microservices/microservice-projects/src/db/database.ts +0 -93
- package/microservices/microservice-projects/src/db/migrations.ts +0 -65
- package/microservices/microservice-projects/src/db/projects.ts +0 -715
- package/microservices/microservice-projects/src/index.ts +0 -57
- package/microservices/microservice-projects/src/mcp/index.ts +0 -501
- package/microservices/microservice-proposals/package.json +0 -27
- package/microservices/microservice-proposals/src/cli/index.ts +0 -400
- package/microservices/microservice-proposals/src/db/database.ts +0 -93
- package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
- package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
- package/microservices/microservice-proposals/src/index.ts +0 -37
- package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
- package/microservices/microservice-reading/package.json +0 -27
- package/microservices/microservice-reading/src/cli/index.ts +0 -464
- package/microservices/microservice-reading/src/db/database.ts +0 -93
- package/microservices/microservice-reading/src/db/migrations.ts +0 -59
- package/microservices/microservice-reading/src/db/reading.ts +0 -524
- package/microservices/microservice-reading/src/index.ts +0 -51
- package/microservices/microservice-reading/src/mcp/index.ts +0 -368
- package/microservices/microservice-shipping/package.json +0 -27
- package/microservices/microservice-shipping/src/cli/index.ts +0 -606
- package/microservices/microservice-shipping/src/db/database.ts +0 -93
- package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
- package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
- package/microservices/microservice-shipping/src/index.ts +0 -53
- package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
- package/microservices/microservice-social/package.json +0 -28
- package/microservices/microservice-social/src/cli/index.ts +0 -1583
- package/microservices/microservice-social/src/db/database.ts +0 -93
- package/microservices/microservice-social/src/db/migrations.ts +0 -160
- package/microservices/microservice-social/src/db/social.ts +0 -1076
- package/microservices/microservice-social/src/index.ts +0 -46
- package/microservices/microservice-social/src/lib/audience.ts +0 -353
- package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
- package/microservices/microservice-social/src/lib/media.ts +0 -311
- package/microservices/microservice-social/src/lib/mentions.ts +0 -434
- package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
- package/microservices/microservice-social/src/lib/publisher.ts +0 -377
- package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
- package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
- package/microservices/microservice-social/src/lib/threads.ts +0 -291
- package/microservices/microservice-social/src/mcp/index.ts +0 -1425
- package/microservices/microservice-social/src/server/index.ts +0 -441
- package/microservices/microservice-subscriptions/package.json +0 -27
- package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
- package/microservices/microservice-subscriptions/src/db/database.ts +0 -93
- package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
- package/microservices/microservice-subscriptions/src/index.ts +0 -41
- package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
- package/microservices/microservice-timesheets/package.json +0 -27
- package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
- package/microservices/microservice-timesheets/src/db/database.ts +0 -82
- package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
- package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
- package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
- package/microservices/microservice-timesheets/src/index.ts +0 -44
- package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
- package/microservices/microservice-transcriber/package.json +0 -28
- package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
- package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
- package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
- package/microservices/microservice-transcriber/src/db/database.ts +0 -82
- package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
- package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
- package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
- package/microservices/microservice-transcriber/src/index.ts +0 -43
- package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
- package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
- package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
- package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
- package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
- package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
- package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
- package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
- package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
- package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
- package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
- package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
- package/microservices/microservice-transcriber/src/server/index.ts +0 -199
- package/microservices/microservice-travel/package.json +0 -27
- package/microservices/microservice-travel/src/cli/index.ts +0 -505
- package/microservices/microservice-travel/src/db/database.ts +0 -93
- package/microservices/microservice-travel/src/db/migrations.ts +0 -77
- package/microservices/microservice-travel/src/db/travel.ts +0 -802
- package/microservices/microservice-travel/src/index.ts +0 -60
- package/microservices/microservice-travel/src/mcp/index.ts +0 -495
- package/microservices/microservice-wiki/package.json +0 -27
- package/microservices/microservice-wiki/src/cli/index.ts +0 -345
- package/microservices/microservice-wiki/src/db/database.ts +0 -93
- package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
- package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
- package/microservices/microservice-wiki/src/index.ts +0 -32
- package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* microservice-social — Social media management microservice
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
createAccount,
|
|
7
|
-
getAccount,
|
|
8
|
-
listAccounts,
|
|
9
|
-
updateAccount,
|
|
10
|
-
deleteAccount,
|
|
11
|
-
countAccounts,
|
|
12
|
-
createPost,
|
|
13
|
-
getPost,
|
|
14
|
-
listPosts,
|
|
15
|
-
updatePost,
|
|
16
|
-
deletePost,
|
|
17
|
-
countPosts,
|
|
18
|
-
schedulePost,
|
|
19
|
-
publishPost,
|
|
20
|
-
createTemplate,
|
|
21
|
-
getTemplate,
|
|
22
|
-
listTemplates,
|
|
23
|
-
deleteTemplate,
|
|
24
|
-
useTemplate,
|
|
25
|
-
getEngagementStats,
|
|
26
|
-
getStatsByPlatform,
|
|
27
|
-
getCalendar,
|
|
28
|
-
getOverallStats,
|
|
29
|
-
type Platform,
|
|
30
|
-
type PostStatus,
|
|
31
|
-
type Account,
|
|
32
|
-
type Post,
|
|
33
|
-
type Template,
|
|
34
|
-
type Engagement,
|
|
35
|
-
type EngagementStats,
|
|
36
|
-
type PlatformStats,
|
|
37
|
-
type CreateAccountInput,
|
|
38
|
-
type UpdateAccountInput,
|
|
39
|
-
type ListAccountsOptions,
|
|
40
|
-
type CreatePostInput,
|
|
41
|
-
type UpdatePostInput,
|
|
42
|
-
type ListPostsOptions,
|
|
43
|
-
type CreateTemplateInput,
|
|
44
|
-
} from "./db/social.js";
|
|
45
|
-
|
|
46
|
-
export { getDatabase, closeDatabase } from "./db/database.js";
|
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Follower sync and audience insights
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { getDatabase } from "../db/database.js";
|
|
6
|
-
|
|
7
|
-
// ---- Types ----
|
|
8
|
-
|
|
9
|
-
export interface Follower {
|
|
10
|
-
id: string;
|
|
11
|
-
account_id: string;
|
|
12
|
-
platform_user_id: string | null;
|
|
13
|
-
username: string | null;
|
|
14
|
-
display_name: string | null;
|
|
15
|
-
follower_count: number;
|
|
16
|
-
following: boolean;
|
|
17
|
-
followed_at: string | null;
|
|
18
|
-
unfollowed_at: string | null;
|
|
19
|
-
metadata: Record<string, unknown>;
|
|
20
|
-
created_at: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface FollowerRow {
|
|
24
|
-
id: string;
|
|
25
|
-
account_id: string;
|
|
26
|
-
platform_user_id: string | null;
|
|
27
|
-
username: string | null;
|
|
28
|
-
display_name: string | null;
|
|
29
|
-
follower_count: number;
|
|
30
|
-
following: number;
|
|
31
|
-
followed_at: string | null;
|
|
32
|
-
unfollowed_at: string | null;
|
|
33
|
-
metadata: string;
|
|
34
|
-
created_at: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function rowToFollower(row: FollowerRow): Follower {
|
|
38
|
-
return {
|
|
39
|
-
...row,
|
|
40
|
-
following: row.following === 1,
|
|
41
|
-
metadata: JSON.parse(row.metadata || "{}"),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface AudienceSnapshot {
|
|
46
|
-
id: string;
|
|
47
|
-
account_id: string;
|
|
48
|
-
follower_count: number;
|
|
49
|
-
following_count: number;
|
|
50
|
-
snapshot_at: string;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface CreateFollowerInput {
|
|
54
|
-
account_id: string;
|
|
55
|
-
platform_user_id?: string;
|
|
56
|
-
username?: string;
|
|
57
|
-
display_name?: string;
|
|
58
|
-
follower_count?: number;
|
|
59
|
-
following?: boolean;
|
|
60
|
-
followed_at?: string;
|
|
61
|
-
metadata?: Record<string, unknown>;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface ListFollowersFilters {
|
|
65
|
-
following?: boolean;
|
|
66
|
-
search?: string;
|
|
67
|
-
limit?: number;
|
|
68
|
-
offset?: number;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface UpdateFollowerInput {
|
|
72
|
-
username?: string;
|
|
73
|
-
display_name?: string;
|
|
74
|
-
follower_count?: number;
|
|
75
|
-
following?: boolean;
|
|
76
|
-
unfollowed_at?: string;
|
|
77
|
-
metadata?: Record<string, unknown>;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface AudienceInsights {
|
|
81
|
-
total_followers: number;
|
|
82
|
-
growth_rate_7d: number;
|
|
83
|
-
growth_rate_30d: number;
|
|
84
|
-
new_followers_7d: number;
|
|
85
|
-
lost_followers_7d: number;
|
|
86
|
-
top_followers: Follower[];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface GrowthPoint {
|
|
90
|
-
date: string;
|
|
91
|
-
count: number;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ---- Followers CRUD ----
|
|
95
|
-
|
|
96
|
-
export function createFollower(input: CreateFollowerInput): Follower {
|
|
97
|
-
const db = getDatabase();
|
|
98
|
-
const id = crypto.randomUUID();
|
|
99
|
-
const metadata = JSON.stringify(input.metadata || {});
|
|
100
|
-
|
|
101
|
-
db.prepare(
|
|
102
|
-
`INSERT INTO followers (id, account_id, platform_user_id, username, display_name, follower_count, following, followed_at, metadata)
|
|
103
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
104
|
-
).run(
|
|
105
|
-
id,
|
|
106
|
-
input.account_id,
|
|
107
|
-
input.platform_user_id || null,
|
|
108
|
-
input.username || null,
|
|
109
|
-
input.display_name || null,
|
|
110
|
-
input.follower_count ?? 0,
|
|
111
|
-
input.following !== false ? 1 : 0,
|
|
112
|
-
input.followed_at || null,
|
|
113
|
-
metadata
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
return getFollower(id)!;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function getFollower(id: string): Follower | null {
|
|
120
|
-
const db = getDatabase();
|
|
121
|
-
const row = db.prepare("SELECT * FROM followers WHERE id = ?").get(id) as FollowerRow | null;
|
|
122
|
-
return row ? rowToFollower(row) : null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function listFollowers(accountId: string, filters: ListFollowersFilters = {}): Follower[] {
|
|
126
|
-
const db = getDatabase();
|
|
127
|
-
const conditions: string[] = ["account_id = ?"];
|
|
128
|
-
const params: unknown[] = [accountId];
|
|
129
|
-
|
|
130
|
-
if (filters.following !== undefined) {
|
|
131
|
-
conditions.push("following = ?");
|
|
132
|
-
params.push(filters.following ? 1 : 0);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (filters.search) {
|
|
136
|
-
conditions.push("(username LIKE ? OR display_name LIKE ?)");
|
|
137
|
-
params.push(`%${filters.search}%`, `%${filters.search}%`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let sql = `SELECT * FROM followers WHERE ${conditions.join(" AND ")} ORDER BY follower_count DESC`;
|
|
141
|
-
|
|
142
|
-
if (filters.limit) {
|
|
143
|
-
sql += " LIMIT ?";
|
|
144
|
-
params.push(filters.limit);
|
|
145
|
-
}
|
|
146
|
-
if (filters.offset) {
|
|
147
|
-
sql += " OFFSET ?";
|
|
148
|
-
params.push(filters.offset);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const rows = db.prepare(sql).all(...params) as FollowerRow[];
|
|
152
|
-
return rows.map(rowToFollower);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function updateFollower(id: string, input: UpdateFollowerInput): Follower | null {
|
|
156
|
-
const db = getDatabase();
|
|
157
|
-
const existing = getFollower(id);
|
|
158
|
-
if (!existing) return null;
|
|
159
|
-
|
|
160
|
-
const sets: string[] = [];
|
|
161
|
-
const params: unknown[] = [];
|
|
162
|
-
|
|
163
|
-
if (input.username !== undefined) {
|
|
164
|
-
sets.push("username = ?");
|
|
165
|
-
params.push(input.username);
|
|
166
|
-
}
|
|
167
|
-
if (input.display_name !== undefined) {
|
|
168
|
-
sets.push("display_name = ?");
|
|
169
|
-
params.push(input.display_name);
|
|
170
|
-
}
|
|
171
|
-
if (input.follower_count !== undefined) {
|
|
172
|
-
sets.push("follower_count = ?");
|
|
173
|
-
params.push(input.follower_count);
|
|
174
|
-
}
|
|
175
|
-
if (input.following !== undefined) {
|
|
176
|
-
sets.push("following = ?");
|
|
177
|
-
params.push(input.following ? 1 : 0);
|
|
178
|
-
}
|
|
179
|
-
if (input.unfollowed_at !== undefined) {
|
|
180
|
-
sets.push("unfollowed_at = ?");
|
|
181
|
-
params.push(input.unfollowed_at);
|
|
182
|
-
}
|
|
183
|
-
if (input.metadata !== undefined) {
|
|
184
|
-
sets.push("metadata = ?");
|
|
185
|
-
params.push(JSON.stringify(input.metadata));
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (sets.length === 0) return existing;
|
|
189
|
-
|
|
190
|
-
params.push(id);
|
|
191
|
-
db.prepare(`UPDATE followers SET ${sets.join(", ")} WHERE id = ?`).run(...params);
|
|
192
|
-
|
|
193
|
-
return getFollower(id);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function removeFollower(id: string): boolean {
|
|
197
|
-
const db = getDatabase();
|
|
198
|
-
const result = db.prepare("DELETE FROM followers WHERE id = ?").run(id);
|
|
199
|
-
return result.changes > 0;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ---- Sync ----
|
|
203
|
-
|
|
204
|
-
export interface SyncResult {
|
|
205
|
-
synced: number;
|
|
206
|
-
new_followers: number;
|
|
207
|
-
unfollowed: number;
|
|
208
|
-
message: string;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Stub that would call the platform API for follower list, upsert into DB.
|
|
213
|
-
* In production this would call X/Instagram/LinkedIn APIs.
|
|
214
|
-
*/
|
|
215
|
-
export function syncFollowers(accountId: string): SyncResult {
|
|
216
|
-
// In a real implementation, this would:
|
|
217
|
-
// 1. Call the platform API to get the current follower list
|
|
218
|
-
// 2. Upsert new followers into the DB
|
|
219
|
-
// 3. Mark unfollowed users (following=0, set unfollowed_at)
|
|
220
|
-
// 4. Update follower metadata (display_name, follower_count)
|
|
221
|
-
|
|
222
|
-
const db = getDatabase();
|
|
223
|
-
const currentFollowers = db.prepare(
|
|
224
|
-
"SELECT COUNT(*) as count FROM followers WHERE account_id = ? AND following = 1"
|
|
225
|
-
).get(accountId) as { count: number };
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
synced: currentFollowers.count,
|
|
229
|
-
new_followers: 0,
|
|
230
|
-
unfollowed: 0,
|
|
231
|
-
message: "Sync stub — connect platform API credentials to enable live sync.",
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// ---- Snapshots ----
|
|
236
|
-
|
|
237
|
-
export function createSnapshot(
|
|
238
|
-
accountId: string,
|
|
239
|
-
followerCount: number,
|
|
240
|
-
followingCount: number
|
|
241
|
-
): AudienceSnapshot {
|
|
242
|
-
const db = getDatabase();
|
|
243
|
-
const id = crypto.randomUUID();
|
|
244
|
-
|
|
245
|
-
db.prepare(
|
|
246
|
-
`INSERT INTO audience_snapshots (id, account_id, follower_count, following_count)
|
|
247
|
-
VALUES (?, ?, ?, ?)`
|
|
248
|
-
).run(id, accountId, followerCount, followingCount);
|
|
249
|
-
|
|
250
|
-
return db.prepare("SELECT * FROM audience_snapshots WHERE id = ?").get(id) as AudienceSnapshot;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Creates a daily snapshot from current follower counts in the DB.
|
|
255
|
-
*/
|
|
256
|
-
export function trackGrowth(accountId: string): AudienceSnapshot {
|
|
257
|
-
const db = getDatabase();
|
|
258
|
-
|
|
259
|
-
const followerCount = (
|
|
260
|
-
db.prepare(
|
|
261
|
-
"SELECT COUNT(*) as count FROM followers WHERE account_id = ? AND following = 1"
|
|
262
|
-
).get(accountId) as { count: number }
|
|
263
|
-
).count;
|
|
264
|
-
|
|
265
|
-
const followingCount = (
|
|
266
|
-
db.prepare(
|
|
267
|
-
"SELECT COUNT(*) as count FROM followers WHERE account_id = ? AND following = 0"
|
|
268
|
-
).get(accountId) as { count: number }
|
|
269
|
-
).count;
|
|
270
|
-
|
|
271
|
-
return createSnapshot(accountId, followerCount, followingCount);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// ---- Insights ----
|
|
275
|
-
|
|
276
|
-
export function getAudienceInsights(accountId: string): AudienceInsights {
|
|
277
|
-
const db = getDatabase();
|
|
278
|
-
|
|
279
|
-
// Total current followers
|
|
280
|
-
const total_followers = (
|
|
281
|
-
db.prepare(
|
|
282
|
-
"SELECT COUNT(*) as count FROM followers WHERE account_id = ? AND following = 1"
|
|
283
|
-
).get(accountId) as { count: number }
|
|
284
|
-
).count;
|
|
285
|
-
|
|
286
|
-
// New followers in last 7 days
|
|
287
|
-
const new_followers_7d = (
|
|
288
|
-
db.prepare(
|
|
289
|
-
"SELECT COUNT(*) as count FROM followers WHERE account_id = ? AND following = 1 AND created_at >= datetime('now', '-7 days')"
|
|
290
|
-
).get(accountId) as { count: number }
|
|
291
|
-
).count;
|
|
292
|
-
|
|
293
|
-
// Lost followers in last 7 days
|
|
294
|
-
const lost_followers_7d = (
|
|
295
|
-
db.prepare(
|
|
296
|
-
"SELECT COUNT(*) as count FROM followers WHERE account_id = ? AND following = 0 AND unfollowed_at >= datetime('now', '-7 days')"
|
|
297
|
-
).get(accountId) as { count: number }
|
|
298
|
-
).count;
|
|
299
|
-
|
|
300
|
-
// Growth rates from snapshots
|
|
301
|
-
const growth_rate_7d = calculateGrowthRate(accountId, 7);
|
|
302
|
-
const growth_rate_30d = calculateGrowthRate(accountId, 30);
|
|
303
|
-
|
|
304
|
-
// Top followers by their follower count
|
|
305
|
-
const top_followers = listFollowers(accountId, { following: true, limit: 10 });
|
|
306
|
-
|
|
307
|
-
return {
|
|
308
|
-
total_followers,
|
|
309
|
-
growth_rate_7d,
|
|
310
|
-
growth_rate_30d,
|
|
311
|
-
new_followers_7d,
|
|
312
|
-
lost_followers_7d,
|
|
313
|
-
top_followers,
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function calculateGrowthRate(accountId: string, days: number): number {
|
|
318
|
-
const db = getDatabase();
|
|
319
|
-
|
|
320
|
-
const latest = db.prepare(
|
|
321
|
-
"SELECT follower_count FROM audience_snapshots WHERE account_id = ? ORDER BY snapshot_at DESC LIMIT 1"
|
|
322
|
-
).get(accountId) as { follower_count: number } | null;
|
|
323
|
-
|
|
324
|
-
const older = db.prepare(
|
|
325
|
-
`SELECT follower_count FROM audience_snapshots WHERE account_id = ? AND snapshot_at <= datetime('now', '-${days} days') ORDER BY snapshot_at DESC LIMIT 1`
|
|
326
|
-
).get(accountId) as { follower_count: number } | null;
|
|
327
|
-
|
|
328
|
-
if (!latest || !older || older.follower_count === 0) return 0;
|
|
329
|
-
|
|
330
|
-
return Math.round(((latest.follower_count - older.follower_count) / older.follower_count) * 10000) / 100;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// ---- Growth Chart ----
|
|
334
|
-
|
|
335
|
-
export function getFollowerGrowthChart(accountId: string, days: number = 30): GrowthPoint[] {
|
|
336
|
-
const db = getDatabase();
|
|
337
|
-
|
|
338
|
-
const rows = db.prepare(
|
|
339
|
-
`SELECT date(snapshot_at) as date, MAX(follower_count) as count
|
|
340
|
-
FROM audience_snapshots
|
|
341
|
-
WHERE account_id = ? AND snapshot_at >= datetime('now', '-${days} days')
|
|
342
|
-
GROUP BY date(snapshot_at)
|
|
343
|
-
ORDER BY date ASC`
|
|
344
|
-
).all(accountId) as GrowthPoint[];
|
|
345
|
-
|
|
346
|
-
return rows;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// ---- Top Followers ----
|
|
350
|
-
|
|
351
|
-
export function getTopFollowers(accountId: string, limit: number = 10): Follower[] {
|
|
352
|
-
return listFollowers(accountId, { following: true, limit });
|
|
353
|
-
}
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI-powered content generation for social media.
|
|
3
|
-
* Supports OpenAI (gpt-4o-mini) and Anthropic (claude-haiku) — same pattern as transcriber summarizer.
|
|
4
|
-
* Default: OpenAI if OPENAI_API_KEY set, else Anthropic.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { PLATFORM_LIMITS, type Platform } from "../db/social.js";
|
|
8
|
-
|
|
9
|
-
export type AIProvider = "openai" | "anthropic";
|
|
10
|
-
export type Tone = "professional" | "casual" | "witty";
|
|
11
|
-
|
|
12
|
-
export interface GeneratePostOptions {
|
|
13
|
-
tone?: Tone;
|
|
14
|
-
includeHashtags?: boolean;
|
|
15
|
-
includeEmoji?: boolean;
|
|
16
|
-
language?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface GeneratedPost {
|
|
20
|
-
content: string;
|
|
21
|
-
hashtags: string[];
|
|
22
|
-
suggested_media_prompt: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface OptimizedPost {
|
|
26
|
-
optimized_content: string;
|
|
27
|
-
improvements: string[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface RepurposedPost {
|
|
31
|
-
content: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ---- Provider Detection ----
|
|
35
|
-
|
|
36
|
-
export function getDefaultAIProvider(): AIProvider | null {
|
|
37
|
-
if (process.env["OPENAI_API_KEY"]) return "openai";
|
|
38
|
-
if (process.env["ANTHROPIC_API_KEY"]) return "anthropic";
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function resolveProvider(provider?: AIProvider): AIProvider {
|
|
43
|
-
const resolved = provider ?? getDefaultAIProvider();
|
|
44
|
-
if (!resolved) throw new Error("No AI API key found. Set OPENAI_API_KEY or ANTHROPIC_API_KEY.");
|
|
45
|
-
return resolved;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// ---- Prompt Builders (exported for testing) ----
|
|
49
|
-
|
|
50
|
-
export function buildGeneratePostPrompt(
|
|
51
|
-
topic: string,
|
|
52
|
-
platform: Platform,
|
|
53
|
-
options: GeneratePostOptions = {}
|
|
54
|
-
): string {
|
|
55
|
-
const limit = PLATFORM_LIMITS[platform];
|
|
56
|
-
const tone = options.tone || "professional";
|
|
57
|
-
const lang = options.language || "English";
|
|
58
|
-
const hashtagLine = options.includeHashtags !== false
|
|
59
|
-
? "Include 3-5 relevant hashtags."
|
|
60
|
-
: "Do NOT include hashtags.";
|
|
61
|
-
const emojiLine = options.includeEmoji
|
|
62
|
-
? "Use emojis where appropriate."
|
|
63
|
-
: "Do not use emojis.";
|
|
64
|
-
|
|
65
|
-
return `Write a social media post about the following topic for ${platform}.
|
|
66
|
-
Character limit: ${limit} characters. The post content MUST be within this limit.
|
|
67
|
-
Tone: ${tone}
|
|
68
|
-
Language: ${lang}
|
|
69
|
-
${hashtagLine}
|
|
70
|
-
${emojiLine}
|
|
71
|
-
|
|
72
|
-
Return ONLY valid JSON with these fields:
|
|
73
|
-
- "content": the post text (within ${limit} chars)
|
|
74
|
-
- "hashtags": array of hashtag strings (without # prefix)
|
|
75
|
-
- "suggested_media_prompt": a short description for AI image generation that would complement this post
|
|
76
|
-
|
|
77
|
-
Topic: ${topic}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function buildSuggestHashtagsPrompt(
|
|
81
|
-
content: string,
|
|
82
|
-
platform: Platform,
|
|
83
|
-
count: number
|
|
84
|
-
): string {
|
|
85
|
-
return `Analyze the following social media post for ${platform} and suggest ${count} relevant hashtags.
|
|
86
|
-
Return ONLY a valid JSON array of strings (without the # prefix).
|
|
87
|
-
|
|
88
|
-
Post: ${content}`;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function buildOptimizePostPrompt(content: string, platform: Platform): string {
|
|
92
|
-
const limit = PLATFORM_LIMITS[platform];
|
|
93
|
-
return `Optimize the following social media post for better engagement on ${platform}.
|
|
94
|
-
Character limit: ${limit} characters. The optimized content MUST be within this limit.
|
|
95
|
-
|
|
96
|
-
Return ONLY valid JSON with these fields:
|
|
97
|
-
- "optimized_content": the improved post text (within ${limit} chars)
|
|
98
|
-
- "improvements": array of strings explaining each change made
|
|
99
|
-
|
|
100
|
-
Original post: ${content}`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function buildGenerateThreadPrompt(topic: string, tweetCount: number): string {
|
|
104
|
-
return `Write a Twitter/X thread of exactly ${tweetCount} tweets about the following topic.
|
|
105
|
-
Each tweet MUST be within 280 characters.
|
|
106
|
-
Number each tweet (1/${tweetCount}, 2/${tweetCount}, etc.) at the start.
|
|
107
|
-
|
|
108
|
-
Return ONLY a valid JSON array of strings, one per tweet.
|
|
109
|
-
|
|
110
|
-
Topic: ${topic}`;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function buildRepurposePostPrompt(
|
|
114
|
-
content: string,
|
|
115
|
-
sourcePlatform: Platform,
|
|
116
|
-
targetPlatform: Platform
|
|
117
|
-
): string {
|
|
118
|
-
const targetLimit = PLATFORM_LIMITS[targetPlatform];
|
|
119
|
-
return `Adapt the following ${sourcePlatform} post for ${targetPlatform}.
|
|
120
|
-
Target character limit: ${targetLimit} characters. The content MUST be within this limit.
|
|
121
|
-
Adjust the tone, length, hashtag style, and formatting to match ${targetPlatform} conventions.
|
|
122
|
-
|
|
123
|
-
Return ONLY valid JSON with a single field:
|
|
124
|
-
- "content": the adapted post text (within ${targetLimit} chars)
|
|
125
|
-
|
|
126
|
-
Original ${sourcePlatform} post: ${content}`;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// ---- AI Functions ----
|
|
130
|
-
|
|
131
|
-
export async function generatePost(
|
|
132
|
-
topic: string,
|
|
133
|
-
platform: Platform,
|
|
134
|
-
options: GeneratePostOptions = {},
|
|
135
|
-
provider?: AIProvider
|
|
136
|
-
): Promise<GeneratedPost> {
|
|
137
|
-
const resolved = resolveProvider(provider);
|
|
138
|
-
const prompt = buildGeneratePostPrompt(topic, platform, options);
|
|
139
|
-
|
|
140
|
-
const raw = resolved === "openai"
|
|
141
|
-
? await callOpenAI(prompt, 500)
|
|
142
|
-
: await callAnthropic(prompt, 500);
|
|
143
|
-
|
|
144
|
-
return parseJSON<GeneratedPost>(raw, {
|
|
145
|
-
content: "",
|
|
146
|
-
hashtags: [],
|
|
147
|
-
suggested_media_prompt: "",
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export async function suggestHashtags(
|
|
152
|
-
content: string,
|
|
153
|
-
platform: Platform,
|
|
154
|
-
count: number = 5,
|
|
155
|
-
provider?: AIProvider
|
|
156
|
-
): Promise<string[]> {
|
|
157
|
-
const resolved = resolveProvider(provider);
|
|
158
|
-
const prompt = buildSuggestHashtagsPrompt(content, platform, count);
|
|
159
|
-
|
|
160
|
-
const raw = resolved === "openai"
|
|
161
|
-
? await callOpenAI(prompt, 200)
|
|
162
|
-
: await callAnthropic(prompt, 200);
|
|
163
|
-
|
|
164
|
-
const parsed = parseJSON<string[]>(raw, []);
|
|
165
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export async function optimizePost(
|
|
169
|
-
content: string,
|
|
170
|
-
platform: Platform,
|
|
171
|
-
provider?: AIProvider
|
|
172
|
-
): Promise<OptimizedPost> {
|
|
173
|
-
const resolved = resolveProvider(provider);
|
|
174
|
-
const prompt = buildOptimizePostPrompt(content, platform);
|
|
175
|
-
|
|
176
|
-
const raw = resolved === "openai"
|
|
177
|
-
? await callOpenAI(prompt, 600)
|
|
178
|
-
: await callAnthropic(prompt, 600);
|
|
179
|
-
|
|
180
|
-
return parseJSON<OptimizedPost>(raw, {
|
|
181
|
-
optimized_content: "",
|
|
182
|
-
improvements: [],
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export async function generateThread(
|
|
187
|
-
topic: string,
|
|
188
|
-
tweetCount: number = 5,
|
|
189
|
-
provider?: AIProvider
|
|
190
|
-
): Promise<string[]> {
|
|
191
|
-
const resolved = resolveProvider(provider);
|
|
192
|
-
const prompt = buildGenerateThreadPrompt(topic, tweetCount);
|
|
193
|
-
|
|
194
|
-
const raw = resolved === "openai"
|
|
195
|
-
? await callOpenAI(prompt, 1500)
|
|
196
|
-
: await callAnthropic(prompt, 1500);
|
|
197
|
-
|
|
198
|
-
const parsed = parseJSON<string[]>(raw, []);
|
|
199
|
-
return Array.isArray(parsed) ? parsed : [];
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export async function repurposePost(
|
|
203
|
-
content: string,
|
|
204
|
-
sourcePlatform: Platform,
|
|
205
|
-
targetPlatform: Platform,
|
|
206
|
-
provider?: AIProvider
|
|
207
|
-
): Promise<RepurposedPost> {
|
|
208
|
-
const resolved = resolveProvider(provider);
|
|
209
|
-
const prompt = buildRepurposePostPrompt(content, sourcePlatform, targetPlatform);
|
|
210
|
-
|
|
211
|
-
const raw = resolved === "openai"
|
|
212
|
-
? await callOpenAI(prompt, 500)
|
|
213
|
-
: await callAnthropic(prompt, 500);
|
|
214
|
-
|
|
215
|
-
return parseJSON<RepurposedPost>(raw, { content: "" });
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// ---- JSON Parser ----
|
|
219
|
-
|
|
220
|
-
function parseJSON<T>(raw: string, fallback: T): T {
|
|
221
|
-
const cleaned = raw.replace(/```json\n?/g, "").replace(/```\n?/g, "").trim();
|
|
222
|
-
try {
|
|
223
|
-
return JSON.parse(cleaned) as T;
|
|
224
|
-
} catch {
|
|
225
|
-
return fallback;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// ---- Shared AI Callers ----
|
|
230
|
-
|
|
231
|
-
export async function callOpenAI(prompt: string, maxTokens: number): Promise<string> {
|
|
232
|
-
const apiKey = process.env["OPENAI_API_KEY"];
|
|
233
|
-
if (!apiKey) throw new Error("OPENAI_API_KEY is not set");
|
|
234
|
-
|
|
235
|
-
const res = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
236
|
-
method: "POST",
|
|
237
|
-
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
238
|
-
body: JSON.stringify({
|
|
239
|
-
model: "gpt-4o-mini",
|
|
240
|
-
messages: [{ role: "user", content: prompt }],
|
|
241
|
-
max_tokens: maxTokens,
|
|
242
|
-
temperature: 0.7,
|
|
243
|
-
}),
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
if (!res.ok) {
|
|
247
|
-
const body = await res.text();
|
|
248
|
-
throw new Error(`OpenAI API error ${res.status}: ${body}`);
|
|
249
|
-
}
|
|
250
|
-
const data = (await res.json()) as { choices: Array<{ message: { content: string } }> };
|
|
251
|
-
return data.choices[0]?.message?.content?.trim() ?? "";
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export async function callAnthropic(prompt: string, maxTokens: number): Promise<string> {
|
|
255
|
-
const apiKey = process.env["ANTHROPIC_API_KEY"];
|
|
256
|
-
if (!apiKey) throw new Error("ANTHROPIC_API_KEY is not set");
|
|
257
|
-
|
|
258
|
-
const res = await fetch("https://api.anthropic.com/v1/messages", {
|
|
259
|
-
method: "POST",
|
|
260
|
-
headers: {
|
|
261
|
-
"x-api-key": apiKey,
|
|
262
|
-
"anthropic-version": "2023-06-01",
|
|
263
|
-
"Content-Type": "application/json",
|
|
264
|
-
},
|
|
265
|
-
body: JSON.stringify({
|
|
266
|
-
model: "claude-haiku-4-5-20251001",
|
|
267
|
-
max_tokens: maxTokens,
|
|
268
|
-
messages: [{ role: "user", content: prompt }],
|
|
269
|
-
}),
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
if (!res.ok) {
|
|
273
|
-
const body = await res.text();
|
|
274
|
-
throw new Error(`Anthropic API error ${res.status}: ${body}`);
|
|
275
|
-
}
|
|
276
|
-
const data = (await res.json()) as { content: Array<{ type: string; text: string }> };
|
|
277
|
-
return data.content.find((b) => b.type === "text")?.text?.trim() ?? "";
|
|
278
|
-
}
|