-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
135 lines (112 loc) · 6.96 KB
/
Copy pathmain.js
File metadata and controls
135 lines (112 loc) · 6.96 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
/**
* OpenAutoGrowth — Main Entry Point
*
* Responsibilities:
* 1. Boot the multi-agent system (Memory, EventBus, Orchestrator, Agents)
* 2. Expose system references on window.OAG for page modules
* 3. Register routes and start the AppShell + Router
*
* UI controllers now live in src/ui/pages/*.js (see docs/frontend/).
*/
// ── Core support layer ────────────────────────────────────────────
import { Memory, ToolRegistry } from './src/core/Memory.js';
import { globalEventBus } from './src/core/EventBus.js';
import { RuleEngine } from './src/core/RuleEngine.js';
// ── Intelligence layer ────────────────────────────────────────────
import { Orchestrator } from './src/agents/Orchestrator.js';
import { Planner } from './src/agents/Planner.js';
// ── Execution agents ──────────────────────────────────────────────
import { ContentGenAgent } from './src/agents/ContentGen.js';
import { MultimodalAgent } from './src/agents/Multimodal.js';
import { StrategyAgent } from './src/agents/Strategy.js';
import { ChannelExecAgent } from './src/agents/ChannelExec.js';
// ── Feedback agents ───────────────────────────────────────────────
import { AnalysisAgent } from './src/agents/Analysis.js';
import { OptimizerAgent } from './src/agents/Optimizer.js';
// ── API layer ─────────────────────────────────────────────────────
import { CampaignAPI } from './src/api/routes.js';
import { wsBroadcaster } from './src/api/websocket.js';
import { auth, ensureLoggedIn } from './src/ui/auth.js';
// ── i18n ──────────────────────────────────────────────────────────
import { i18n } from './src/i18n/index.js';
// ── UI shell + router ─────────────────────────────────────────────
import './src/ui/components.css';
import { router } from './src/ui/router.js';
import { AppShell } from './src/ui/shell.js';
import * as tour from './src/ui/onboarding.js';
// ══════════════════════════════════════════════════════════════════
// SYSTEM BOOTSTRAP
// ══════════════════════════════════════════════════════════════════
const memory = new Memory();
const toolRegistry = new ToolRegistry();
const ruleEngine = new RuleEngine();
const planner = new Planner();
const orchestrator = new Orchestrator({ planner, memory, ruleEngine });
orchestrator.registerAgent('Strategy', new StrategyAgent());
orchestrator.registerAgent('ContentGen', new ContentGenAgent());
orchestrator.registerAgent('Multimodal', new MultimodalAgent());
orchestrator.registerAgent('ChannelExec', new ChannelExecAgent());
orchestrator.registerAgent('Analysis', new AnalysisAgent());
orchestrator.registerAgent('Optimizer', new OptimizerAgent());
const api = new CampaignAPI({ orchestrator, memory });
// Expose refs for page modules (they read from window.OAG, avoiding
// circular imports between bootstrap and leaf pages).
window.OAG = {
api,
orchestrator,
memory,
ruleEngine,
eventBus: globalEventBus,
wsBroadcaster,
i18n,
auth,
};
console.log('[System] OpenAutoGrowth initialized — 8 agents online.');
// ══════════════════════════════════════════════════════════════════
// ROUTER + SHELL
// ══════════════════════════════════════════════════════════════════
document.addEventListener('DOMContentLoaded', () => {
const outlet = document.getElementById('app-outlet');
if (!outlet) {
console.error('[main] #app-outlet missing in index.html');
return;
}
router.setOutlet(outlet);
// Dedicated agent pages must register BEFORE the generic /agents/:id
// placeholder so their concrete patterns win the match.
router
.register('/', () => import('./src/ui/pages/hub.js'))
.register('/campaigns', () => import('./src/ui/pages/campaigns.js'))
.register('/campaigns/:id', () => import('./src/ui/pages/campaign-detail.js'))
.register('/integrations', () => import('./src/ui/pages/integrations.js'))
.register('/integrations/:platform', () => import('./src/ui/pages/integration-manage.js'))
.register('/agents/content-gen', () => import('./src/ui/pages/agent-content-gen.js'))
.register('/agents/optimizer', () => import('./src/ui/pages/agent-optimizer.js'))
.register('/agents/planner', () => import('./src/ui/pages/agent-planner.js'))
.register('/agents/analysis', () => import('./src/ui/pages/agent-analysis.js'))
.register('/agents/strategy', () => import('./src/ui/pages/agent-strategy.js'))
.register('/agents/channel-exec', () => import('./src/ui/pages/agent-channel-exec.js'))
.register('/agents/multimodal', () => import('./src/ui/pages/agent-multimodal.js'))
.register('/agents/orchestrator', () => import('./src/ui/pages/agent-orchestrator.js'))
.register('/users', () => import('./src/ui/pages/users.js'))
.register('/agents/:id', () => import('./src/ui/pages/agent-placeholder.js'))
.register('/governance', () => import('./src/ui/pages/governance.js'))
.setFallback('/');
const shell = new AppShell();
shell.mount();
router.start();
i18n.updateUI();
// Phase 1A: require login before the user can interact with anything
// that hits a protected endpoint. The modal blocks the UI; the rest of
// the app stays mounted underneath so reload-without-token doesn't
// wipe page state. 401s from any later request also auto-open it.
if (!auth.isLoggedIn()) {
ensureLoggedIn(api);
}
// First-time onboarding tour. Reads `localStorage.oag_tour_state` —
// if not 'completed' or 'skipped', prompts the user. Manual replay
// available via the Hub's "Replay tour" link → window.OAG.tour.reset().
window.OAG = window.OAG || {};
window.OAG.tour = tour;
tour.maybeAutoStart();
});