
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@iflow-ai/iflow-cli-sdk
Advanced tools
A powerful TypeScript SDK for interacting with iFlow CLI using the Agent Communication Protocol (ACP). Build AI-powered applications with full control over conversations, tool execution, and SubAgent orchestration.
โจ Key Feature: The SDK automatically manages the iFlow process - no manual setup required!
agentId propagationdefault, autoEdit, yolo, and plan modesIf you haven't installed iFlow CLI yet:
Mac/Linux/Ubuntu:
bash -c "$(curl -fsSL https://cloud.iflow.cn/iflow-cli/install.sh)"
Windows:
npm install -g @iflow-ai/iflow-cli@latest
Install from NPM:
npm install --save @iflow-ai/iflow-cli-sdk
The SDK automatically manages the iFlow process - no manual setup required!
import { IFlowClient } from "@iflow-ai/iflow-cli-sdk";
async function main() {
// SDK automatically:
// 1. Detects if iFlow is installed
// 2. Starts iFlow process if not running
// 3. Finds an available port
// 4. Cleans up on exit
const client = new IFlowClient();
await client.connect();
await client.sendMessage("Hello, iFlow!");
for await (const message in client.receiveMessages()) {
console.log(message);
// Process messages...
}
}
No need to manually start iFlow! The SDK handles everything for you.
If you need to manage iFlow yourself (rare cases):
import { IFlowClient } from "@iflow-ai/iflow-cli-sdk";
async function main() {
// Disable automatic process management
const client = new IFlowClient({
url: "ws://localhost:8090/acp", // Connect to existing iFlow
autoStartProcess: false,
});
await client.connect();
await client.sendMessage("Hello, iFlow!");
}
Note: Manual mode requires you to start iFlow separately:
iflow --experimental-acp --port 8090
import { query } from "@iflow-ai/iflow-cli-sdk";
async function main() {
const response = await query("What is the capital of France?");
console.log(response); // "The capital of France is Paris."
}
import { IFlowClient, MessageType } from "@iflow-ai/iflow-cli-sdk";
async function main() {
const client = new IFlowClient();
await client.connect();
await client.sendMessage("Explain quantum computing");
for await (const message in client.receiveMessages()) {
if (message.type === MessageType.ASSISTANT && message.chunk.text) {
console.log(message.chunk.text);
} else if (message.type === MessageType.TASK_FINISH) {
break;
}
}
}
import { IFlowClient, PermissionMode, MessageType } from "@iflow-ai/iflow-cli-sdk";
async function main() {
const client = new IFlowClient({
permissionMode: PermissionMode.AUTO,
})
await client.connect();
await client.sendMessage("Create a file called test.txt");
for await (const message in client.receiveMessages()) {
if (message.type === MessageType.TOOL_CALL) {
console.log(`Tool name: ${message.toolName}`);
console.log(`Tool status: ${message.status}`);
if (message.agentInfo) {
console.log(`Agent ID: ${message.agentInfo.agentId}`);
console.log(`Task ID: ${message.agentInfo.taskId}`);
console.log(`Agent index: ${message.agentInfo.agentIndex}`);
}
if (message.args) {
console.log(message.args);
}
if (message.output) {
console.log(message.output);
}
} else if (message.type === MessageType.TASK_FINISH) {
break;
}
}
}
import { IFlowClient, MessageType } from "@iflow-ai/iflow-cli-sdk";
const options: IFlowOptions = {
agents: [
{
agentType: "code-reviewer",
name: "reviewer",
description: "Code review specialist",
whenToUse: "For code review and quality checks",
allowedTools: ["fs", "grep"],
allowedMcps: ["eslint", "prettier"],
systemPrompt: "You are a code review expert.",
proactive: False,
location: "project",
},
{
agentType: "test-writer",
name: "tester",
description: "Test writing specialist",
whenToUse: "For writing unit and integration tests",
allowedTools: ["fs", "bash"],
systemPrompt: "You are a test writing expert.",
location: "project",
},
],
};
async function main() {
const client = new IFlowClient(options)
await client.connect();
await client.sendMessage("$test-writer Write a unit test");
for await (const message in client.receiveMessages()) {
if (message.type === MessageType.TOOL_CALL) {
console.log(`Tool name: ${message.toolName}`);
if (message.args) {
console.log(message.args);
}
if (message.output) {
console.log(message.output);
}
} if (message.type === MessageType.ASSISTANT && message.chunk.text) {
console.log(message.chunk.text);
} else if (message.type === MessageType.TASK_FINISH) {
break;
}
}
}
import { IFlowClient, IFlowOptions, ApprovalMode, HookEventType } from "@iflow-ai/iflow-cli-sdk";
const options: IFlowOptions = {
mcpServers: [
{
name: "filesystem",
command: "mcp-server-filesystem",
args: ["--allowed-dirs", "/workspace"],
env: [
{
name: "DEBUG",
value: "1",
},
],
},
],
sessionSettings: {
allowed_tools: ["read_file", "write_file", "execute_code"],
system_prompt: "You are an expert Python developer",
permission_mode: ApprovalMode.AUTO_EDIT,
max_turns: 100,
},
hooks: {
[HookEventType.PRE_TOOL_USE]: [
{
hooks: {
command: "echo 'Processing request...'",
timeout: 5,
},
},
],
},
commands: [
{
name: "test",
content: "pytest --verbose",
},
],
agents: [
{
agentType: "python-expert",
whenToUse: "For Python development tasks",
allowedTools: ["edit_file", "run_python", "debug"],
systemPrompt: "You are a Python expert focused on clean, efficient code",
name: "Python Expert",
description: "Specialized in Python development",
},
],
};
async function main() {
const client = new IFlowClient(options);
await client.connect();
await client.sendMessage("$test-writer Write a unit test");
// Process responses...
}
IFlowClient: Main client for bidirectional communicationIFlowOptions: Configuration optionsRawDataClient: Access to raw protocol dataAssistantMessage: AI assistant responses with optional agent informationToolCallMessage: Tool execution requests with execution details (toolName, args, output) and agent informationPlanMessage: Structured task plans with priority and statusTaskFinishMessage: Task completion signal with stop reason (end_urn, max_tokens, refusal, cancelled)AgentInfo: Agent metadata extracted from iFlow's agentId format (agentId, taskId, agentIndex, timestamp)query(prompt): Simple synchronous queryqueryStream(prompt): Streaming responsessrc/
โโโ internals/
โ โโโ FileHandler.ts # File access
โ โโโ ProcessManager.ts # iFlow process management
โ โโโ Protocol.ts # ACP protocol handler
โ โโโ Transport.ts # WebSocket transport layer
โโโ types/
โ โโโ acp.ts # ACP data types
โ โโโ messages.ts # Message types
โ โโโ options.ts # iFlow options
โโโ utils/
โ โโโ logger.ts # Logs util
โ โโโ parseAgentId.ts # Parse agent id
โโโ IFlowClient.ts # Main IFlowClient implementation
โโโ RawDataClient.ts # Raw protocol access
โโโ query.ts # Simple query functions
โโโ index.ts # Main entry
npm test
# Lint code
npm run lint
# Format code
npm run format
The SDK implements the Agent Communication Protocol (ACP) v1 with full extension support, including:
agent_message_chunk - Assistant responsesagent_thought_chunk - Internal reasoningtool_call / tool_call_update - Tool execution lifecycleplan - Structured task planning with prioritiesuser_message_chunk - User message echoingstop_reason - Task completion with reason (end_turn, max_tokens, refusal, cancelled)agentId tracking and managementContributions are welcome! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ for the AI development community
FAQs
TypeScript SDK for iFlow CLI
We found that @iflow-ai/iflow-cli-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authoritiesโ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socketโs new workflow scanning support.