post-engineer-mcp 1.29.0 → 1.31.0
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 +10 -0
- package/dist/client.d.ts +53 -2
- package/dist/client.js +256 -3
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +19 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.js +32 -2
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +11 -0
- package/dist/limits.js +11 -0
- package/dist/limits.js.map +1 -1
- package/dist/tools.d.ts +152 -2
- package/dist/tools.js +656 -1
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
package/dist/tools.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { MAX_LIBRARY_IMAGES, MAX_LIBRARY_IMAGE_MB, MAX_LIBRARY_TAG_LENGTH, MAX_LIBRARY_DESCRIPTION_LENGTH, } from './client.js';
|
|
2
|
+
import { MAX_LIBRARY_IMAGES, MAX_LIBRARY_IMAGE_MB, MAX_LIBRARY_TAG_LENGTH, MAX_LIBRARY_DESCRIPTION_LENGTH, MAX_UPLOAD_VIDEO_GB, } from './client.js';
|
|
3
3
|
import { getErrorMessage, ApiError } from './errors.js';
|
|
4
4
|
// Shared field definitions: path/tag/description limits appear in both the
|
|
5
5
|
// create-persona images array and add_persona_image — define once so the
|
|
@@ -68,6 +68,88 @@ export const CancelScheduleShape = {
|
|
|
68
68
|
scheduleId: z.string().min(1, 'scheduleId is required').describe('The ID of the schedule to cancel'),
|
|
69
69
|
};
|
|
70
70
|
export const CancelScheduleSchema = z.object(CancelScheduleShape);
|
|
71
|
+
export const GetSlotShape = {
|
|
72
|
+
slotId: z
|
|
73
|
+
.string()
|
|
74
|
+
.min(1, 'slotId is required')
|
|
75
|
+
.describe('The slot ID (the slotId field from list_posts or generate_persona_videos).'),
|
|
76
|
+
};
|
|
77
|
+
export const GetSlotSchema = z.object(GetSlotShape);
|
|
78
|
+
export const UpdateSlotTopicShape = {
|
|
79
|
+
slotId: z
|
|
80
|
+
.string()
|
|
81
|
+
.min(1, 'slotId is required')
|
|
82
|
+
.describe('The slot ID (the slotId field from list_posts or generate_persona_videos).'),
|
|
83
|
+
topic: z
|
|
84
|
+
.string()
|
|
85
|
+
.min(1, 'topic is required')
|
|
86
|
+
.describe('The new topic text for the slot. Only a slot that has not started generating (status pending/awaiting) can be edited; published or mid-flight slots are rejected.'),
|
|
87
|
+
};
|
|
88
|
+
export const UpdateSlotTopicSchema = z.object(UpdateSlotTopicShape);
|
|
89
|
+
export const DeleteSlotShape = {
|
|
90
|
+
slotId: z
|
|
91
|
+
.string()
|
|
92
|
+
.min(1, 'slotId is required')
|
|
93
|
+
.describe('The slot ID to delete. Only pending (awaiting) or failed slots can be deleted; published or mid-flight slots are rejected. The schedule\'s last slot cannot be deleted — delete the whole schedule with cancel_schedule instead.'),
|
|
94
|
+
};
|
|
95
|
+
export const DeleteSlotSchema = z.object(DeleteSlotShape);
|
|
96
|
+
export const ListVideoGenerationsShape = {
|
|
97
|
+
limit: z
|
|
98
|
+
.number()
|
|
99
|
+
.int()
|
|
100
|
+
.min(1)
|
|
101
|
+
.max(200)
|
|
102
|
+
.optional()
|
|
103
|
+
.describe('Max generations to return (1-200). Defaults to 50, newest first.'),
|
|
104
|
+
};
|
|
105
|
+
export const ListVideoGenerationsSchema = z.object(ListVideoGenerationsShape);
|
|
106
|
+
export const GetVideoGenerationShape = {
|
|
107
|
+
generationId: z
|
|
108
|
+
.string()
|
|
109
|
+
.min(1, 'generationId is required')
|
|
110
|
+
.describe('The generation ID (the generationId field from list_video_generations).'),
|
|
111
|
+
};
|
|
112
|
+
export const GetVideoGenerationSchema = z.object(GetVideoGenerationShape);
|
|
113
|
+
export const ListTokenTransactionsShape = {
|
|
114
|
+
limit: z
|
|
115
|
+
.number()
|
|
116
|
+
.int()
|
|
117
|
+
.min(1)
|
|
118
|
+
.max(100)
|
|
119
|
+
.optional()
|
|
120
|
+
.describe('Max transactions to return (1-100). Defaults to 20, newest first.'),
|
|
121
|
+
offset: z
|
|
122
|
+
.number()
|
|
123
|
+
.int()
|
|
124
|
+
.min(0)
|
|
125
|
+
.optional()
|
|
126
|
+
.describe('How many newest transactions to skip for paging. Defaults to 0.'),
|
|
127
|
+
};
|
|
128
|
+
export const ListTokenTransactionsSchema = z.object(ListTokenTransactionsShape);
|
|
129
|
+
export const GetPersonaDeletePreviewShape = {
|
|
130
|
+
personaId: z
|
|
131
|
+
.string()
|
|
132
|
+
.min(1, 'personaId is required')
|
|
133
|
+
.describe('The persona ID to preview deletion for. Read-only: shows what deleting the persona would remove (counts plus per-video download links).'),
|
|
134
|
+
};
|
|
135
|
+
export const GetPersonaDeletePreviewSchema = z.object(GetPersonaDeletePreviewShape);
|
|
136
|
+
export const DeletePersonaShape = {
|
|
137
|
+
personaId: z
|
|
138
|
+
.string()
|
|
139
|
+
.min(1, 'personaId is required')
|
|
140
|
+
.describe('The persona ID to delete. DESTRUCTIVE and irreversible: deletes the persona, all its schedules and slots, all generated videos, and the image library. No token refunds — prepaid tokens for pending slots are forfeited. Call get_persona_delete_preview first to see exactly what will be removed.'),
|
|
141
|
+
};
|
|
142
|
+
export const DeletePersonaSchema = z.object(DeletePersonaShape);
|
|
143
|
+
export const DisconnectAccountShape = {
|
|
144
|
+
provider: z
|
|
145
|
+
.enum(['youtube', 'instagram', 'linkedin', 'bluesky'])
|
|
146
|
+
.describe('The social platform of the account to disconnect.'),
|
|
147
|
+
providerAccountId: z
|
|
148
|
+
.string()
|
|
149
|
+
.min(1, 'providerAccountId is required')
|
|
150
|
+
.describe('The account ID on that provider (the channelId / igUserId / providerAccountId / did field from list_social_accounts).'),
|
|
151
|
+
};
|
|
152
|
+
export const DisconnectAccountSchema = z.object(DisconnectAccountShape);
|
|
71
153
|
export const GetTokenBalanceShape = {};
|
|
72
154
|
export const GetTokenBalanceSchema = z.object(GetTokenBalanceShape);
|
|
73
155
|
// Loopback hosts for which a plain http: media/webhook URL is tolerated
|
|
@@ -337,6 +419,482 @@ export async function handleListPosts(client, args) {
|
|
|
337
419
|
export async function handleCancelSchedule(client, args) {
|
|
338
420
|
return handleLibraryCall(() => client.cancelSchedule(args.scheduleId), 'cancelling schedule', 'Schedule cancelled successfully');
|
|
339
421
|
}
|
|
422
|
+
export async function handleGetSlot(client, args) {
|
|
423
|
+
try {
|
|
424
|
+
const narrowed = narrowSlotDetail(await client.getSlot(args.slotId));
|
|
425
|
+
const slot = narrowed.slot;
|
|
426
|
+
const humanSummary = `Slot ${slot.id ?? args.slotId}: "${slot.topic ?? '(untitled)'}" — ${slot.status ?? 'unknown'}, scheduled for ${slot.slotAt ?? '(unscheduled)'}.`;
|
|
427
|
+
return {
|
|
428
|
+
content: [
|
|
429
|
+
{
|
|
430
|
+
type: 'text',
|
|
431
|
+
text: `${humanSummary}\n${JSON.stringify(narrowed, null, 2)}`,
|
|
432
|
+
},
|
|
433
|
+
],
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
438
|
+
return {
|
|
439
|
+
content: [
|
|
440
|
+
{
|
|
441
|
+
type: 'text',
|
|
442
|
+
text: `Error getting slot: ${JSON.stringify({
|
|
443
|
+
code: error.code,
|
|
444
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
445
|
+
field: error.field,
|
|
446
|
+
})}`,
|
|
447
|
+
},
|
|
448
|
+
],
|
|
449
|
+
isError: true,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
return {
|
|
453
|
+
content: [
|
|
454
|
+
{
|
|
455
|
+
type: 'text',
|
|
456
|
+
text: `Error getting slot: ${getErrorMessage(error)}`,
|
|
457
|
+
},
|
|
458
|
+
],
|
|
459
|
+
isError: true,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
export async function handleUpdateSlotTopic(client, args) {
|
|
464
|
+
try {
|
|
465
|
+
const result = (await client.updateSlotTopic(args.slotId, args.topic));
|
|
466
|
+
const topic = typeof result.topic === 'string' ? result.topic : args.topic;
|
|
467
|
+
return {
|
|
468
|
+
content: [
|
|
469
|
+
{
|
|
470
|
+
type: 'text',
|
|
471
|
+
text: `Slot ${args.slotId} topic updated to "${topic}".\n${JSON.stringify({ success: true, topic }, null, 2)}`,
|
|
472
|
+
},
|
|
473
|
+
],
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
catch (error) {
|
|
477
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
478
|
+
return {
|
|
479
|
+
content: [
|
|
480
|
+
{
|
|
481
|
+
type: 'text',
|
|
482
|
+
text: `Error updating slot topic: ${JSON.stringify({
|
|
483
|
+
code: error.code,
|
|
484
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
485
|
+
field: error.field,
|
|
486
|
+
})}`,
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
isError: true,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
return {
|
|
493
|
+
content: [
|
|
494
|
+
{
|
|
495
|
+
type: 'text',
|
|
496
|
+
text: `Error updating slot topic: ${getErrorMessage(error)}`,
|
|
497
|
+
},
|
|
498
|
+
],
|
|
499
|
+
isError: true,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
export async function handleDeleteSlot(client, args) {
|
|
504
|
+
return handleLibraryCall(() => client.deleteSlot(args.slotId), 'deleting slot', `Slot ${args.slotId} deleted`);
|
|
505
|
+
}
|
|
506
|
+
export async function handleListVideoGenerations(client, args) {
|
|
507
|
+
try {
|
|
508
|
+
const generations = narrowVideoGenerations(await client.listVideoGenerations(args.limit));
|
|
509
|
+
const humanSummary = `${generations.length} video generation(s) in history (newest first).`;
|
|
510
|
+
return {
|
|
511
|
+
content: [
|
|
512
|
+
{
|
|
513
|
+
type: 'text',
|
|
514
|
+
text: `${humanSummary}\n${JSON.stringify({ generations }, null, 2)}`,
|
|
515
|
+
},
|
|
516
|
+
],
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
catch (error) {
|
|
520
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
521
|
+
return {
|
|
522
|
+
content: [
|
|
523
|
+
{
|
|
524
|
+
type: 'text',
|
|
525
|
+
text: `Error listing video generations: ${JSON.stringify({
|
|
526
|
+
code: error.code,
|
|
527
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
528
|
+
field: error.field,
|
|
529
|
+
})}`,
|
|
530
|
+
},
|
|
531
|
+
],
|
|
532
|
+
isError: true,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
return {
|
|
536
|
+
content: [
|
|
537
|
+
{
|
|
538
|
+
type: 'text',
|
|
539
|
+
text: `Error listing video generations: ${getErrorMessage(error)}`,
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
isError: true,
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
export async function handleGetVideoGeneration(client, args) {
|
|
547
|
+
try {
|
|
548
|
+
const result = (await client.getVideoGeneration(args.generationId));
|
|
549
|
+
const generation = narrowVideoGeneration(result !== null && typeof result === 'object' ? result.generation : null);
|
|
550
|
+
const humanSummary = `Generation ${generation.generationId ?? args.generationId}: "${generation.videoSubject ?? '(untitled)'}" — ${generation.status ?? 'unknown'}.`;
|
|
551
|
+
return {
|
|
552
|
+
content: [
|
|
553
|
+
{
|
|
554
|
+
type: 'text',
|
|
555
|
+
text: `${humanSummary}\n${JSON.stringify({ generation }, null, 2)}`,
|
|
556
|
+
},
|
|
557
|
+
],
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
catch (error) {
|
|
561
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
562
|
+
return {
|
|
563
|
+
content: [
|
|
564
|
+
{
|
|
565
|
+
type: 'text',
|
|
566
|
+
text: `Error getting video generation: ${JSON.stringify({
|
|
567
|
+
code: error.code,
|
|
568
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
569
|
+
field: error.field,
|
|
570
|
+
})}`,
|
|
571
|
+
},
|
|
572
|
+
],
|
|
573
|
+
isError: true,
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
return {
|
|
577
|
+
content: [
|
|
578
|
+
{
|
|
579
|
+
type: 'text',
|
|
580
|
+
text: `Error getting video generation: ${getErrorMessage(error)}`,
|
|
581
|
+
},
|
|
582
|
+
],
|
|
583
|
+
isError: true,
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
/** Narrows one video_generations row. Anything the API adds later rides
|
|
588
|
+
* through unparsed — the projection only pins what the tool renders and
|
|
589
|
+
* documents. */
|
|
590
|
+
function narrowVideoGeneration(row) {
|
|
591
|
+
const record = typeof row === 'object' && row !== null ? row : {};
|
|
592
|
+
const str = (value) => typeof value === 'string' ? value : null;
|
|
593
|
+
return {
|
|
594
|
+
id: str(record.id),
|
|
595
|
+
generationId: str(record.generationId),
|
|
596
|
+
engineTaskId: str(record.engineTaskId),
|
|
597
|
+
personaName: str(record.personaName),
|
|
598
|
+
videoSubject: str(record.videoSubject),
|
|
599
|
+
status: str(record.status),
|
|
600
|
+
errorCode: str(record.errorCode),
|
|
601
|
+
tokensRefunded: typeof record.tokensRefunded === 'boolean' ? record.tokensRefunded : null,
|
|
602
|
+
createdAt: str(record.createdAt),
|
|
603
|
+
completedAt: str(record.completedAt),
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
/** Narrows the GET /api/persona/video-generations envelope to the pinned
|
|
607
|
+
* row fields. */
|
|
608
|
+
function narrowVideoGenerations(result) {
|
|
609
|
+
const record = typeof result === 'object' && result !== null
|
|
610
|
+
? result
|
|
611
|
+
: {};
|
|
612
|
+
const raw = Array.isArray(record.generations) ? record.generations : [];
|
|
613
|
+
return raw.map((row) => narrowVideoGeneration(row));
|
|
614
|
+
}
|
|
615
|
+
export async function handleListTokenTransactions(client, args) {
|
|
616
|
+
try {
|
|
617
|
+
const narrowed = narrowTokenTransactions(await client.listTokenTransactions(args.limit, args.offset));
|
|
618
|
+
const shown = narrowed.transactions.length;
|
|
619
|
+
const humanSummary = `Token ledger: showing ${shown} of ${narrowed.total ?? '?'} transaction(s) (newest first). ` +
|
|
620
|
+
`Negative amounts are spends, positive amounts are credits.`;
|
|
621
|
+
return {
|
|
622
|
+
content: [
|
|
623
|
+
{
|
|
624
|
+
type: 'text',
|
|
625
|
+
text: `${humanSummary}\n${JSON.stringify(narrowed, null, 2)}`,
|
|
626
|
+
},
|
|
627
|
+
],
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
catch (error) {
|
|
631
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
632
|
+
return {
|
|
633
|
+
content: [
|
|
634
|
+
{
|
|
635
|
+
type: 'text',
|
|
636
|
+
text: `Error listing token transactions: ${JSON.stringify({
|
|
637
|
+
code: error.code,
|
|
638
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
639
|
+
field: error.field,
|
|
640
|
+
})}`,
|
|
641
|
+
},
|
|
642
|
+
],
|
|
643
|
+
isError: true,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
content: [
|
|
648
|
+
{
|
|
649
|
+
type: 'text',
|
|
650
|
+
text: `Error listing token transactions: ${getErrorMessage(error)}`,
|
|
651
|
+
},
|
|
652
|
+
],
|
|
653
|
+
isError: true,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
export async function handleGetPersonaDeletePreview(client, args) {
|
|
658
|
+
try {
|
|
659
|
+
const narrowed = narrowDeletePreview(await client.getPersonaDeletePreview(args.personaId));
|
|
660
|
+
const counts = narrowed.counts;
|
|
661
|
+
const humanSummary = `Deleting persona "${narrowed.persona.name ?? args.personaId}" would remove ` +
|
|
662
|
+
`${counts.schedules ?? '?'} schedule(s), ${counts.upcomingSlots ?? '?'} upcoming slot(s), ` +
|
|
663
|
+
`${counts.publishedSlots ?? '?'} published slot(s), ${counts.generatedVideos ?? '?'} generated video(s), ` +
|
|
664
|
+
`and ${counts.personaImages ?? '?'} library image(s). No token refunds.`;
|
|
665
|
+
return {
|
|
666
|
+
content: [
|
|
667
|
+
{
|
|
668
|
+
type: 'text',
|
|
669
|
+
text: `${humanSummary}\n${JSON.stringify(narrowed, null, 2)}`,
|
|
670
|
+
},
|
|
671
|
+
],
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
catch (error) {
|
|
675
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
676
|
+
return {
|
|
677
|
+
content: [
|
|
678
|
+
{
|
|
679
|
+
type: 'text',
|
|
680
|
+
text: `Error getting persona delete preview: ${JSON.stringify({
|
|
681
|
+
code: error.code,
|
|
682
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
683
|
+
field: error.field,
|
|
684
|
+
})}`,
|
|
685
|
+
},
|
|
686
|
+
],
|
|
687
|
+
isError: true,
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
return {
|
|
691
|
+
content: [
|
|
692
|
+
{
|
|
693
|
+
type: 'text',
|
|
694
|
+
text: `Error getting persona delete preview: ${getErrorMessage(error)}`,
|
|
695
|
+
},
|
|
696
|
+
],
|
|
697
|
+
isError: true,
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
export async function handleDeletePersona(client, args) {
|
|
702
|
+
try {
|
|
703
|
+
await client.deletePersona(args.personaId);
|
|
704
|
+
return {
|
|
705
|
+
content: [
|
|
706
|
+
{
|
|
707
|
+
type: 'text',
|
|
708
|
+
text: `Persona ${args.personaId} deleted: the persona, all its schedules and slots, ` +
|
|
709
|
+
`all generated videos, and the image library are gone. No token refunds were issued.`,
|
|
710
|
+
},
|
|
711
|
+
],
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
catch (error) {
|
|
715
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
716
|
+
return {
|
|
717
|
+
content: [
|
|
718
|
+
{
|
|
719
|
+
type: 'text',
|
|
720
|
+
text: `Error deleting persona: ${JSON.stringify({
|
|
721
|
+
code: error.code,
|
|
722
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
723
|
+
field: error.field,
|
|
724
|
+
})}`,
|
|
725
|
+
},
|
|
726
|
+
],
|
|
727
|
+
isError: true,
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
return {
|
|
731
|
+
content: [
|
|
732
|
+
{
|
|
733
|
+
type: 'text',
|
|
734
|
+
text: `Error deleting persona: ${getErrorMessage(error)}`,
|
|
735
|
+
},
|
|
736
|
+
],
|
|
737
|
+
isError: true,
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
export async function handleDisconnectAccount(client, args) {
|
|
742
|
+
try {
|
|
743
|
+
await client.disconnectAccount(args.provider, args.providerAccountId);
|
|
744
|
+
return {
|
|
745
|
+
content: [
|
|
746
|
+
{
|
|
747
|
+
type: 'text',
|
|
748
|
+
text: `Account ${args.providerAccountId} (${args.provider}) disconnected.`,
|
|
749
|
+
},
|
|
750
|
+
],
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
catch (error) {
|
|
754
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
755
|
+
return {
|
|
756
|
+
content: [
|
|
757
|
+
{
|
|
758
|
+
type: 'text',
|
|
759
|
+
text: `Error disconnecting account: ${JSON.stringify({
|
|
760
|
+
code: error.code,
|
|
761
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
762
|
+
field: error.field,
|
|
763
|
+
})}`,
|
|
764
|
+
},
|
|
765
|
+
],
|
|
766
|
+
isError: true,
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
return {
|
|
770
|
+
content: [
|
|
771
|
+
{
|
|
772
|
+
type: 'text',
|
|
773
|
+
text: `Error disconnecting account: ${getErrorMessage(error)}`,
|
|
774
|
+
},
|
|
775
|
+
],
|
|
776
|
+
isError: true,
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
/** Narrows the GET /api/persona/delete-preview envelope: the persona, the
|
|
781
|
+
* removal counts, and the per-video download links. Anything the API adds
|
|
782
|
+
* later rides through unparsed. */
|
|
783
|
+
function narrowDeletePreview(result) {
|
|
784
|
+
const record = typeof result === 'object' && result !== null
|
|
785
|
+
? result
|
|
786
|
+
: {};
|
|
787
|
+
const persona = typeof record.persona === 'object' && record.persona !== null
|
|
788
|
+
? record.persona
|
|
789
|
+
: {};
|
|
790
|
+
const counts = typeof record.counts === 'object' && record.counts !== null
|
|
791
|
+
? record.counts
|
|
792
|
+
: {};
|
|
793
|
+
const rawVideos = Array.isArray(record.videos) ? record.videos : [];
|
|
794
|
+
const str = (value) => typeof value === 'string' ? value : null;
|
|
795
|
+
const num = (value) => typeof value === 'number' ? value : null;
|
|
796
|
+
const bool = (value) => typeof value === 'boolean' ? value : null;
|
|
797
|
+
return {
|
|
798
|
+
persona: { id: str(persona.id), name: str(persona.name) },
|
|
799
|
+
counts: {
|
|
800
|
+
schedules: num(counts.schedules),
|
|
801
|
+
upcomingSlots: num(counts.upcomingSlots),
|
|
802
|
+
publishedSlots: num(counts.publishedSlots),
|
|
803
|
+
failedSlots: num(counts.failedSlots),
|
|
804
|
+
generatedVideos: num(counts.generatedVideos),
|
|
805
|
+
personaImages: num(counts.personaImages),
|
|
806
|
+
},
|
|
807
|
+
videos: rawVideos.map((video) => {
|
|
808
|
+
const v = typeof video === 'object' && video !== null
|
|
809
|
+
? video
|
|
810
|
+
: {};
|
|
811
|
+
return {
|
|
812
|
+
taskId: str(v.taskId),
|
|
813
|
+
topic: str(v.topic),
|
|
814
|
+
status: str(v.status),
|
|
815
|
+
downloadUrl: str(v.downloadUrl),
|
|
816
|
+
};
|
|
817
|
+
}),
|
|
818
|
+
videosTruncated: bool(record.videosTruncated),
|
|
819
|
+
linksIncomplete: bool(record.linksIncomplete),
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
/** Narrows the GET /api/billing/transactions envelope. Anything the API
|
|
823
|
+
* adds later rides through unparsed — the projection only pins what the
|
|
824
|
+
* tool renders and documents. */
|
|
825
|
+
function narrowTokenTransactions(result) {
|
|
826
|
+
const record = typeof result === 'object' && result !== null
|
|
827
|
+
? result
|
|
828
|
+
: {};
|
|
829
|
+
const raw = Array.isArray(record.transactions) ? record.transactions : [];
|
|
830
|
+
const str = (value) => typeof value === 'string' ? value : null;
|
|
831
|
+
const num = (value) => typeof value === 'number' ? value : null;
|
|
832
|
+
return {
|
|
833
|
+
transactions: raw.map((row) => {
|
|
834
|
+
const r = typeof row === 'object' && row !== null ? row : {};
|
|
835
|
+
return {
|
|
836
|
+
id: str(r.id),
|
|
837
|
+
amount: num(r.amount),
|
|
838
|
+
type: str(r.type),
|
|
839
|
+
description: str(r.description),
|
|
840
|
+
reason: str(r.reason),
|
|
841
|
+
generationId: str(r.generationId),
|
|
842
|
+
createdAt: str(r.createdAt),
|
|
843
|
+
};
|
|
844
|
+
}),
|
|
845
|
+
total: num(record.total),
|
|
846
|
+
limit: num(record.limit),
|
|
847
|
+
offset: num(record.offset),
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
/** Narrows the GET /api/schedule/slots/[slotId] envelope to the fields the
|
|
851
|
+
* tool contract promises: the slot row, its schedule, and the persona.
|
|
852
|
+
* Anything the API adds later rides through unparsed — the projection only
|
|
853
|
+
* pins what the tool renders and documents. */
|
|
854
|
+
function narrowSlotDetail(result) {
|
|
855
|
+
const record = typeof result === 'object' && result !== null
|
|
856
|
+
? result
|
|
857
|
+
: {};
|
|
858
|
+
const slot = typeof record.slot === 'object' && record.slot !== null
|
|
859
|
+
? record.slot
|
|
860
|
+
: {};
|
|
861
|
+
const schedule = typeof record.schedule === 'object' && record.schedule !== null
|
|
862
|
+
? record.schedule
|
|
863
|
+
: null;
|
|
864
|
+
const persona = typeof record.persona === 'object' && record.persona !== null
|
|
865
|
+
? record.persona
|
|
866
|
+
: null;
|
|
867
|
+
const str = (value) => typeof value === 'string' ? value : null;
|
|
868
|
+
const num = (value) => typeof value === 'number' ? value : null;
|
|
869
|
+
const providers = Array.isArray(schedule?.providers)
|
|
870
|
+
? schedule.providers.filter((p) => typeof p === 'string')
|
|
871
|
+
: [];
|
|
872
|
+
return {
|
|
873
|
+
slot: {
|
|
874
|
+
id: str(slot.id),
|
|
875
|
+
scheduleId: str(slot.scheduleId),
|
|
876
|
+
slotAt: str(slot.slotAt),
|
|
877
|
+
status: str(slot.status),
|
|
878
|
+
topic: str(slot.topic),
|
|
879
|
+
taskId: str(slot.taskId),
|
|
880
|
+
progress: num(slot.progress),
|
|
881
|
+
stage: str(slot.stage),
|
|
882
|
+
error: str(slot.error),
|
|
883
|
+
publishedAt: str(slot.publishedAt),
|
|
884
|
+
},
|
|
885
|
+
schedule: schedule === null
|
|
886
|
+
? null
|
|
887
|
+
: {
|
|
888
|
+
id: str(schedule.id),
|
|
889
|
+
providers,
|
|
890
|
+
publishMode: str(schedule.publishMode),
|
|
891
|
+
timezone: str(schedule.timezone),
|
|
892
|
+
},
|
|
893
|
+
persona: persona === null
|
|
894
|
+
? null
|
|
895
|
+
: { id: str(persona.id), name: str(persona.name) },
|
|
896
|
+
};
|
|
897
|
+
}
|
|
340
898
|
export async function handleGetTokenBalance(client) {
|
|
341
899
|
return handleLibraryCall(() => client.getTokenBalance(), 'getting token balance');
|
|
342
900
|
}
|
|
@@ -556,4 +1114,101 @@ function narrowScheduledVideos(result) {
|
|
|
556
1114
|
replayed: typeof record.replayed === 'boolean' ? record.replayed : null,
|
|
557
1115
|
};
|
|
558
1116
|
}
|
|
1117
|
+
export const PublishVideoDirectShape = {
|
|
1118
|
+
provider: z
|
|
1119
|
+
.enum(['youtube', 'instagram', 'linkedin', 'bluesky'])
|
|
1120
|
+
.describe('The social platform to publish the video to.'),
|
|
1121
|
+
videoPath: z
|
|
1122
|
+
.string()
|
|
1123
|
+
.min(1, 'videoPath is required')
|
|
1124
|
+
.describe(`Local path to the video file (.mp4 or .mov, max ${MAX_UPLOAD_VIDEO_GB}GB). The video is published as-is: no generation, no schedule.`),
|
|
1125
|
+
accountIds: z
|
|
1126
|
+
.array(z.string().min(1))
|
|
1127
|
+
.min(1, 'At least one account ID is required')
|
|
1128
|
+
.describe('Target accounts: the IDs from list_social_accounts (channel IDs for YouTube, IG user IDs for Instagram, DIDs for Bluesky, member IDs or org URNs for LinkedIn).'),
|
|
1129
|
+
title: z
|
|
1130
|
+
.string()
|
|
1131
|
+
.optional()
|
|
1132
|
+
.describe('YouTube only: required video title.'),
|
|
1133
|
+
description: z
|
|
1134
|
+
.string()
|
|
1135
|
+
.optional()
|
|
1136
|
+
.describe('YouTube only: required video description.'),
|
|
1137
|
+
tags: z
|
|
1138
|
+
.array(z.string())
|
|
1139
|
+
.optional()
|
|
1140
|
+
.describe('YouTube only: required list of tags.'),
|
|
1141
|
+
privacyStatus: z
|
|
1142
|
+
.enum(['public', 'private', 'unlisted'])
|
|
1143
|
+
.optional()
|
|
1144
|
+
.describe('YouTube only: required privacy status.'),
|
|
1145
|
+
caption: z
|
|
1146
|
+
.string()
|
|
1147
|
+
.optional()
|
|
1148
|
+
.describe('Instagram/Bluesky/LinkedIn: required caption.'),
|
|
1149
|
+
};
|
|
1150
|
+
export const PublishVideoDirectSchema = z.object(PublishVideoDirectShape);
|
|
1151
|
+
export async function handlePublishVideoDirect(client, args) {
|
|
1152
|
+
try {
|
|
1153
|
+
const result = await client.publishVideoDirect({
|
|
1154
|
+
provider: args.provider,
|
|
1155
|
+
videoPath: args.videoPath,
|
|
1156
|
+
accountIds: args.accountIds,
|
|
1157
|
+
title: args.title,
|
|
1158
|
+
description: args.description,
|
|
1159
|
+
tags: args.tags,
|
|
1160
|
+
privacyStatus: args.privacyStatus,
|
|
1161
|
+
caption: args.caption,
|
|
1162
|
+
});
|
|
1163
|
+
const lines = result.results.map((account) => {
|
|
1164
|
+
if (account.success) {
|
|
1165
|
+
const link = account.videoUrl ?? account.postId ?? account.videoId ?? '';
|
|
1166
|
+
return `- ${account.accountId}: published${link ? ` (${link})` : ''}`;
|
|
1167
|
+
}
|
|
1168
|
+
return `- ${account.accountId}: FAILED — ${account.error ?? 'unknown error'}`;
|
|
1169
|
+
});
|
|
1170
|
+
return {
|
|
1171
|
+
content: [
|
|
1172
|
+
{
|
|
1173
|
+
type: 'text',
|
|
1174
|
+
text: `Direct publish to ${result.provider}: ${result.successCount}/${result.results.length} accounts succeeded.\n` +
|
|
1175
|
+
lines.join('\n') +
|
|
1176
|
+
`\n${JSON.stringify({
|
|
1177
|
+
success: result.success,
|
|
1178
|
+
provider: result.provider,
|
|
1179
|
+
successCount: result.successCount,
|
|
1180
|
+
results: result.results,
|
|
1181
|
+
logId: result.logId,
|
|
1182
|
+
})}`,
|
|
1183
|
+
},
|
|
1184
|
+
],
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
catch (error) {
|
|
1188
|
+
if (error instanceof ApiError && error.code !== null) {
|
|
1189
|
+
return {
|
|
1190
|
+
content: [
|
|
1191
|
+
{
|
|
1192
|
+
type: 'text',
|
|
1193
|
+
text: `Error publishing video: ${JSON.stringify({
|
|
1194
|
+
code: error.code,
|
|
1195
|
+
message: sanitizeEngineError(getErrorMessage(error)),
|
|
1196
|
+
field: error.field,
|
|
1197
|
+
})}`,
|
|
1198
|
+
},
|
|
1199
|
+
],
|
|
1200
|
+
isError: true,
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
return {
|
|
1204
|
+
content: [
|
|
1205
|
+
{
|
|
1206
|
+
type: 'text',
|
|
1207
|
+
text: `Error publishing video: ${getErrorMessage(error)}`,
|
|
1208
|
+
},
|
|
1209
|
+
],
|
|
1210
|
+
isError: true,
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
559
1214
|
//# sourceMappingURL=tools.js.map
|