Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.
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
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-explicit-any": "warn"
},
"ignorePatterns": ["dist", "build", "node_modules", "*.py", ".venv"]
}

8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ archive.zip
.cache
.DS_Store
local_db*

# TypeScript/Node.js
node_modules/
dist/
build/
*.tsbuildinfo
.pnpm-store/
.vite/
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
dist
build
.venv
*.py
__pycache__
*.pyc
.env

9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false
}

93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,99 @@ This repo is inteded for use with Python 3.9
./scripts/bash/run-docker-dev.sh
```

## TypeScript/Node.js Apps (Development)

This repository now includes TypeScript/Node.js applications alongside the Python project. The monorepo structure allows both to coexist independently.

### Prerequisites

- Node.js >= 18.0.0
- pnpm >= 8.0.0

### Setup

1. Install pnpm (if not already installed):

```bash
npm install -g pnpm
```

2. Install all dependencies:

```bash
pnpm install
```

### Running the TypeScript Apps

#### Development Mode

- **API Server** (Node.js + Express backend):
```bash
pnpm dev:api
```
The API server will run on `http://localhost:3001`

- **Web Dashboard** (React + TypeScript frontend):
```bash
pnpm dev:web
```
The web app will run on `http://localhost:3000`

- **Run both simultaneously** (in separate terminals):
```bash
# Terminal 1
pnpm dev:api

# Terminal 2
pnpm dev:web
```

#### Other Commands

- **Build all packages**:
```bash
pnpm build
```

- **Type checking**:
```bash
pnpm type-check
```

- **Linting**:
```bash
pnpm lint
```

- **Format code**:
```bash
pnpm format
```

### Monorepo Structure

```
.
├── apps/
│ ├── api/ # Node.js + TypeScript backend API
│ └── web/ # React + TypeScript dashboard
├── packages/
│ └── domain/ # Shared TypeScript types and validation
├── samples/ # Saved JSON samples
├── scripts/ # Fetch scripts (separate from scripts/python/)
└── [existing Python code remains unchanged]
```

### Shared Domain Package

The `@polymarket/domain` package contains shared TypeScript types and Zod validation schemas that can be used across all TypeScript apps. Import using:

```typescript
import { Market, Event, Trade } from '@domain/types';
import { MarketSchema } from '@domain/validation';
```

## Architecture

The Polymarket Agents architecture features modular components that can be maintained and extended by individual community members.
Expand Down
41 changes: 41 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@polymarket/api",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"kill:3001": "powershell -NoProfile -ExecutionPolicy Bypass -Command \"try { $conns = Get-NetTCPConnection -LocalPort 3001 -State Listen -ErrorAction SilentlyContinue; if ($conns) { $pids = $conns | Select-Object -ExpandProperty OwningProcess -Unique; $pids | ForEach-Object { Stop-Process -Id $_ -Force -ErrorAction SilentlyContinue } } } catch {} ; exit 0\"",
"dev": "npm run kill:3001 && tsx watch src/index.ts",
"dev:raw": "tsx watch src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"type-check": "tsc --noEmit",
"lint": "eslint src --ext .ts",
"test": "vitest run",
"test:watch": "vitest",
"sanity": "tsx src/services/runSanity.ts",
"smoke": "powershell -ExecutionPolicy Bypass -File scripts/smoke.ps1",
"health": "powershell -Command \"$response = Invoke-RestMethod -Uri 'http://localhost:3001/health' -Method Get; $response | ConvertTo-Json -Depth 20\"",
"agents:list": "powershell -Command \"$response = Invoke-RestMethod -Uri 'http://localhost:3001/agents' -Method Get; $response | ConvertTo-Json -Depth 20\"",
"replay:agent1": "powershell -Command \"$response = Invoke-RestMethod -Uri 'http://localhost:3001/replay?agentId=agent-1' -Method Get; $response | ConvertTo-Json -Depth 20\"",
"chat:agent1": "powershell -ExecutionPolicy Bypass -File scripts/chat-agent1.ps1",
"chat": "powershell -ExecutionPolicy Bypass -File scripts/chat.ps1"
},
"dependencies": {
"@polymarket/domain": "workspace:*",
"cors": "^2.8.5",
"express": "^4.18.2",
"openai": "^4.20.1",
"zod": "^3.25.76"
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/node": "^20.11.0",
"@types/supertest": "^6.0.2",
"supertest": "^6.3.3",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"vitest": "^1.2.0"
}
}
65 changes: 65 additions & 0 deletions apps/api/scripts/chat-agent1.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Chat script for agent-1
# Usage: pnpm -C apps/api chat:agent1 "Your message here"
# Or: $env:MESSAGE="Your message"; pnpm -C apps/api chat:agent1

param(
[string]$Message = $env:MESSAGE
)

if (-not $Message) {
Write-Host "Usage: pnpm -C apps/api chat:agent1 `"Your message here`"" -ForegroundColor Red
Write-Host "Or: `$env:MESSAGE=`"Your message`"; pnpm -C apps/api chat:agent1" -ForegroundColor Yellow
exit 1
}

# Check API health first
try {
$healthResponse = Invoke-RestMethod -Uri 'http://localhost:3001/health' -Method Get -ErrorAction Stop
} catch {
Write-Host "API is not running (start with .\scripts\dev.ps1)" -ForegroundColor Red
exit 1
}

$body = @{
agentId = 'agent-1'
message = $Message
} | ConvertTo-Json

try {
$response = Invoke-RestMethod -Uri 'http://localhost:3001/chat' -Method Post -Body $body -ContentType 'application/json' -ErrorAction Stop

if (-not $response.success) {
Write-Host "Chat failed:" -ForegroundColor Red
Write-Host " errorCode: $($response.errorCode)" -ForegroundColor Yellow
Write-Host " error: $($response.error)" -ForegroundColor Yellow
exit 1
}

$response | ConvertTo-Json -Depth 20
} catch {
$statusCode = $null
if ($_.Exception.Response) {
$statusCode = $_.Exception.Response.StatusCode.value__
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
$responseBody = $reader.ReadToEnd()
try {
$errorResponse = $responseBody | ConvertFrom-Json
if ($errorResponse.success -eq $false) {
Write-Host "Chat failed:" -ForegroundColor Red
Write-Host " errorCode: $($errorResponse.errorCode)" -ForegroundColor Yellow
Write-Host " error: $($errorResponse.error)" -ForegroundColor Yellow
if ($statusCode) {
Write-Host " httpStatus: $statusCode" -ForegroundColor Yellow
}
exit 1
}
} catch {
# Not JSON, show raw response
}
Write-Host "Error: $_" -ForegroundColor Red
Write-Host "Response: $responseBody" -ForegroundColor Yellow
} else {
Write-Host "Error: $_" -ForegroundColor Red
}
exit 1
}
84 changes: 84 additions & 0 deletions apps/api/scripts/chat.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Chat script (generalized)
# Usage: pnpm -C apps/api chat "agent-1" "Your message here"
# Usage: pnpm -C apps/api chat "agent-2" "Hva er status?"
# Or: $env:AGENT_ID="agent-2"; $env:MESSAGE="Your message"; pnpm -C apps/api chat

param(
[string]$AgentId = $env:AGENT_ID,
[string]$Message = $env:MESSAGE
)

# If first arg looks like agentId (starts with "agent-"), use it
if ($args.Count -gt 0 -and $args[0] -match '^agent-\d+$') {
$AgentId = $args[0]
if ($args.Count -gt 1) {
$Message = $args[1..($args.Count-1)] -join ' '
}
} elseif ($args.Count -gt 0 -and -not $Message) {
# If no agentId pattern and no message, treat first arg as message
$Message = $args -join ' '
}

# Default agentId if not provided
if (-not $AgentId) {
$AgentId = 'agent-1'
}

if (-not $Message) {
Write-Host "Usage: pnpm -C apps/api chat `"agent-1`" `"Your message here`"" -ForegroundColor Red
Write-Host "Usage: pnpm -C apps/api chat `"agent-2`" `"Hva er status?`"" -ForegroundColor Yellow
Write-Host "Or: `$env:AGENT_ID=`"agent-1`"; `$env:MESSAGE=`"Your message`"; pnpm -C apps/api chat" -ForegroundColor Yellow
exit 1
}

# Check API health first
try {
$healthResponse = Invoke-RestMethod -Uri 'http://localhost:3001/health' -Method Get -ErrorAction Stop
} catch {
Write-Host "API is not running (start with .\scripts\dev.ps1)" -ForegroundColor Red
exit 1
}

$body = @{
agentId = $AgentId
message = $Message
} | ConvertTo-Json

try {
$response = Invoke-RestMethod -Uri 'http://localhost:3001/chat' -Method Post -Body $body -ContentType 'application/json' -ErrorAction Stop

if (-not $response.success) {
Write-Host "Chat failed:" -ForegroundColor Red
Write-Host " errorCode: $($response.errorCode)" -ForegroundColor Yellow
Write-Host " error: $($response.error)" -ForegroundColor Yellow
exit 1
}

$response | ConvertTo-Json -Depth 20
} catch {
$statusCode = $null
if ($_.Exception.Response) {
$statusCode = $_.Exception.Response.StatusCode.value__
$reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
$responseBody = $reader.ReadToEnd()
try {
$errorResponse = $responseBody | ConvertFrom-Json
if ($errorResponse.success -eq $false) {
Write-Host "Chat failed:" -ForegroundColor Red
Write-Host " errorCode: $($errorResponse.errorCode)" -ForegroundColor Yellow
Write-Host " error: $($errorResponse.error)" -ForegroundColor Yellow
if ($statusCode) {
Write-Host " httpStatus: $statusCode" -ForegroundColor Yellow
}
exit 1
}
} catch {
# Not JSON, show raw response
}
Write-Host "Error: $_" -ForegroundColor Red
Write-Host "Response: $responseBody" -ForegroundColor Yellow
} else {
Write-Host "Error: $_" -ForegroundColor Red
}
exit 1
}
Loading