Skip to content

Commit fa59113

Browse files
authored
TypeScript SDK Examples (#46)
1 parent f99c869 commit fa59113

File tree

26 files changed

+3475
-0
lines changed

26 files changed

+3475
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
pnpm-debug.log*
7+
8+
# Build outputs
9+
dist/
10+
build/
11+
*.tsbuildinfo
12+
13+
# Environment files
14+
.env
15+
.env.local
16+
.env.development.local
17+
.env.test.local
18+
.env.production.local
19+
20+
# IDE files
21+
.vscode/
22+
.idea/
23+
*.swp
24+
*.swo
25+
*~
26+
27+
# OS files
28+
.DS_Store
29+
Thumbs.db
30+
31+
# Logs
32+
logs/
33+
*.log
34+
35+
# Runtime data
36+
pids/
37+
*.pid
38+
*.seed
39+
*.pid.lock
40+
41+
# Coverage directory used by tools like istanbul
42+
coverage/
43+
*.lcov
44+
45+
# Temporary files
46+
tmp/
47+
temp/
48+
*.tmp
49+
*.temp
50+
51+
# State files (example outputs)
52+
/tmp/direct-context-state.json
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Context Examples
2+
3+
Examples demonstrating the Auggie SDK's context modes and AI-powered code analysis.
4+
5+
## Prerequisites
6+
7+
1. **Node.js 18+** - Required to run the examples
8+
2. **Auggie CLI** - Required for FileSystem Context examples
9+
```bash
10+
npm install -g @augmentcode/auggie
11+
```
12+
3. **Authentication** - Required for all examples
13+
```bash
14+
auggie login
15+
```
16+
This creates a session file at `~/.augment/session.json` with your API token.
17+
18+
Alternatively, you can set environment variables:
19+
```bash
20+
export AUGMENT_API_TOKEN=your_token_here
21+
export AUGMENT_API_URL=https://staging-shard-0.api.augmentcode.com/
22+
```
23+
24+
## Setup
25+
26+
Install dependencies:
27+
28+
```bash
29+
cd examples/typescript-sdk/context
30+
npm install
31+
```
32+
33+
## Examples
34+
35+
### [Direct Context](./direct-context/)
36+
API-based indexing with semantic search and AI Q&A.
37+
38+
**Run it:**
39+
```bash
40+
npm run direct-context
41+
```
42+
43+
### [FileSystem Context](./filesystem-context/)
44+
Local directory search via MCP protocol.
45+
46+
**Prerequisites:**
47+
- Auggie CLI must be installed and in your PATH
48+
- Authentication via `auggie login` or `AUGMENT_API_TOKEN` environment variable
49+
- A `.gitignore` or `.augmentignore` file in the workspace directory to exclude `node_modules/` and other large directories
50+
51+
**Important:** The FileSystem Context indexes all files in the workspace directory. To avoid timeouts when indexing large directories (like `node_modules/`), make sure you have a `.gitignore` or `.augmentignore` file that excludes them. The auggie CLI respects both `.gitignore` and `.augmentignore` patterns during indexing.
52+
53+
**Run it:**
54+
```bash
55+
npm run filesystem-context
56+
```
57+
58+
### [File Search Server](./file-search-server/)
59+
REST API for semantic file search with AI summarization.
60+
61+
**Prerequisites:** Auggie CLI must be installed and in your PATH.
62+
63+
**Run it:**
64+
```bash
65+
npm run file-search-server [workspace-directory]
66+
```
67+
68+
Then query the API:
69+
```bash
70+
curl "http://localhost:3000/search?q=typescript"
71+
```
72+
73+
### [Prompt Enhancer Server](./prompt-enhancer-server/)
74+
HTTP server that enhances prompts with codebase context.
75+
76+
**Prerequisites:** Auggie CLI must be installed and in your PATH.
77+
78+
**Run it:**
79+
```bash
80+
npm run prompt-enhancer-server [workspace-directory]
81+
```
82+
83+
Then enhance prompts:
84+
```bash
85+
curl -X POST http://localhost:3001/enhance \
86+
-H "Content-Type: application/json" \
87+
-d '{"prompt": "fix the login bug"}'
88+
```
89+
90+
### [GitHub Action Indexer](./github-action-indexer/)
91+
Index GitHub repositories for semantic search.
92+
93+
This example has its own package.json and dependencies.
94+
95+
**Setup:**
96+
```bash
97+
npm run github-indexer:install
98+
```
99+
100+
**Run it:**
101+
```bash
102+
npm run github-indexer:index
103+
npm run github-indexer:search
104+
```
105+
106+
See [github-action-indexer/README.md](./github-action-indexer/README.md) for more details.
107+
108+
## Running Examples Directly with tsx
109+
110+
You can also run examples directly without installing dependencies:
111+
112+
```bash
113+
npx tsx direct-context/index.ts
114+
npx tsx filesystem-context/index.ts
115+
npx tsx file-search-server/index.ts .
116+
npx tsx prompt-enhancer-server/index.ts .
117+
```
118+
119+
Note: This will download dependencies on each run. For better performance, use `npm install` first.
120+
121+
## Troubleshooting
122+
123+
### MCP Timeout in FileSystem Context
124+
125+
**Problem:** The FileSystem Context example times out during indexing.
126+
127+
**Cause:** The workspace directory contains too many files (e.g., `node_modules/` with 45,000+ files).
128+
129+
**Solution:** Create a `.gitignore` or `.augmentignore` file in the workspace directory to exclude large directories:
130+
131+
```bash
132+
# .gitignore or .augmentignore
133+
node_modules/
134+
dist/
135+
*.log
136+
.DS_Store
137+
```
138+
139+
The auggie CLI respects both `.gitignore` and `.augmentignore` patterns and will skip excluded files during indexing.
140+
141+
### Authentication Errors
142+
143+
**Problem:** `Error: API key is required for searchAndAsk()`
144+
145+
**Cause:** The SDK cannot find your authentication credentials.
146+
147+
**Solution:** Run `auggie login` to authenticate, or set the `AUGMENT_API_TOKEN` and `AUGMENT_API_URL` environment variables.
148+
149+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Direct Context Example
2+
3+
API-based indexing with semantic search, AI Q&A, and state persistence.
4+
5+
## Usage
6+
7+
```bash
8+
# Authenticate
9+
auggie login
10+
11+
# Run the example
12+
npx tsx examples/context/direct-context/index.ts
13+
```
14+
15+
## What It Does
16+
17+
- Creates a Direct Context instance
18+
- Adds sample files to the index
19+
- Performs semantic searches
20+
- Uses `searchAndAsk()` for AI-powered Q&A
21+
- Generates documentation
22+
- Exports/imports context state
23+
24+
## Key Features
25+
26+
- **`search()`**: Semantic search returning formatted code snippets
27+
- **`searchAndAsk()`**: One-step AI Q&A about indexed code
28+
- **State persistence**: Export/import index for reuse
29+

0 commit comments

Comments
 (0)