Skip to content

Commit 78f35c2

Browse files
committed
feat: move cli to its own package
1 parent 9519fbc commit 78f35c2

File tree

8 files changed

+140
-35
lines changed

8 files changed

+140
-35
lines changed

package-lock.json

Lines changed: 42 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/agent-api/README.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,3 @@ You can use the `api.http` file to test the API using the [REST Client](https://
1515
### `npm run build`
1616

1717
To build the API for production to the `dist` folder.
18-
19-
### `npm run cli`
20-
21-
Run the burger agent CLI. Usage examples:
22-
23-
```bash
24-
# Ask a simple question
25-
npm run cli "show me the burger menu"
26-
27-
# Ask with a specific user ID
28-
npm run cli "place an order" -- --userId user123
29-
30-
# Start a new session
31-
npm run cli "hello" -- --new
32-
33-
# Combine options
34-
npm run cli "cancel my order" -- --userId user123 --new
35-
```
36-
37-
The CLI maintains conversation history in `~/.burger-agent-cli/burger-agent-cli.json` for context across sessions.

packages/agent-api/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727
"@langchain/mcp-adapters": "^0.5.2",
2828
"@langchain/openai": "^0.5.18",
2929
"@microsoft/ai-chat-protocol": "^1.0.0-beta.20240814.1",
30-
"dotenv": "^17.0.1",
3130
"langchain": "^0.3.6"
3231
},
3332
"devDependencies": {
3433
"@types/node": "^20",
3534
"azure-functions-core-tools": "^4",
36-
"tsx": "^4",
3735
"typescript": "^5"
3836
}
3937
}

packages/agent-cli/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Contoso Burgers AI lightweight Agent CLI
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Run the burger agent CLI. Usage examples:
10+
11+
```bash
12+
# Ask a simple question
13+
npm run start "show me the burger menu"
14+
15+
# Ask with a specific user ID
16+
npm run start "place an order" -- --userId user123
17+
18+
# Start a new session
19+
npm run start "hello" -- --new
20+
21+
# Combine options
22+
npm run start "cancel my order" -- --userId user123 --new
23+
```
24+
25+
The CLI maintains conversation history in `~/.burger-agent-cli/burger-agent-cli.json` for context across sessions.
26+
27+
### `npm run build`
28+
29+
To build the CLI for production to the `dist` folder.
30+
31+
After building, you can install the CLI globally with:
32+
33+
```bash
34+
npm install -g .
35+
```
36+
37+
And then run it with:
38+
39+
```bash
40+
agent-cli --help
41+
```

packages/agent-api/agent-cli.ts renamed to packages/agent-cli/agent-cli.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
#!/usr/bin/env node
2-
1+
import path from 'node:path';
2+
import fs from 'node:fs/promises';
3+
import os from 'node:os';
4+
import { DefaultAzureCredential, getBearerTokenProvider } from '@azure/identity';
35
import { AzureChatOpenAI } from '@langchain/openai';
46
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
57
import { ChatPromptTemplate } from '@langchain/core/prompts';
68
import { createToolCallingAgent } from 'langchain/agents';
79
import { AgentExecutor } from 'langchain/agents';
810
import { loadMcpTools } from '@langchain/mcp-adapters';
911
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
10-
import { getAzureOpenAiTokenProvider } from './src/auth.js';
1112
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
1213
import { BaseMessage, HumanMessage, AIMessage } from '@langchain/core/messages';
13-
import path from 'node:path';
14-
import fs from 'node:fs/promises';
15-
import os from 'node:os';
1614
import dotenv from 'dotenv';
1715

1816
dotenv.config({ path: path.join(process.cwd(), '../../.env'), quiet: true });
@@ -150,7 +148,7 @@ export async function run() {
150148
}
151149
}
152150

153-
const azureADTokenProvider = getAzureOpenAiTokenProvider();
151+
const azureADTokenProvider = getBearerTokenProvider(new DefaultAzureCredential(), 'https://cognitiveservices.azure.com/.default');;
154152

155153
model = new AzureChatOpenAI({
156154
temperature: 0.3,
@@ -228,7 +226,3 @@ export async function run() {
228226
process.exitCode = 0;
229227
}
230228
}
231-
232-
if (process.argv[1] && process.argv[1].endsWith('agent-cli.ts') || process.argv[1].endsWith('agent-cli.js')) {
233-
run();
234-
}

packages/agent-cli/bin/cli.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
import { run } from '../../agent-api/dist/agent-cli.js';
3+
4+
await run();

packages/agent-cli/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "agent-cli",
3+
"version": "1.0.0",
4+
"description": "Contoso Burgers AI lightweight Agent CLI",
5+
"private": true,
6+
"type": "module",
7+
"bin": {
8+
"agent-cli": "./bin/cli.js"
9+
},
10+
"scripts": {
11+
"start": "tsx ./bin/cli.js --",
12+
"build": "tsc",
13+
"watch": "tsc -w",
14+
"clean": "rimraf dist"
15+
},
16+
"author": "Microsoft",
17+
"license": "MIT",
18+
"dependencies": {
19+
"@azure/identity": "^4.2.0",
20+
"@langchain/core": "^0.3.18",
21+
"@langchain/langgraph": "^0.3.6",
22+
"@langchain/mcp-adapters": "^0.5.2",
23+
"@langchain/openai": "^0.5.18",
24+
"dotenv": "^17.0.1",
25+
"langchain": "^0.3.6"
26+
},
27+
"devDependencies": {
28+
"@types/node": "^20",
29+
"tsx": "^4",
30+
"typescript": "^5"
31+
}
32+
}

packages/agent-cli/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"module": "esnext",
4+
"target": "esnext",
5+
"incremental": true,
6+
"skipLibCheck": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"outDir": "dist",
9+
"rootDir": ".",
10+
"sourceMap": true,
11+
"strict": true,
12+
"moduleResolution": "node",
13+
"esModuleInterop": true,
14+
"lib": ["ESNext"]
15+
}
16+
}

0 commit comments

Comments
 (0)