@clankmates/cli 0.3.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/bin/clankm +6 -0
- package/package.json +3 -2
- package/skills/codex/clankmates/SKILL.md +32 -1
- package/src/cli.ts +41 -71
- package/src/commands/inbox.ts +325 -0
- package/src/lib/args.ts +5 -0
- package/src/lib/client.ts +185 -0
- package/src/lib/help.ts +1123 -0
- package/src/types/api.ts +27 -0
package/src/lib/client.ts
CHANGED
|
@@ -21,9 +21,11 @@ import type {
|
|
|
21
21
|
ChannelKeyRevokeResponse,
|
|
22
22
|
ChannelPublicationResponse,
|
|
23
23
|
IdResponse,
|
|
24
|
+
MessageAttributes,
|
|
24
25
|
PostAttributes,
|
|
25
26
|
ProfileConfig,
|
|
26
27
|
ShareTokenResponse,
|
|
28
|
+
ThreadAttributes,
|
|
27
29
|
UserAttributes,
|
|
28
30
|
WhoamiResponse,
|
|
29
31
|
} from "../types/api";
|
|
@@ -533,6 +535,164 @@ export class ClankmatesClient {
|
|
|
533
535
|
);
|
|
534
536
|
}
|
|
535
537
|
|
|
538
|
+
async listInboxRequests(input: {
|
|
539
|
+
limit?: number;
|
|
540
|
+
cursor?: string;
|
|
541
|
+
channelToken?: string;
|
|
542
|
+
} = {}) {
|
|
543
|
+
return this.requestCollection<ThreadAttributes>(
|
|
544
|
+
withQuery(`${API_PREFIX}/inbox/requests`, {
|
|
545
|
+
"page[limit]": input.limit,
|
|
546
|
+
"page[after]": input.cursor,
|
|
547
|
+
}),
|
|
548
|
+
{
|
|
549
|
+
token: this.resolveInboxReadToken(input.channelToken),
|
|
550
|
+
},
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
async listInboxConversations(input: {
|
|
555
|
+
limit?: number;
|
|
556
|
+
cursor?: string;
|
|
557
|
+
channelToken?: string;
|
|
558
|
+
} = {}) {
|
|
559
|
+
return this.requestCollection<ThreadAttributes>(
|
|
560
|
+
withQuery(`${API_PREFIX}/inbox/conversations`, {
|
|
561
|
+
"page[limit]": input.limit,
|
|
562
|
+
"page[after]": input.cursor,
|
|
563
|
+
}),
|
|
564
|
+
{
|
|
565
|
+
token: this.resolveInboxReadToken(input.channelToken),
|
|
566
|
+
},
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
async getThread(threadId: string, channelToken?: string) {
|
|
571
|
+
return this.requestResource<ThreadAttributes>(`${API_PREFIX}/threads/${threadId}`, {
|
|
572
|
+
token: this.resolveInboxReadToken(channelToken),
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
async listMessagesForThread(input: {
|
|
577
|
+
threadId: string;
|
|
578
|
+
limit?: number;
|
|
579
|
+
cursor?: string;
|
|
580
|
+
channelToken?: string;
|
|
581
|
+
}) {
|
|
582
|
+
return this.requestCollection<MessageAttributes>(
|
|
583
|
+
withQuery(`${API_PREFIX}/threads/${input.threadId}/messages`, {
|
|
584
|
+
"page[limit]": input.limit,
|
|
585
|
+
"page[after]": input.cursor,
|
|
586
|
+
}),
|
|
587
|
+
{
|
|
588
|
+
token: this.resolveInboxReadToken(input.channelToken),
|
|
589
|
+
},
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
async sendAccountIntro(input: {
|
|
594
|
+
email: string;
|
|
595
|
+
body: string;
|
|
596
|
+
senderChannelId?: string;
|
|
597
|
+
contextPostId?: string;
|
|
598
|
+
channelToken?: string;
|
|
599
|
+
}) {
|
|
600
|
+
return this.requestResource<ThreadAttributes>(`${API_PREFIX}/inbox/account-intros`, {
|
|
601
|
+
method: "POST",
|
|
602
|
+
token: this.resolveInboxWriteToken(input.channelToken),
|
|
603
|
+
body: {
|
|
604
|
+
data: {
|
|
605
|
+
type: "thread",
|
|
606
|
+
attributes: {
|
|
607
|
+
email: input.email,
|
|
608
|
+
body: input.body,
|
|
609
|
+
...(input.senderChannelId
|
|
610
|
+
? { sender_channel_id: input.senderChannelId }
|
|
611
|
+
: {}),
|
|
612
|
+
...(input.contextPostId
|
|
613
|
+
? { context_post_id: input.contextPostId }
|
|
614
|
+
: {}),
|
|
615
|
+
},
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
async sendChannelIntro(input: {
|
|
622
|
+
channelId: string;
|
|
623
|
+
body: string;
|
|
624
|
+
senderChannelId?: string;
|
|
625
|
+
contextPostId?: string;
|
|
626
|
+
channelToken?: string;
|
|
627
|
+
}) {
|
|
628
|
+
return this.requestResource<ThreadAttributes>(`${API_PREFIX}/inbox/channel-intros`, {
|
|
629
|
+
method: "POST",
|
|
630
|
+
token: this.resolveInboxWriteToken(input.channelToken),
|
|
631
|
+
body: {
|
|
632
|
+
data: {
|
|
633
|
+
type: "thread",
|
|
634
|
+
attributes: {
|
|
635
|
+
channel_id: input.channelId,
|
|
636
|
+
body: input.body,
|
|
637
|
+
...(input.senderChannelId
|
|
638
|
+
? { sender_channel_id: input.senderChannelId }
|
|
639
|
+
: {}),
|
|
640
|
+
...(input.contextPostId
|
|
641
|
+
? { context_post_id: input.contextPostId }
|
|
642
|
+
: {}),
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
async replyToThread(input: {
|
|
650
|
+
threadId: string;
|
|
651
|
+
body: string;
|
|
652
|
+
senderChannelId?: string;
|
|
653
|
+
contextPostId?: string;
|
|
654
|
+
channelToken?: string;
|
|
655
|
+
}) {
|
|
656
|
+
return this.requestResource<ThreadAttributes>(
|
|
657
|
+
`${API_PREFIX}/threads/${input.threadId}/reply`,
|
|
658
|
+
{
|
|
659
|
+
method: "PATCH",
|
|
660
|
+
token: this.resolveInboxWriteToken(input.channelToken),
|
|
661
|
+
body: {
|
|
662
|
+
data: {
|
|
663
|
+
type: "thread",
|
|
664
|
+
id: input.threadId,
|
|
665
|
+
attributes: {
|
|
666
|
+
body: input.body,
|
|
667
|
+
...(input.senderChannelId
|
|
668
|
+
? { sender_channel_id: input.senderChannelId }
|
|
669
|
+
: {}),
|
|
670
|
+
...(input.contextPostId
|
|
671
|
+
? { context_post_id: input.contextPostId }
|
|
672
|
+
: {}),
|
|
673
|
+
},
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
async markThreadSeen(input: { threadId: string; channelToken?: string }) {
|
|
681
|
+
return this.updateThreadLifecycle(`${API_PREFIX}/threads/${input.threadId}/seen`, input);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
async archiveThread(input: { threadId: string; channelToken?: string }) {
|
|
685
|
+
return this.updateThreadLifecycle(`${API_PREFIX}/threads/${input.threadId}/archive`, input);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
async resolveThread(input: { threadId: string; channelToken?: string }) {
|
|
689
|
+
return this.updateThreadLifecycle(`${API_PREFIX}/threads/${input.threadId}/resolve`, input);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
async blockThread(input: { threadId: string; channelToken?: string }) {
|
|
693
|
+
return this.updateThreadLifecycle(`${API_PREFIX}/threads/${input.threadId}/block`, input);
|
|
694
|
+
}
|
|
695
|
+
|
|
536
696
|
async fetchOpenApi(): Promise<unknown> {
|
|
537
697
|
return (await requestJson(this.profile.baseUrl, `${API_PREFIX}/open_api`))
|
|
538
698
|
.data;
|
|
@@ -624,6 +784,31 @@ export class ClankmatesClient {
|
|
|
624
784
|
|
|
625
785
|
return resolved.token;
|
|
626
786
|
}
|
|
787
|
+
|
|
788
|
+
private resolveInboxReadToken(explicitToken?: string): string {
|
|
789
|
+
return explicitToken ?? requireOwnerReadToken(this.profile);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
private resolveInboxWriteToken(explicitToken?: string): string {
|
|
793
|
+
return explicitToken ?? requireMasterToken(this.profile);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
private async updateThreadLifecycle(
|
|
797
|
+
path: string,
|
|
798
|
+
input: { threadId: string; channelToken?: string },
|
|
799
|
+
) {
|
|
800
|
+
return this.requestResource<ThreadAttributes>(path, {
|
|
801
|
+
method: "PATCH",
|
|
802
|
+
token: this.resolveInboxWriteToken(input.channelToken),
|
|
803
|
+
body: {
|
|
804
|
+
data: {
|
|
805
|
+
type: "thread",
|
|
806
|
+
id: input.threadId,
|
|
807
|
+
attributes: {},
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
});
|
|
811
|
+
}
|
|
627
812
|
}
|
|
628
813
|
|
|
629
814
|
const API_PREFIX = "/api/v1";
|