This repository was archived by the owner on Feb 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgmail-agent.ts
More file actions
79 lines (63 loc) · 1.71 KB
/
Copy pathgmail-agent.ts
File metadata and controls
79 lines (63 loc) · 1.71 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {
experimental_createMCPClient,
generateText,
stepCountIs,
type CoreMessage,
} from "ai";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { Composio } from "@composio/core";
import * as readline from "readline";
const openrouter = createOpenRouter({
apiKey: process.env.OPENROUTER_API_KEY,
});
const composio = new Composio({
apiKey: process.env.COMPOSIO_APIKEY!,
});
const session = await composio.experimental.toolRouter.createSession(
"rahul@composio.dev",
{
toolkits: ["gmail"],
}
);
console.log("session id:", session.sessionId);
const httpTransport = new StreamableHTTPClientTransport(new URL(session.url));
const httpClient = await experimental_createMCPClient({
transport: httpTransport,
});
const tools = await httpClient.tools();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const messages: CoreMessage[] = [];
console.log("\ngmail agent ready. type your messages (ctrl+c to exit)\n");
const chat = async (userMessage: string) => {
messages.push({
role: "user",
content: userMessage,
});
const result = await generateText({
model: openrouter("anthropic/claude-4.5-sonnet"),
system: "you are a gmail agent for the user",
messages: messages,
tools: tools,
stopWhen: stepCountIs(25),
});
messages.push({
role: "assistant",
content: result.text,
});
console.log("\nassistant:", result.text, "\n");
};
const prompt = () => {
rl.question("you: ", async (input) => {
if (!input.trim()) {
prompt();
return;
}
await chat(input);
prompt();
});
};
prompt();