opc-agent 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opc/memory.db +0 -0
- package/COMPETITIVE-GAP.md +92 -92
- package/CONTRIBUTING.md +36 -36
- package/README.md +290 -290
- package/README.zh-CN.md +269 -269
- package/STUDIO-REWRITE-TASK.md +76 -0
- package/dist/channels/telegram.d.ts +5 -0
- package/dist/channels/telegram.d.ts.map +1 -1
- package/dist/channels/telegram.js +108 -0
- package/dist/channels/telegram.js.map +1 -1
- package/dist/channels/voice.d.ts +71 -97
- package/dist/channels/voice.d.ts.map +1 -1
- package/dist/channels/voice.js +369 -347
- package/dist/channels/voice.js.map +1 -1
- package/dist/channels/web.d.ts.map +1 -1
- package/dist/channels/web.js +8 -2
- package/dist/channels/web.js.map +1 -1
- package/dist/channels/wechat.js +6 -6
- package/dist/cli/chat.d.ts +4 -1
- package/dist/cli/chat.d.ts.map +1 -1
- package/dist/cli/chat.js +680 -73
- package/dist/cli/chat.js.map +1 -1
- package/dist/cli/setup.js +1 -1
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli.js +373 -280
- package/dist/cli.js.map +1 -1
- package/dist/core/a2a-http.d.ts +75 -0
- package/dist/core/a2a-http.d.ts.map +1 -0
- package/dist/core/a2a-http.js +217 -0
- package/dist/core/a2a-http.js.map +1 -0
- package/dist/core/a2a.d.ts +2 -0
- package/dist/core/a2a.d.ts.map +1 -1
- package/dist/core/a2a.js +6 -1
- package/dist/core/a2a.js.map +1 -1
- package/dist/core/agent.d.ts +1 -0
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +3 -0
- package/dist/core/agent.js.map +1 -1
- package/dist/core/gateway-registry.d.ts +116 -0
- package/dist/core/gateway-registry.d.ts.map +1 -0
- package/dist/core/gateway-registry.js +280 -0
- package/dist/core/gateway-registry.js.map +1 -0
- package/dist/core/model-recommender.d.ts +40 -0
- package/dist/core/model-recommender.d.ts.map +1 -0
- package/dist/core/model-recommender.js +186 -0
- package/dist/core/model-recommender.js.map +1 -0
- package/dist/core/priority-queue.d.ts +100 -0
- package/dist/core/priority-queue.d.ts.map +1 -0
- package/dist/core/priority-queue.js +181 -0
- package/dist/core/priority-queue.js.map +1 -0
- package/dist/core/runtime.d.ts.map +1 -1
- package/dist/core/runtime.js +192 -22
- package/dist/core/runtime.js.map +1 -1
- package/dist/deploy/index.js +56 -56
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +155 -10
- package/dist/doctor.js.map +1 -1
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -13
- package/dist/index.js.map +1 -1
- package/dist/memory/deepbrain.d.ts +1 -1
- package/dist/memory/deepbrain.d.ts.map +1 -1
- package/dist/memory/deepbrain.js +95 -4
- package/dist/memory/deepbrain.js.map +1 -1
- package/dist/memory/evolve-engine.d.ts +113 -0
- package/dist/memory/evolve-engine.d.ts.map +1 -0
- package/dist/memory/evolve-engine.js +549 -0
- package/dist/memory/evolve-engine.js.map +1 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +3 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/sqlite-store.d.ts +40 -0
- package/dist/memory/sqlite-store.d.ts.map +1 -0
- package/dist/memory/sqlite-store.js +269 -0
- package/dist/memory/sqlite-store.js.map +1 -0
- package/dist/memory/user-profiler.d.ts +8 -0
- package/dist/memory/user-profiler.d.ts.map +1 -1
- package/dist/memory/user-profiler.js +89 -0
- package/dist/memory/user-profiler.js.map +1 -1
- package/dist/scheduler/cron-engine.d.ts.map +1 -1
- package/dist/scheduler/cron-engine.js +3 -36
- package/dist/scheduler/cron-engine.js.map +1 -1
- package/dist/scheduler/proactive.d.ts +62 -0
- package/dist/scheduler/proactive.d.ts.map +1 -0
- package/dist/scheduler/proactive.js +185 -0
- package/dist/scheduler/proactive.js.map +1 -0
- package/dist/skills/auto-learn.d.ts.map +1 -1
- package/dist/skills/auto-learn.js +65 -11
- package/dist/skills/auto-learn.js.map +1 -1
- package/dist/skills/builtin/index.d.ts.map +1 -1
- package/dist/skills/builtin/index.js +163 -30
- package/dist/skills/builtin/index.js.map +1 -1
- package/dist/skills/types.d.ts +1 -1
- package/dist/skills/types.d.ts.map +1 -1
- package/dist/skills/types.js +1 -0
- package/dist/skills/types.js.map +1 -1
- package/dist/studio/server.d.ts +1 -0
- package/dist/studio/server.d.ts.map +1 -1
- package/dist/studio/server.js +148 -17
- package/dist/studio/server.js.map +1 -1
- package/dist/studio-ui/index.html +867 -2630
- package/dist/ui/components.js +105 -105
- package/examples/README.md +22 -22
- package/examples/basic-agent.ts +90 -90
- package/examples/brain-integration.ts +71 -71
- package/examples/multi-channel.ts +74 -74
- package/install.ps1 +127 -127
- package/install.sh +154 -154
- package/models.json +164 -164
- package/package.json +5 -2
- package/scripts/install.ps1 +31 -31
- package/scripts/install.sh +40 -40
- package/templates/ecommerce-assistant/README.md +45 -45
- package/templates/ecommerce-assistant/oad.yaml +47 -47
- package/templates/tech-support/README.md +43 -43
- package/templates/tech-support/oad.yaml +45 -45
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OPC Agent Example: Multi-Channel Setup
|
|
3
|
-
*
|
|
4
|
-
* Shows how to configure Web + Telegram channels for an agent.
|
|
5
|
-
* Note: This is a configuration demo — actual channel connections
|
|
6
|
-
* require valid tokens/endpoints.
|
|
7
|
-
*
|
|
8
|
-
* Run: npx tsx examples/multi-channel.ts
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
BaseAgent,
|
|
13
|
-
AgentRuntime,
|
|
14
|
-
WebChannel,
|
|
15
|
-
TelegramChannel,
|
|
16
|
-
InMemoryStore,
|
|
17
|
-
} from 'opc-agent';
|
|
18
|
-
|
|
19
|
-
async function main() {
|
|
20
|
-
console.log('🌐 OPC Agent — Multi-Channel Demo\n');
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const agent = new BaseAgent({
|
|
24
|
-
name: 'multi-channel-agent',
|
|
25
|
-
description: 'Agent that works across multiple channels',
|
|
26
|
-
version: '1.0.0',
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const memory = new InMemoryStore();
|
|
30
|
-
const runtime = new AgentRuntime(agent, { memory });
|
|
31
|
-
|
|
32
|
-
// Channel 1: Web (HTTP endpoint)
|
|
33
|
-
const webChannel = new WebChannel({
|
|
34
|
-
port: 3000,
|
|
35
|
-
path: '/chat',
|
|
36
|
-
});
|
|
37
|
-
console.log('📡 Web channel configured: http://localhost:3000/chat');
|
|
38
|
-
|
|
39
|
-
// Channel 2: Telegram (requires BOT_TOKEN)
|
|
40
|
-
const telegramToken = process.env.TELEGRAM_BOT_TOKEN;
|
|
41
|
-
if (telegramToken) {
|
|
42
|
-
const telegramChannel = new TelegramChannel({
|
|
43
|
-
token: telegramToken,
|
|
44
|
-
});
|
|
45
|
-
runtime.addChannel(telegramChannel);
|
|
46
|
-
console.log('📱 Telegram channel configured');
|
|
47
|
-
} else {
|
|
48
|
-
console.log('📱 Telegram: skipped (set TELEGRAM_BOT_TOKEN to enable)');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Register web channel
|
|
52
|
-
runtime.addChannel(webChannel);
|
|
53
|
-
|
|
54
|
-
console.log('\n✅ Agent configured with channels:');
|
|
55
|
-
console.log(' • Web: HTTP REST endpoint');
|
|
56
|
-
console.log(' • Telegram: Bot API (optional)');
|
|
57
|
-
console.log('\nAvailable channels in OPC Agent:');
|
|
58
|
-
console.log(' WebChannel, TelegramChannel, WebSocketChannel,');
|
|
59
|
-
console.log(' SlackChannel, DiscordChannel, FeishuChannel,');
|
|
60
|
-
console.log(' EmailChannel, WeChatChannel, VoiceChannel,');
|
|
61
|
-
console.log(' WebhookChannel\n');
|
|
62
|
-
|
|
63
|
-
// In production you would call: await runtime.start();
|
|
64
|
-
console.log('💡 To start: await runtime.start()');
|
|
65
|
-
} catch (e: any) {
|
|
66
|
-
console.error(`❌ Error: ${e.message}`);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
main().catch(e => {
|
|
72
|
-
console.error(`\n❌ Error: ${e.message}\n`);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* OPC Agent Example: Multi-Channel Setup
|
|
3
|
+
*
|
|
4
|
+
* Shows how to configure Web + Telegram channels for an agent.
|
|
5
|
+
* Note: This is a configuration demo — actual channel connections
|
|
6
|
+
* require valid tokens/endpoints.
|
|
7
|
+
*
|
|
8
|
+
* Run: npx tsx examples/multi-channel.ts
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
BaseAgent,
|
|
13
|
+
AgentRuntime,
|
|
14
|
+
WebChannel,
|
|
15
|
+
TelegramChannel,
|
|
16
|
+
InMemoryStore,
|
|
17
|
+
} from 'opc-agent';
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
console.log('🌐 OPC Agent — Multi-Channel Demo\n');
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const agent = new BaseAgent({
|
|
24
|
+
name: 'multi-channel-agent',
|
|
25
|
+
description: 'Agent that works across multiple channels',
|
|
26
|
+
version: '1.0.0',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const memory = new InMemoryStore();
|
|
30
|
+
const runtime = new AgentRuntime(agent, { memory });
|
|
31
|
+
|
|
32
|
+
// Channel 1: Web (HTTP endpoint)
|
|
33
|
+
const webChannel = new WebChannel({
|
|
34
|
+
port: 3000,
|
|
35
|
+
path: '/chat',
|
|
36
|
+
});
|
|
37
|
+
console.log('📡 Web channel configured: http://localhost:3000/chat');
|
|
38
|
+
|
|
39
|
+
// Channel 2: Telegram (requires BOT_TOKEN)
|
|
40
|
+
const telegramToken = process.env.TELEGRAM_BOT_TOKEN;
|
|
41
|
+
if (telegramToken) {
|
|
42
|
+
const telegramChannel = new TelegramChannel({
|
|
43
|
+
token: telegramToken,
|
|
44
|
+
});
|
|
45
|
+
runtime.addChannel(telegramChannel);
|
|
46
|
+
console.log('📱 Telegram channel configured');
|
|
47
|
+
} else {
|
|
48
|
+
console.log('📱 Telegram: skipped (set TELEGRAM_BOT_TOKEN to enable)');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Register web channel
|
|
52
|
+
runtime.addChannel(webChannel);
|
|
53
|
+
|
|
54
|
+
console.log('\n✅ Agent configured with channels:');
|
|
55
|
+
console.log(' • Web: HTTP REST endpoint');
|
|
56
|
+
console.log(' • Telegram: Bot API (optional)');
|
|
57
|
+
console.log('\nAvailable channels in OPC Agent:');
|
|
58
|
+
console.log(' WebChannel, TelegramChannel, WebSocketChannel,');
|
|
59
|
+
console.log(' SlackChannel, DiscordChannel, FeishuChannel,');
|
|
60
|
+
console.log(' EmailChannel, WeChatChannel, VoiceChannel,');
|
|
61
|
+
console.log(' WebhookChannel\n');
|
|
62
|
+
|
|
63
|
+
// In production you would call: await runtime.start();
|
|
64
|
+
console.log('💡 To start: await runtime.start()');
|
|
65
|
+
} catch (e: any) {
|
|
66
|
+
console.error(`❌ Error: ${e.message}`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
main().catch(e => {
|
|
72
|
+
console.error(`\n❌ Error: ${e.message}\n`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
});
|
package/install.ps1
CHANGED
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
# ============================================================================
|
|
2
|
-
# OPC Agent 一键安装脚本 for Windows PowerShell
|
|
3
|
-
# 用法: irm https://raw.githubusercontent.com/Deepleaper/opc-agent/main/install.ps1 | iex
|
|
4
|
-
# 高级: $env:OPC_NO_OLLAMA='1'; irm ... | iex
|
|
5
|
-
# ============================================================================
|
|
6
|
-
|
|
7
|
-
$ErrorActionPreference = "Stop"
|
|
8
|
-
|
|
9
|
-
# ── 颜色输出 ──────────────────────────────────────────────────
|
|
10
|
-
function Write-Step($msg) { Write-Host "`n━━━ $msg ━━━" -ForegroundColor Blue }
|
|
11
|
-
function Write-Ok($msg) { Write-Host "✅ $msg" -ForegroundColor Green }
|
|
12
|
-
function Write-Warn($msg) { Write-Host "⚠️ $msg" -ForegroundColor Yellow }
|
|
13
|
-
function Write-Err($msg) { Write-Host "❌ $msg" -ForegroundColor Red }
|
|
14
|
-
function Write-Info($msg) { Write-Host "ℹ️ $msg" -ForegroundColor Cyan }
|
|
15
|
-
|
|
16
|
-
$SkipOllama = $env:OPC_NO_OLLAMA -eq '1'
|
|
17
|
-
|
|
18
|
-
# ── Banner ────────────────────────────────────────────────────
|
|
19
|
-
Write-Host ""
|
|
20
|
-
Write-Host " ___ ____ ____ _ _ " -ForegroundColor Cyan
|
|
21
|
-
Write-Host " / _ \| _ \/ ___| / \ __ _ ___ _ __ | |_ " -ForegroundColor Cyan
|
|
22
|
-
Write-Host " | | | | |_) \___ \ / _ \ / _`` |/ _ \ '_ \| __|" -ForegroundColor Cyan
|
|
23
|
-
Write-Host " | |_| | __/ ___) / ___ \ (_| | __/ | | | |_ " -ForegroundColor Cyan
|
|
24
|
-
Write-Host " \___/|_| |____/_/ \_\__, |\___|_| |_|\__|" -ForegroundColor Cyan
|
|
25
|
-
Write-Host " |___/ " -ForegroundColor Cyan
|
|
26
|
-
Write-Host ""
|
|
27
|
-
Write-Info "一键安装 OPC Agent / One-line installer for OPC Agent"
|
|
28
|
-
Write-Host ""
|
|
29
|
-
|
|
30
|
-
# ── 检测操作系统 ──────────────────────────────────────────────
|
|
31
|
-
Write-Step "🔍 检测操作系统 / Detecting OS"
|
|
32
|
-
Write-Ok "Windows $([System.Environment]::OSVersion.Version) detected"
|
|
33
|
-
|
|
34
|
-
# ── 检测 Node.js ─────────────────────────────────────────────
|
|
35
|
-
Write-Step "📦 检测 Node.js (>=18) / Checking Node.js"
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
$nodeVerFull = (node -v)
|
|
39
|
-
$nodeVerMajor = [int]($nodeVerFull -replace 'v','' -split '\.' | Select-Object -First 1)
|
|
40
|
-
if ($nodeVerMajor -ge 18) {
|
|
41
|
-
Write-Ok "Node.js $nodeVerFull ✓"
|
|
42
|
-
} else {
|
|
43
|
-
Write-Err "Node.js $nodeVerFull 版本过低 / version too old (need >=18)"
|
|
44
|
-
Write-Err "修复建议 / Fix: winget install OpenJS.NodeJS.LTS"
|
|
45
|
-
Write-Info "或访问 / or visit: https://nodejs.org/"
|
|
46
|
-
exit 1
|
|
47
|
-
}
|
|
48
|
-
} catch {
|
|
49
|
-
Write-Err "未检测到 Node.js / Node.js not found"
|
|
50
|
-
Write-Err "修复建议 / Fix:"
|
|
51
|
-
Write-Info " winget install OpenJS.NodeJS.LTS"
|
|
52
|
-
Write-Info " # 或访问 / or visit: https://nodejs.org/"
|
|
53
|
-
exit 1
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
# ── 检测 npm ─────────────────────────────────────────────────
|
|
57
|
-
try { npm --version | Out-Null } catch {
|
|
58
|
-
Write-Err "未检测到 npm / npm not found"
|
|
59
|
-
Write-Err "修复建议 / Fix: 重新安装 Node.js"
|
|
60
|
-
exit 1
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
# ── 安装 OPC Agent ────────────────────────────────────────────
|
|
64
|
-
Write-Step "🚀 安装 OPC Agent / Installing OPC Agent"
|
|
65
|
-
Write-Info "运行 npm install -g opc-agent ..."
|
|
66
|
-
npm install -g opc-agent
|
|
67
|
-
if ($LASTEXITCODE -ne 0) { Write-Err "安装失败 / Install failed"; exit 1 }
|
|
68
|
-
|
|
69
|
-
$opcVer = try { opc --version 2>$null } catch { "unknown" }
|
|
70
|
-
Write-Ok "OPC Agent v$opcVer 安装成功 / installed successfully"
|
|
71
|
-
|
|
72
|
-
# ── 初始化 ────────────────────────────────────────────────────
|
|
73
|
-
Write-Step "⚙️ 初始化 OPC Agent / Initializing"
|
|
74
|
-
Write-Info "运行 opc init --yes ..."
|
|
75
|
-
try { opc init --yes; Write-Ok "初始化完成 / initialized" } catch { Write-Warn "初始化跳过(可能已初始化)/ init skipped" }
|
|
76
|
-
|
|
77
|
-
# ── 进入项目目录后再检查 ──────────────────────────────────────
|
|
78
|
-
if (Test-Path "my-agent") {
|
|
79
|
-
Set-Location "my-agent"
|
|
80
|
-
Write-Info "已进入 my-agent/ 目录 / Entered my-agent/ directory"
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
# ── 环境检查 ──────────────────────────────────────────────────
|
|
84
|
-
Write-Step "🩺 环境检查 / Running Doctor"
|
|
85
|
-
Write-Info "运行 opc doctor ..."
|
|
86
|
-
try { opc doctor } catch { Write-Warn "部分检查未通过,请查看上方输出 / Some checks failed" }
|
|
87
|
-
|
|
88
|
-
# ── Ollama(可选)─────────────────────────────────────────────
|
|
89
|
-
if (-not $SkipOllama) {
|
|
90
|
-
Write-Step "🦙 检测 Ollama (可选) / Checking Ollama (optional)"
|
|
91
|
-
|
|
92
|
-
$hasOllama = $false
|
|
93
|
-
try { ollama --version 2>$null | Out-Null; $hasOllama = $true } catch {}
|
|
94
|
-
|
|
95
|
-
if ($hasOllama) {
|
|
96
|
-
Write-Ok "Ollama 已安装 / installed ✓"
|
|
97
|
-
} else {
|
|
98
|
-
Write-Warn "未检测到 Ollama / Ollama not found"
|
|
99
|
-
Write-Info "Ollama 可让你在本地运行 AI 模型(免费、隐私安全)"
|
|
100
|
-
Write-Info "Ollama lets you run AI models locally (free & private)"
|
|
101
|
-
Write-Info "安装方法 / Install: winget install Ollama.Ollama"
|
|
102
|
-
Write-Info "或访问 / or visit: https://ollama.com/download"
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
# ── 完成 ──────────────────────────────────────────────────────
|
|
107
|
-
Write-Step "🎉 安装完成!/ Installation Complete!"
|
|
108
|
-
Write-Host ""
|
|
109
|
-
Write-Host "┌──────────────────────────────────────────────────────┐" -ForegroundColor Green
|
|
110
|
-
Write-Host "│ │" -ForegroundColor Green
|
|
111
|
-
Write-Host "│ 🎊 OPC Agent 已就绪!/ OPC Agent is ready! │" -ForegroundColor Green
|
|
112
|
-
Write-Host "│ │" -ForegroundColor Green
|
|
113
|
-
Write-Host "│ 快速开始 / Quick Start: │" -ForegroundColor Green
|
|
114
|
-
Write-Host "│ │" -ForegroundColor Green
|
|
115
|
-
Write-Host "│ opc chat 💬 开始对话 / Start chat │" -ForegroundColor Green
|
|
116
|
-
Write-Host "│ opc init my-agent 📁 创建新 Agent │" -ForegroundColor Green
|
|
117
|
-
Write-Host "│ opc studio 🖥️ 打开面板 / Dashboard │" -ForegroundColor Green
|
|
118
|
-
Write-Host "│ opc --help 📖 查看帮助 / Help │" -ForegroundColor Green
|
|
119
|
-
Write-Host "│ │" -ForegroundColor Green
|
|
120
|
-
Write-Host "│ 无需全局安装也可使用 / Without global install: │" -ForegroundColor Green
|
|
121
|
-
Write-Host "│ npx opc-agent chat │" -ForegroundColor Green
|
|
122
|
-
Write-Host "│ npx opc-agent init my-agent │" -ForegroundColor Green
|
|
123
|
-
Write-Host "│ │" -ForegroundColor Green
|
|
124
|
-
Write-Host "│ 文档 / Docs: https://github.com/Deepleaper/opc-agent│" -ForegroundColor Green
|
|
125
|
-
Write-Host "│ │" -ForegroundColor Green
|
|
126
|
-
Write-Host "└──────────────────────────────────────────────────────┘" -ForegroundColor Green
|
|
127
|
-
Write-Host ""
|
|
1
|
+
# ============================================================================
|
|
2
|
+
# OPC Agent 一键安装脚本 for Windows PowerShell
|
|
3
|
+
# 用法: irm https://raw.githubusercontent.com/Deepleaper/opc-agent/main/install.ps1 | iex
|
|
4
|
+
# 高级: $env:OPC_NO_OLLAMA='1'; irm ... | iex
|
|
5
|
+
# ============================================================================
|
|
6
|
+
|
|
7
|
+
$ErrorActionPreference = "Stop"
|
|
8
|
+
|
|
9
|
+
# ── 颜色输出 ──────────────────────────────────────────────────
|
|
10
|
+
function Write-Step($msg) { Write-Host "`n━━━ $msg ━━━" -ForegroundColor Blue }
|
|
11
|
+
function Write-Ok($msg) { Write-Host "✅ $msg" -ForegroundColor Green }
|
|
12
|
+
function Write-Warn($msg) { Write-Host "⚠️ $msg" -ForegroundColor Yellow }
|
|
13
|
+
function Write-Err($msg) { Write-Host "❌ $msg" -ForegroundColor Red }
|
|
14
|
+
function Write-Info($msg) { Write-Host "ℹ️ $msg" -ForegroundColor Cyan }
|
|
15
|
+
|
|
16
|
+
$SkipOllama = $env:OPC_NO_OLLAMA -eq '1'
|
|
17
|
+
|
|
18
|
+
# ── Banner ────────────────────────────────────────────────────
|
|
19
|
+
Write-Host ""
|
|
20
|
+
Write-Host " ___ ____ ____ _ _ " -ForegroundColor Cyan
|
|
21
|
+
Write-Host " / _ \| _ \/ ___| / \ __ _ ___ _ __ | |_ " -ForegroundColor Cyan
|
|
22
|
+
Write-Host " | | | | |_) \___ \ / _ \ / _`` |/ _ \ '_ \| __|" -ForegroundColor Cyan
|
|
23
|
+
Write-Host " | |_| | __/ ___) / ___ \ (_| | __/ | | | |_ " -ForegroundColor Cyan
|
|
24
|
+
Write-Host " \___/|_| |____/_/ \_\__, |\___|_| |_|\__|" -ForegroundColor Cyan
|
|
25
|
+
Write-Host " |___/ " -ForegroundColor Cyan
|
|
26
|
+
Write-Host ""
|
|
27
|
+
Write-Info "一键安装 OPC Agent / One-line installer for OPC Agent"
|
|
28
|
+
Write-Host ""
|
|
29
|
+
|
|
30
|
+
# ── 检测操作系统 ──────────────────────────────────────────────
|
|
31
|
+
Write-Step "🔍 检测操作系统 / Detecting OS"
|
|
32
|
+
Write-Ok "Windows $([System.Environment]::OSVersion.Version) detected"
|
|
33
|
+
|
|
34
|
+
# ── 检测 Node.js ─────────────────────────────────────────────
|
|
35
|
+
Write-Step "📦 检测 Node.js (>=18) / Checking Node.js"
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
$nodeVerFull = (node -v)
|
|
39
|
+
$nodeVerMajor = [int]($nodeVerFull -replace 'v','' -split '\.' | Select-Object -First 1)
|
|
40
|
+
if ($nodeVerMajor -ge 18) {
|
|
41
|
+
Write-Ok "Node.js $nodeVerFull ✓"
|
|
42
|
+
} else {
|
|
43
|
+
Write-Err "Node.js $nodeVerFull 版本过低 / version too old (need >=18)"
|
|
44
|
+
Write-Err "修复建议 / Fix: winget install OpenJS.NodeJS.LTS"
|
|
45
|
+
Write-Info "或访问 / or visit: https://nodejs.org/"
|
|
46
|
+
exit 1
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
Write-Err "未检测到 Node.js / Node.js not found"
|
|
50
|
+
Write-Err "修复建议 / Fix:"
|
|
51
|
+
Write-Info " winget install OpenJS.NodeJS.LTS"
|
|
52
|
+
Write-Info " # 或访问 / or visit: https://nodejs.org/"
|
|
53
|
+
exit 1
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# ── 检测 npm ─────────────────────────────────────────────────
|
|
57
|
+
try { npm --version | Out-Null } catch {
|
|
58
|
+
Write-Err "未检测到 npm / npm not found"
|
|
59
|
+
Write-Err "修复建议 / Fix: 重新安装 Node.js"
|
|
60
|
+
exit 1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# ── 安装 OPC Agent ────────────────────────────────────────────
|
|
64
|
+
Write-Step "🚀 安装 OPC Agent / Installing OPC Agent"
|
|
65
|
+
Write-Info "运行 npm install -g opc-agent ..."
|
|
66
|
+
npm install -g opc-agent
|
|
67
|
+
if ($LASTEXITCODE -ne 0) { Write-Err "安装失败 / Install failed"; exit 1 }
|
|
68
|
+
|
|
69
|
+
$opcVer = try { opc --version 2>$null } catch { "unknown" }
|
|
70
|
+
Write-Ok "OPC Agent v$opcVer 安装成功 / installed successfully"
|
|
71
|
+
|
|
72
|
+
# ── 初始化 ────────────────────────────────────────────────────
|
|
73
|
+
Write-Step "⚙️ 初始化 OPC Agent / Initializing"
|
|
74
|
+
Write-Info "运行 opc init --yes ..."
|
|
75
|
+
try { opc init --yes; Write-Ok "初始化完成 / initialized" } catch { Write-Warn "初始化跳过(可能已初始化)/ init skipped" }
|
|
76
|
+
|
|
77
|
+
# ── 进入项目目录后再检查 ──────────────────────────────────────
|
|
78
|
+
if (Test-Path "my-agent") {
|
|
79
|
+
Set-Location "my-agent"
|
|
80
|
+
Write-Info "已进入 my-agent/ 目录 / Entered my-agent/ directory"
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# ── 环境检查 ──────────────────────────────────────────────────
|
|
84
|
+
Write-Step "🩺 环境检查 / Running Doctor"
|
|
85
|
+
Write-Info "运行 opc doctor ..."
|
|
86
|
+
try { opc doctor } catch { Write-Warn "部分检查未通过,请查看上方输出 / Some checks failed" }
|
|
87
|
+
|
|
88
|
+
# ── Ollama(可选)─────────────────────────────────────────────
|
|
89
|
+
if (-not $SkipOllama) {
|
|
90
|
+
Write-Step "🦙 检测 Ollama (可选) / Checking Ollama (optional)"
|
|
91
|
+
|
|
92
|
+
$hasOllama = $false
|
|
93
|
+
try { ollama --version 2>$null | Out-Null; $hasOllama = $true } catch {}
|
|
94
|
+
|
|
95
|
+
if ($hasOllama) {
|
|
96
|
+
Write-Ok "Ollama 已安装 / installed ✓"
|
|
97
|
+
} else {
|
|
98
|
+
Write-Warn "未检测到 Ollama / Ollama not found"
|
|
99
|
+
Write-Info "Ollama 可让你在本地运行 AI 模型(免费、隐私安全)"
|
|
100
|
+
Write-Info "Ollama lets you run AI models locally (free & private)"
|
|
101
|
+
Write-Info "安装方法 / Install: winget install Ollama.Ollama"
|
|
102
|
+
Write-Info "或访问 / or visit: https://ollama.com/download"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# ── 完成 ──────────────────────────────────────────────────────
|
|
107
|
+
Write-Step "🎉 安装完成!/ Installation Complete!"
|
|
108
|
+
Write-Host ""
|
|
109
|
+
Write-Host "┌──────────────────────────────────────────────────────┐" -ForegroundColor Green
|
|
110
|
+
Write-Host "│ │" -ForegroundColor Green
|
|
111
|
+
Write-Host "│ 🎊 OPC Agent 已就绪!/ OPC Agent is ready! │" -ForegroundColor Green
|
|
112
|
+
Write-Host "│ │" -ForegroundColor Green
|
|
113
|
+
Write-Host "│ 快速开始 / Quick Start: │" -ForegroundColor Green
|
|
114
|
+
Write-Host "│ │" -ForegroundColor Green
|
|
115
|
+
Write-Host "│ opc chat 💬 开始对话 / Start chat │" -ForegroundColor Green
|
|
116
|
+
Write-Host "│ opc init my-agent 📁 创建新 Agent │" -ForegroundColor Green
|
|
117
|
+
Write-Host "│ opc studio 🖥️ 打开面板 / Dashboard │" -ForegroundColor Green
|
|
118
|
+
Write-Host "│ opc --help 📖 查看帮助 / Help │" -ForegroundColor Green
|
|
119
|
+
Write-Host "│ │" -ForegroundColor Green
|
|
120
|
+
Write-Host "│ 无需全局安装也可使用 / Without global install: │" -ForegroundColor Green
|
|
121
|
+
Write-Host "│ npx opc-agent chat │" -ForegroundColor Green
|
|
122
|
+
Write-Host "│ npx opc-agent init my-agent │" -ForegroundColor Green
|
|
123
|
+
Write-Host "│ │" -ForegroundColor Green
|
|
124
|
+
Write-Host "│ 文档 / Docs: https://github.com/Deepleaper/opc-agent│" -ForegroundColor Green
|
|
125
|
+
Write-Host "│ │" -ForegroundColor Green
|
|
126
|
+
Write-Host "└──────────────────────────────────────────────────────┘" -ForegroundColor Green
|
|
127
|
+
Write-Host ""
|