-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcopilot.js
More file actions
61 lines (56 loc) · 2.05 KB
/
Copy pathcopilot.js
File metadata and controls
61 lines (56 loc) · 2.05 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
/**
* Agent Wallet hub — Copilot tab (trading-frontier task 01).
*
* The Conversational Trading Copilot: the owner talks (text or voice) to the
* agent and it answers with REAL live data and proposes guarded trades to
* confirm. All logic lives in src/agent-copilot.js (reusable so agent-detail can
* mount the same copilot); this tab is the thin wallet-hub wrapper that wires it
* to the shared hub context (agent id, owner flag, network, toast).
*
* Owner-only: the copilot reads this wallet's positions and can place guarded
* trades from it, so a visitor never sees it.
*/
import { registerWalletTab } from '../registry.js';
import { mountTradingCopilot } from '../../agent-copilot.js';
registerWalletTab({
id: 'copilot',
label: 'Copilot',
order: 25, // sits beside Trade (30) — talk, or trade by hand
ownerOnly: true,
mount({ panel, ctx }) {
let handle = null;
let destroyed = false;
// The copilot renders its own loading/streaming/error states internally. This
// wrapper only guards the mount itself: if it throws (bad import, DOM error),
// degrade to a designed, retryable card instead of a blank or broken panel.
function boot() {
try {
handle = mountTradingCopilot({
panel,
agentId: ctx.agentId,
agentName: ctx.agent?.name || 'Copilot',
isOwner: ctx.isOwner,
getNetwork: ctx.getNetwork,
onNetworkChange: ctx.onNetworkChange,
toast: ctx.toast,
});
} catch (err) {
console.error('[agent-wallet-hub] copilot failed to mount', err);
handle = null;
panel.innerHTML = `<div class="awh-card"><p class="awh-empty" role="alert">The trading copilot couldn’t start. <button class="awh-btn" type="button" data-act="retry">Retry</button></p></div>`;
panel.querySelector('[data-act="retry"]')?.addEventListener('click', () => {
if (!destroyed) boot();
});
}
}
boot();
return {
onShow() { handle?.onShow?.(); },
onHide() { handle?.onHide?.(); },
destroy() {
destroyed = true;
try { handle?.destroy?.(); } catch { /* teardown best-effort */ }
},
};
},
});