-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
1640 lines (1367 loc) · 41.4 KB
/
install.sh
File metadata and controls
1640 lines (1367 loc) · 41.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# DialogChain Universal Installer & Project Creator
# Supports Linux, macOS, and Windows (WSL/Git Bash)
# Usage: curl -sSL https://install.dialogchain.io | bash
set -euo pipefail
# =============================================================================
# Configuration and Constants
# =============================================================================
readonly DIALOGCHAIN_VERSION="0.1.0"
readonly INSTALL_DIR="${DIALOGCHAIN_HOME:-$HOME/.dialogchain}"
readonly BIN_DIR="$INSTALL_DIR/bin"
readonly CONFIG_DIR="$INSTALL_DIR/config"
readonly TEMPLATES_DIR="$INSTALL_DIR/templates"
readonly LOG_FILE="$INSTALL_DIR/install.log"
# Colors for output
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly BLUE='\033[0;34m'
readonly PURPLE='\033[0;35m'
readonly CYAN='\033[0;36m'
readonly NC='\033[0m' # No Color
# System detection
OS=""
ARCH=""
PACKAGE_MANAGER=""
# =============================================================================
# Utility Functions
# =============================================================================
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $*" | tee -a "$LOG_FILE" >/dev/null
}
info() {
echo -e "${BLUE}[INFO]${NC} $*"
log "INFO: $*"
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $*"
log "SUCCESS: $*"
}
warning() {
echo -e "${YELLOW}[WARNING]${NC} $*"
log "WARNING: $*"
}
error() {
echo -e "${RED}[ERROR]${NC} $*" >&2
log "ERROR: $*"
}
fatal() {
error "$*"
exit 1
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
spinner() {
local pid=$1
local delay=0.1
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
# =============================================================================
# System Detection
# =============================================================================
detect_system() {
info "Detecting system information..."
# Detect OS
case "$(uname -s)" in
Linux*) OS="linux";;
Darwin*) OS="macos";;
CYGWIN*|MINGW*|MSYS*) OS="windows";;
*) fatal "Unsupported operating system: $(uname -s)";;
esac
# Detect Architecture
case "$(uname -m)" in
x86_64|amd64) ARCH="x86_64";;
arm64|aarch64) ARCH="arm64";;
armv7l) ARCH="armv7";;
*) fatal "Unsupported architecture: $(uname -m)";;
esac
# Detect Package Manager
if command_exists apt-get; then
PACKAGE_MANAGER="apt"
elif command_exists yum; then
PACKAGE_MANAGER="yum"
elif command_exists dnf; then
PACKAGE_MANAGER="dnf"
elif command_exists pacman; then
PACKAGE_MANAGER="pacman"
elif command_exists brew; then
PACKAGE_MANAGER="brew"
elif command_exists zypper; then
PACKAGE_MANAGER="zypper"
else
warning "No supported package manager found. Manual installation required."
PACKAGE_MANAGER="manual"
fi
success "System detected: $OS ($ARCH) with $PACKAGE_MANAGER"
}
# =============================================================================
# Dependency Installation
# =============================================================================
install_system_dependencies() {
info "Installing system dependencies..."
local deps=""
case $OS in
"linux")
case $PACKAGE_MANAGER in
"apt")
deps="curl wget git build-essential pkg-config libssl-dev python3 python3-pip nodejs npm docker.io"
sudo apt-get update
sudo apt-get install -y $deps
;;
"yum"|"dnf")
deps="curl wget git gcc gcc-c++ make pkgconfig openssl-devel python3 python3-pip nodejs npm docker"
sudo $PACKAGE_MANAGER install -y $deps
;;
"pacman")
deps="curl wget git base-devel openssl python python-pip nodejs npm docker"
sudo pacman -S --noconfirm $deps
;;
"zypper")
deps="curl wget git gcc gcc-c++ make pkg-config libopenssl-devel python3 python3-pip nodejs npm docker"
sudo zypper install -y $deps
;;
*)
warning "Please install manually: curl, wget, git, build tools, OpenSSL, Python3, Node.js, Docker"
;;
esac
;;
"macos")
if [[ $PACKAGE_MANAGER == "brew" ]]; then
deps="curl wget git openssl python3 node docker"
brew install $deps
else
warning "Please install Homebrew or manually install: curl, wget, git, OpenSSL, Python3, Node.js, Docker"
fi
;;
"windows")
warning "On Windows, please ensure you have: Git, Python3, Node.js, Docker Desktop installed"
;;
esac
}
install_rust() {
if command_exists rustc; then
info "Rust is already installed: $(rustc --version)"
return
fi
info "Installing Rust toolchain..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
# Source cargo env
source "$HOME/.cargo/env" 2>/dev/null || true
if command_exists rustc; then
success "Rust installed successfully: $(rustc --version)"
else
fatal "Failed to install Rust. Please install manually from https://rustup.rs/"
fi
}
install_go() {
if command_exists go; then
info "Go is already installed: $(go version)"
return
fi
info "Installing Go..."
local go_version="1.21.5"
local go_archive="go${go_version}.${OS}-${ARCH}.tar.gz"
local go_url="https://golang.org/dl/${go_archive}"
case $OS in
"linux"|"macos")
curl -L "$go_url" -o "/tmp/$go_archive"
sudo tar -C /usr/local -xzf "/tmp/$go_archive"
rm "/tmp/$go_archive"
# Add to PATH if not already there
if ! echo "$PATH" | grep -q "/usr/local/go/bin"; then
echo 'export PATH=$PATH:/usr/local/go/bin' >> "$HOME/.bashrc"
echo 'export PATH=$PATH:/usr/local/go/bin' >> "$HOME/.zshrc" 2>/dev/null || true
export PATH=$PATH:/usr/local/go/bin
fi
;;
"windows")
warning "Please install Go manually from https://golang.org/dl/"
;;
esac
if command_exists go; then
success "Go installed successfully: $(go version)"
else
warning "Go installation may require manual PATH configuration"
fi
}
install_python_deps() {
info "Installing Python dependencies..."
# Create virtual environment for DialogChain
python3 -m venv "$INSTALL_DIR/python-env"
source "$INSTALL_DIR/python-env/bin/activate"
# Upgrade pip
pip install --upgrade pip
# Install common ML/AI packages
pip install \
torch torchvision torchaudio \
ultralytics \
opencv-python \
numpy pandas scikit-learn \
fastapi uvicorn \
pika paho-mqtt \
psycopg2-binary pymongo redis \
prometheus-client \
pyyaml toml
deactivate
success "Python environment created at $INSTALL_DIR/python-env"
}
install_node_deps() {
info "Setting up Node.js environment..."
# Create package.json for global DialogChain deps
mkdir -p "$INSTALL_DIR/node-env"
cd "$INSTALL_DIR/node-env"
cat > package.json << 'EOF'
{
"name": "dialogchain-node-env",
"version": "1.0.0",
"description": "Node.js environment for DialogChain processors",
"dependencies": {
"express": "^4.18.2",
"ws": "^8.14.2",
"mqtt": "^5.3.0",
"axios": "^1.6.2",
"pg": "^8.11.3",
"mongodb": "^6.3.0",
"redis": "^4.6.11",
"prom-client": "^15.1.0",
"yaml": "^2.3.4",
"sharp": "^0.33.1"
}
}
EOF
npm install
cd - >/dev/null
success "Node.js environment created at $INSTALL_DIR/node-env"
}
setup_docker() {
if ! command_exists docker; then
warning "Docker not found. Some features will be unavailable."
return
fi
info "Setting up Docker environment..."
# Start Docker service if not running (Linux only)
if [[ $OS == "linux" ]]; then
if ! systemctl is-active --quiet docker; then
sudo systemctl start docker
sudo systemctl enable docker
fi
# Add current user to docker group
if ! groups | grep -q docker; then
sudo usermod -aG docker "$USER"
warning "Added user to docker group. Please log out and log back in for changes to take effect."
fi
fi
# Pull useful base images
docker pull python:3.11-slim &
docker pull node:18-alpine &
docker pull golang:1.21-alpine &
docker pull rust:1.75-slim &
wait
success "Docker environment configured"
}
# =============================================================================
# DialogChain Installation
# =============================================================================
create_directory_structure() {
info "Creating DialogChain directory structure..."
mkdir -p "$INSTALL_DIR"/{bin,config,templates,logs,projects,cache}
mkdir -p "$TEMPLATES_DIR"/{examples,processors,triggers,outputs}
# Create log file
touch "$LOG_FILE"
success "Directory structure created at $INSTALL_DIR"
}
install_dialogchain_cli() {
info "Installing DialogChain CLI..."
# For now, we'll create a comprehensive CLI script
# In production, this would download pre-compiled binaries
cat > "$BIN_DIR/dialogchain" << 'EOF'
#!/bin/bash
# DialogChain CLI Tool
set -euo pipefail
readonly DIALOGCHAIN_HOME="${DIALOGCHAIN_HOME:-$HOME/.dialogchain}"
readonly TEMPLATES_DIR="$DIALOGCHAIN_HOME/templates"
readonly PROJECTS_DIR="$DIALOGCHAIN_HOME/projects"
# Colors
readonly GREEN='\033[0;32m'
readonly BLUE='\033[0;34m'
readonly RED='\033[0;31m'
readonly NC='\033[0m'
info() { echo -e "${BLUE}[INFO]${NC} $*"; }
success() { echo -e "${GREEN}[SUCCESS]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
show_help() {
cat << 'HELP'
DialogChain CLI - Multi-language Pipeline Engine
USAGE:
dialogchain <COMMAND> [OPTIONS]
COMMANDS:
create <name> Create new pipeline project
init Initialize current directory as DialogChain project
validate <config> Validate pipeline configuration
run <config> Run pipeline from configuration
dev <config> Run pipeline in development mode with hot reload
build <config> Build pipeline for production deployment
deploy <config> Deploy pipeline to production
logs [pipeline] Show pipeline execution logs
status Show status of running pipelines
stop <pipeline> Stop running pipeline
templates List available templates
examples Show example configurations
doctor Check system dependencies
version Show version information
OPTIONS:
-h, --help Show this help message
-v, --verbose Enable verbose output
--env <environment> Specify environment (dev, staging, prod)
--config <file> Override default config file
EXAMPLES:
dialogchain create my-security-system
dialogchain run pipeline.yaml
dialogchain dev --env development pipeline.yaml
dialogchain deploy --env production pipeline.yaml
For more information, visit: https://dialogchain.io/docs
HELP
}
create_project() {
local project_name="$1"
local project_dir="$PROJECTS_DIR/$project_name"
if [[ -d "$project_dir" ]]; then
error "Project '$project_name' already exists"
exit 1
fi
info "Creating new DialogChain project: $project_name"
mkdir -p "$project_dir"/{configs,processors,scripts,docker,docs}
# Create main pipeline configuration
cat > "$project_dir/pipeline.yaml" << 'YAML'
name: "PROJECT_NAME"
version: "1.0.0"
description: "Generated DialogChain pipeline"
triggers:
- id: http_input
type: http
port: 8080
path: /webhook
enabled: true
processors:
- id: main_processor
type: python
script: "processors/main.py"
parallel: true
timeout: 5000
retry: 2
dependencies: []
outputs:
- id: console_output
type: file
path: "logs/output.log"
format: "json"
settings:
performance:
max_concurrent: 10
buffer_size: 1000
monitoring:
enabled: true
security:
require_auth: false
YAML
# Replace PROJECT_NAME with actual name
sed -i "s/PROJECT_NAME/$project_name/g" "$project_dir/pipeline.yaml"
# Create example Python processor
cat > "$project_dir/processors/main.py" << 'PYTHON'
#!/usr/bin/env python3
"""
Example DialogChain processor
Reads JSON data from stdin, processes it, and outputs to stdout
"""
import json
import sys
from datetime import datetime
def process_data(data):
"""Main processing function"""
try:
# Add timestamp
data['processed_at'] = datetime.utcnow().isoformat()
data['processor'] = 'main_processor'
# Your processing logic here
if 'message' in data:
data['message'] = data['message'].upper()
return data
except Exception as e:
return {'error': str(e), 'original_data': data}
def main():
try:
# Read input from stdin
input_data = json.load(sys.stdin)
# Process the data
result = process_data(input_data)
# Output result to stdout
json.dump(result, sys.stdout, indent=2)
except Exception as e:
error_output = {'error': f'Processor failed: {str(e)}'}
json.dump(error_output, sys.stdout, indent=2)
sys.exit(1)
if __name__ == '__main__':
main()
PYTHON
chmod +x "$project_dir/processors/main.py"
# Create Go processor example
cat > "$project_dir/processors/main.go" << 'GO'
package main
import (
"encoding/json"
"fmt"
"os"
"time"
)
type ProcessorData struct {
Message string `json:"message,omitempty"`
ProcessedAt string `json:"processed_at"`
Processor string `json:"processor"`
Data map[string]interface{} `json:"data,omitempty"`
}
func main() {
var input map[string]interface{}
// Read from stdin
decoder := json.NewDecoder(os.Stdin)
if err := decoder.Decode(&input); err != nil {
fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err)
os.Exit(1)
}
// Process the data
result := ProcessorData{
ProcessedAt: time.Now().UTC().Format(time.RFC3339),
Processor: "go_processor",
Data: input,
}
if msg, ok := input["message"].(string); ok {
result.Message = fmt.Sprintf("Processed: %s", msg)
}
// Output to stdout
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
if err := encoder.Encode(result); err != nil {
fmt.Fprintf(os.Stderr, "Error encoding output: %v\n", err)
os.Exit(1)
}
}
GO
# Create Docker configuration
cat > "$project_dir/docker/Dockerfile" << 'DOCKERFILE'
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Make scripts executable
RUN chmod +x processors/*.py
EXPOSE 8080
CMD ["python", "-m", "dialogchain.runner", "pipeline.yaml"]
DOCKERFILE
# Create requirements.txt
cat > "$project_dir/requirements.txt" << 'REQUIREMENTS'
pyyaml>=6.0
requests>=2.31.0
paho-mqtt>=1.6.1
fastapi>=0.104.0
uvicorn>=0.24.0
websockets>=11.0
aiofiles>=23.0
prometheus-client>=0.19.0
psycopg2-binary>=2.9.7
redis>=5.0.0
REQUIREMENTS
# Create docker-compose.yml
cat > "$project_dir/docker-compose.yml" << 'COMPOSE'
version: '3.8'
services:
dialogchain:
build:
context: .
dockerfile: docker/Dockerfile
ports:
- "8080:8080"
environment:
- ENVIRONMENT=development
- LOG_LEVEL=INFO
volumes:
- ./logs:/app/logs
- ./configs:/app/configs
depends_on:
- redis
- postgres
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
postgres:
image: postgres:15-alpine
environment:
POSTGRES_DB: dialogchain
POSTGRES_USER: dialogchain
POSTGRES_PASSWORD: password
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
mqtt:
image: eclipse-mosquitto:2
ports:
- "1883:1883"
- "9001:9001"
volumes:
- ./configs/mosquitto.conf:/mosquitto/config/mosquitto.conf
volumes:
redis_data:
postgres_data:
COMPOSE
# Create README.md
cat > "$project_dir/README.md" << 'README'
# PROJECT_NAME
DialogChain pipeline for automated data processing.
## Quick Start
1. **Development Mode:**
```bash
dialogchain dev pipeline.yaml
```
2. **Production Build:**
```bash
dialogchain build pipeline.yaml
dialogchain deploy --env production pipeline.yaml
```
3. **Docker Deployment:**
```bash
docker-compose up -d
```
## Project Structure
```
├── pipeline.yaml # Main pipeline configuration
├── processors/ # Custom processors
│ ├── main.py # Python processor example
│ └── main.go # Go processor example
├── configs/ # Environment-specific configs
├── scripts/ # Utility scripts
├── docker/ # Docker configuration
├── docs/ # Documentation
└── logs/ # Log files
```
## Configuration
Edit `pipeline.yaml` to customize your pipeline:
- **Triggers**: Define input sources (HTTP, MQTT, timers, etc.)
- **Processors**: Add data processing steps
- **Outputs**: Configure destinations for processed data
## Processors
### Python Processors
- Located in `processors/` directory
- Must read from stdin and write to stdout
- JSON format for data exchange
### Go Processors
- Compile with: `go build -o processors/processor processors/main.go`
- Same stdin/stdout interface
## Monitoring
- Logs: `dialogchain logs`
- Status: `dialogchain status`
- Metrics: Available at http://localhost:9090/metrics
## Deployment
### Local Development
```bash
dialogchain dev pipeline.yaml
```
### Production
```bash
dialogchain deploy --env production pipeline.yaml
```
### Docker
```bash
docker-compose up -d
```
For more information, visit: https://dialogchain.io/docs
README
sed -i "s/PROJECT_NAME/$project_name/g" "$project_dir/README.md"
# Create .gitignore
cat > "$project_dir/.gitignore" << 'GITIGNORE'
# DialogChain
logs/
cache/
*.log
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
ENV/
# Go
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
# Node.js
node_modules/
npm-debug.log*
yarn-debug.log*
# Docker
.docker/
# IDE
.vscode/
.idea/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
GITIGNORE
# Create environment configurations
mkdir -p "$project_dir/configs"
cat > "$project_dir/configs/development.yaml" << 'DEV_CONFIG'
environment: development
debug: true
log_level: DEBUG
settings:
performance:
max_concurrent: 5
buffer_size: 100
monitoring:
enabled: true
metrics_port: 9090
security:
require_auth: false
rate_limit: 100
DEV_CONFIG
cat > "$project_dir/configs/production.yaml" << 'PROD_CONFIG'
environment: production
debug: false
log_level: INFO
settings:
performance:
max_concurrent: 50
buffer_size: 10000
monitoring:
enabled: true
metrics_port: 9090
security:
require_auth: true
rate_limit: 10000
tls:
cert_file: "/certs/server.crt"
key_file: "/certs/server.key"
PROD_CONFIG
success "Project '$project_name' created successfully at $project_dir"
info "Next steps:"
echo " cd $project_dir"
echo " dialogchain dev pipeline.yaml"
}
case "${1:-help}" in
"create")
if [[ $# -lt 2 ]]; then
error "Project name required"
echo "Usage: dialogchain create <project_name>"
exit 1
fi
create_project "$2"
;;
"help"|"-h"|"--help")
show_help
;;
"version"|"-v"|"--version")
echo "DialogChain CLI v0.1.0"
;;
*)
error "Unknown command: $1"
echo "Run 'dialogchain help' for usage information"
exit 1
;;
esac
EOF
chmod +x "$BIN_DIR/dialogchain"
success "DialogChain CLI installed"
}
create_templates() {
info "Creating project templates..."
# Security System Template
cat > "$TEMPLATES_DIR/examples/security_system.yaml" << 'EOF'
name: "smart_security_system"
version: "1.0.0"
description: "AI-powered security monitoring with real-time alerts"
triggers:
- id: camera_feed
type: http
port: 8080
path: /camera/frame
enabled: true
- id: motion_sensor
type: mqtt
broker: "mqtt://localhost:1883"
topic: "sensors/motion"
enabled: true
processors:
- id: object_detection
type: python
script: "processors/yolo_detect.py"
venv: "/opt/dialogchain/python-env"
parallel: true
timeout: 5000
retry: 2
dependencies: []
environment:
MODEL_PATH: "/models/yolov8n.pt"
CONFIDENCE_THRESHOLD: "0.6"
- id: threat_analysis
type: go
binary: "./processors/threat-analyzer"
args: ["--confidence=0.7"]
parallel: false
timeout: 2000
retry: 1
dependencies: ["object_detection"]
outputs:
- id: security_alert
type: email
smtp: "smtp://localhost:587"
to: ["security@company.com"]
condition: "threat_level > 0.8"
- id: dashboard_update
type: websocket
url: "ws://dashboard:3000/alerts"
batch_size: 10
settings:
performance:
max_concurrent: 10
buffer_size: 1000
monitoring:
enabled: true
security:
require_auth: true
rate_limit: 1000
EOF
# IoT Data Processing Template
cat > "$TEMPLATES_DIR/examples/iot_processing.yaml" << 'EOF'
name: "iot_data_processor"
version: "1.0.0"
description: "High-throughput IoT data processing and analytics"
triggers:
- id: sensor_data
type: mqtt
broker: "mqtt://iot-broker:1883"
topic: "sensors/+/data"
enabled: true
- id: api_endpoint
type: http
port: 8080
path: /api/sensors
enabled: true
processors:
- id: data_validation
type: rust_wasm
wasm: "processors/validator.wasm"
parallel: true
timeout: 1000
retry: 0
dependencies: []
- id: anomaly_detection
type: python
script: "processors/anomaly_detector.py"
parallel: true
timeout: 3000
retry: 1
dependencies: ["data_validation"]
- id: aggregation
type: go
binary: "./processors/aggregator"
parallel: false
timeout: 2000
retry: 1
dependencies: ["anomaly_detection"]
outputs:
- id: database_storage
type: database
connection: "postgresql://user:pass@localhost/iot"
table: "sensor_readings"
batch_size: 1000
- id: real_time_dashboard
type: websocket
url: "ws://dashboard:3000/data"
condition: "anomaly_score > 0.5"
settings:
performance:
max_concurrent: 100
buffer_size: 10000
monitoring:
enabled: true
EOF
success "Templates created"
}
update_shell_profile() {
info "Updating shell profile..."
local shell_profile=""
if [[ -n "${BASH_VERSION:-}" ]]; then
shell_profile="$HOME/.bashrc"
elif [[ -n "${ZSH_VERSION:-}" ]]; then
shell_profile="$HOME/.zshrc"
else
shell_profile="$HOME/.profile"
fi
# Add DialogChain to PATH
if ! grep -q "DIALOGCHAIN_HOME" "$shell_profile" 2>/dev/null; then
cat >> "$shell_profile" << EOF
# DialogChain Configuration