Skip to content

Commit 5ae8feb

Browse files
authored
Merge pull request elizaOS#2400 from elizaOS/fixes
fix: lint errors
2 parents 1eacc8d + 0c55316 commit 5ae8feb

File tree

4 files changed

+445
-402
lines changed

4 files changed

+445
-402
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import eslintGlobalConfig from "../../eslint.config.mjs";
2+
3+
export default [...eslintGlobalConfig];

packages/client-instagram/src/index.ts

+46-44
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,52 @@ import { InstagramInteractionService } from "./services/interaction";
66
import { InstagramPostService } from "./services/post";
77

88
export const InstagramClientInterface: Client = {
9-
async start(runtime: IAgentRuntime) {
10-
try {
11-
// Validate configuration
12-
const config = await validateInstagramConfig(runtime);
13-
elizaLogger.log("Instagram client configuration validated");
14-
15-
// Initialize client and get initial state
16-
const state = await initializeClient(runtime, config);
17-
elizaLogger.log("Instagram client initialized");
18-
19-
// Create services
20-
const postService = new InstagramPostService(runtime, state);
21-
const interactionService = new InstagramInteractionService(runtime, state);
22-
23-
// Start services
24-
if (!config.INSTAGRAM_DRY_RUN) {
25-
await postService.start();
26-
elizaLogger.log("Instagram post service started");
27-
28-
if (config.INSTAGRAM_ENABLE_ACTION_PROCESSING) {
29-
await interactionService.start();
30-
elizaLogger.log("Instagram interaction service started");
9+
async start(runtime: IAgentRuntime) {
10+
try {
11+
// Validate configuration
12+
const config = await validateInstagramConfig(runtime);
13+
elizaLogger.log("Instagram client configuration validated");
14+
15+
// Initialize client and get initial state
16+
const state = await initializeClient(runtime, config);
17+
elizaLogger.log("Instagram client initialized");
18+
19+
// Create services
20+
const postService = new InstagramPostService(runtime, state);
21+
const interactionService = new InstagramInteractionService(
22+
runtime,
23+
state
24+
);
25+
26+
// Start services
27+
if (!config.INSTAGRAM_DRY_RUN) {
28+
await postService.start();
29+
elizaLogger.log("Instagram post service started");
30+
31+
if (config.INSTAGRAM_ENABLE_ACTION_PROCESSING) {
32+
await interactionService.start();
33+
elizaLogger.log("Instagram interaction service started");
34+
}
35+
} else {
36+
elizaLogger.log("Instagram client running in dry-run mode");
37+
}
38+
39+
// Return manager instance
40+
return {
41+
post: postService,
42+
interaction: interactionService,
43+
state,
44+
};
45+
} catch (error) {
46+
elizaLogger.error("Failed to start Instagram client:", error);
47+
throw error;
3148
}
32-
} else {
33-
elizaLogger.log("Instagram client running in dry-run mode");
34-
}
35-
36-
// Return manager instance
37-
return {
38-
post: postService,
39-
interaction: interactionService,
40-
state
41-
};
42-
43-
} catch (error) {
44-
elizaLogger.error("Failed to start Instagram client:", error);
45-
throw error;
46-
}
47-
},
48-
49-
async stop(runtime: IAgentRuntime) {
50-
elizaLogger.log("Stopping Instagram client services...");
51-
// Cleanup will be handled by the services themselves
52-
}
49+
},
50+
51+
async stop(_runtime: IAgentRuntime) {
52+
elizaLogger.log("Stopping Instagram client services...");
53+
// Cleanup will be handled by the services themselves
54+
},
5355
};
5456

55-
export default InstagramClientInterface;
57+
export default InstagramClientInterface;
+65-67
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// src/lib/auth.ts
22
import { IAgentRuntime, elizaLogger } from "@elizaos/core";
3-
import { IgLoginTwoFactorRequiredError } from 'instagram-private-api';
3+
import { IgLoginTwoFactorRequiredError } from "instagram-private-api";
44
import { InstagramConfig } from "../environment";
55
import { InstagramState } from "../types";
66
import { fetchProfile } from "./profile";
@@ -10,96 +10,94 @@ import { createInitialState, getIgClient } from "./state";
1010
* Authenticates with Instagram
1111
*/
1212
async function authenticate(
13-
runtime: IAgentRuntime,
14-
config: InstagramConfig
13+
runtime: IAgentRuntime,
14+
config: InstagramConfig
1515
): Promise<InstagramState> {
16-
const ig = getIgClient();
17-
let state = createInitialState();
16+
const ig = getIgClient();
17+
const state = createInitialState();
1818

19-
try {
20-
// Generate device ID
21-
ig.state.generateDevice(config.INSTAGRAM_USERNAME);
22-
23-
// Attempt to load cached session
24-
const cachedSession = await runtime.cacheManager.get('instagram/session');
25-
if (cachedSession) {
26-
try {
27-
await ig.state.deserialize(cachedSession);
28-
const profile = await fetchProfile(runtime, config);
29-
return {
30-
...state,
31-
isInitialized: true,
32-
profile
33-
};
34-
} catch (error) {
35-
elizaLogger.warn('Cached session invalid, proceeding with fresh login');
36-
}
37-
}
38-
39-
// Proceed with fresh login
4019
try {
41-
await ig.account.login(
42-
config.INSTAGRAM_USERNAME,
43-
config.INSTAGRAM_PASSWORD
44-
);
20+
// Generate device ID
21+
ig.state.generateDevice(config.INSTAGRAM_USERNAME);
22+
23+
// Attempt to load cached session
24+
const cachedSession =
25+
await runtime.cacheManager.get("instagram/session");
26+
if (cachedSession) {
27+
try {
28+
await ig.state.deserialize(cachedSession);
29+
const profile = await fetchProfile(runtime, config);
30+
return {
31+
...state,
32+
isInitialized: true,
33+
profile,
34+
};
35+
} catch {
36+
elizaLogger.warn(
37+
`Cached session invalid, proceeding with fresh login`
38+
);
39+
}
40+
}
4541

46-
// Cache the session
47-
const serialized = await ig.state.serialize();
48-
await runtime.cacheManager.set('instagram/session', serialized);
42+
// Proceed with fresh login
43+
try {
44+
await ig.account.login(
45+
config.INSTAGRAM_USERNAME,
46+
config.INSTAGRAM_PASSWORD
47+
);
4948

50-
const profile = await fetchProfile(runtime, config);
49+
// Cache the session
50+
const serialized = await ig.state.serialize();
51+
await runtime.cacheManager.set("instagram/session", serialized);
5152

52-
return {
53-
...state,
54-
isInitialized: true,
55-
profile
56-
};
53+
const profile = await fetchProfile(runtime, config);
5754

55+
return {
56+
...state,
57+
isInitialized: true,
58+
profile,
59+
};
60+
} catch (error) {
61+
if (error instanceof IgLoginTwoFactorRequiredError) {
62+
// Handle 2FA if needed - would need to implement 2FA code generation
63+
throw new Error("2FA authentication not yet implemented");
64+
}
65+
throw error;
66+
}
5867
} catch (error) {
59-
if (error instanceof IgLoginTwoFactorRequiredError) {
60-
// Handle 2FA if needed - would need to implement 2FA code generation
61-
throw new Error('2FA authentication not yet implemented');
62-
}
63-
throw error;
68+
elizaLogger.error("Authentication failed:", error);
69+
throw error;
6470
}
65-
66-
} catch (error) {
67-
elizaLogger.error('Authentication failed:', error);
68-
throw error;
69-
}
7071
}
7172

7273
/**
7374
* Sets up webhooks for real-time updates if needed
7475
*/
7576
async function setupWebhooks() {
76-
// Implement webhook setup
77-
// This is a placeholder for future implementation
77+
// Implement webhook setup
78+
// This is a placeholder for future implementation
7879
}
7980

8081
/**
8182
* Initializes the Instagram client
8283
*/
8384
export async function initializeClient(
84-
runtime: IAgentRuntime,
85-
config: InstagramConfig
85+
runtime: IAgentRuntime,
86+
config: InstagramConfig
8687
): Promise<InstagramState> {
87-
try {
88-
// Authenticate and get initial state
89-
const state = await authenticate(runtime, config);
88+
try {
89+
// Authenticate and get initial state
90+
const state = await authenticate(runtime, config);
9091

91-
// Set up webhook handlers if needed
92-
await setupWebhooks();
92+
// Set up webhook handlers if needed
93+
await setupWebhooks();
9394

94-
return state;
95-
} catch (error) {
96-
elizaLogger.error('Failed to initialize Instagram client:', error);
97-
throw error;
98-
}
95+
return state;
96+
} catch (error) {
97+
elizaLogger.error("Failed to initialize Instagram client:", error);
98+
throw error;
99+
}
99100
}
100101

101102
// Export other authentication related functions if needed
102-
export {
103-
authenticate,
104-
setupWebhooks
105-
};
103+
export { authenticate, setupWebhooks };

0 commit comments

Comments
 (0)