-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathagent.ts
More file actions
55 lines (44 loc) · 1.18 KB
/
agent.ts
File metadata and controls
55 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { type CredentialManager, XRPC } from '@atcute/client';
import type { Queries } from '@tsky/lexicons';
import { Actor } from '~/actor';
import { Feed } from '~/feed';
import { List } from '~/list';
import { StarterPack } from '~/starterpack';
import { User } from '~/user';
import { Video } from '~/video';
import { Client } from './client';
export class Agent {
private client: Client<Queries>;
constructor(private handler: CredentialManager) {
// Initialize the client
const xrpc = new XRPC({ handler: this.handler });
this.client = new Client(xrpc);
}
get session() {
return this.handler.session;
}
actor(identifier: string) {
return new Actor(this.client, identifier);
}
list(uri: string) {
return new List(this.client, uri);
}
get feed() {
return new Feed(this.client);
}
get user() {
if (!this.session) {
throw new Error('There is no active session');
}
return new User(this.client, this.session.handle);
}
get video() {
if (!this.session) {
throw new Error('There is no active session');
}
return new Video(this.client);
}
get starterpack() {
return new StarterPack(this.client);
}
}