Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ test-results/
.specstory/
chart/chartsmith/*.tgz
.direnv/
claude-service/node_modules/
5 changes: 5 additions & 0 deletions claude-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
*.log
.env
.env.*
37 changes: 37 additions & 0 deletions claude-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build stage
FROM node:22-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY tsconfig.json ./
COPY src ./src

RUN npm run build

# Production stage
FROM node:22-alpine

WORKDIR /app

# Install production dependencies only
COPY package*.json ./
RUN npm ci --omit=dev && npm cache clean --force

# Copy built files
COPY --from=builder /app/dist ./dist

# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 -G nodejs

USER nodejs

EXPOSE 3100

ENV NODE_ENV=production
ENV PORT=3100

CMD ["node", "dist/index.js"]
124 changes: 124 additions & 0 deletions claude-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Claude Service

A Node.js service that wraps the official Anthropic Claude SDK, providing HTTP endpoints for the Go worker to consume.

## Why?

The official Anthropic SDK is only available for Node.js and Python. This service allows the Go worker to access SDK-exclusive features like:

- Prompt caching
- Extended thinking (Claude 3.7+)
- Better streaming primitives
- Faster feature parity with API releases

## Endpoints

### Health Check
```
GET /health
```

### Messages (Non-streaming)
```
POST /v1/messages
Content-Type: application/json

{
"model": "claude-3-7-sonnet-20250219",
"max_tokens": 8192,
"system": "You are a helpful assistant.",
"messages": [
{"role": "user", "content": "Hello!"}
]
}
```

### Messages (Streaming)
```
POST /v1/messages/stream
Content-Type: application/json
Accept: text/event-stream

{
"model": "claude-3-7-sonnet-20250219",
"max_tokens": 8192,
"messages": [
{"role": "user", "content": "Hello!"}
]
}
```

Returns Server-Sent Events (SSE):
```
event: content_block_delta
data: {"type":"content_block_delta","delta":{"type":"text_delta","text":"Hello"}}

event: message_stop
data: {"type":"message_stop","message":{...}}

event: done
data: [DONE]
```

### Extended Thinking (Claude 3.7+)
```
POST /v1/messages/think
Content-Type: application/json
Accept: text/event-stream

{
"model": "claude-3-7-sonnet-20250219",
"max_tokens": 16000,
"thinking": {
"type": "enabled",
"budget_tokens": 10000
},
"messages": [
{"role": "user", "content": "Solve this complex problem..."}
]
}
```

## Development

```bash
# Install dependencies
npm install

# Run in development mode (with hot reload)
npm run dev

# Type check
npm run typecheck

# Build for production
npm run build

# Run production build
npm start
```

## Environment Variables

- `ANTHROPIC_API_KEY` - Required. Your Anthropic API key.
- `PORT` - Optional. Server port (default: 3100).

## Docker

```bash
# Build
docker build -t claude-service .

# Run
docker run -p 3100:3100 -e ANTHROPIC_API_KEY=your-key claude-service
```

## Integration with Go Worker

Set the `CLAUDE_SERVICE_URL` environment variable in the Go worker to enable routing Claude calls through this service:

```bash
export CLAUDE_SERVICE_URL=http://localhost:3100
```

When this variable is set, supported LLM functions will use the Node service instead of the Go Anthropic SDK.
Loading