opencode-account-manager 0.4.4 → 0.5.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.
@@ -0,0 +1,120 @@
1
+ import React, { useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+
4
+ export interface PaletteAction {
5
+ id: string;
6
+ label: string;
7
+ shortcut?: string;
8
+ description?: string;
9
+ category?: string;
10
+ }
11
+
12
+ interface ActionPaletteProps {
13
+ actions: PaletteAction[];
14
+ onSelect: (actionId: string) => void;
15
+ onClose: () => void;
16
+ }
17
+
18
+ export function ActionPalette({ actions, onSelect, onClose }: ActionPaletteProps) {
19
+ const [search, setSearch] = useState("");
20
+ const [selectedIndex, setSelectedIndex] = useState(0);
21
+
22
+ // Filter actions by search
23
+ const filteredActions = actions.filter(action => {
24
+ const searchLower = search.toLowerCase();
25
+ return (
26
+ action.label.toLowerCase().includes(searchLower) ||
27
+ action.id.toLowerCase().includes(searchLower) ||
28
+ (action.description?.toLowerCase().includes(searchLower))
29
+ );
30
+ });
31
+
32
+ useInput((input, key) => {
33
+ // Close on Escape
34
+ if (key.escape) {
35
+ onClose();
36
+ return;
37
+ }
38
+
39
+ // Navigate up
40
+ if (key.upArrow) {
41
+ setSelectedIndex(prev => Math.max(0, prev - 1));
42
+ return;
43
+ }
44
+
45
+ // Navigate down
46
+ if (key.downArrow) {
47
+ setSelectedIndex(prev => Math.min(filteredActions.length - 1, prev + 1));
48
+ return;
49
+ }
50
+
51
+ // Select on Enter
52
+ if (key.return) {
53
+ const action = filteredActions[selectedIndex];
54
+ if (action) {
55
+ onSelect(action.id);
56
+ }
57
+ return;
58
+ }
59
+
60
+ // Backspace
61
+ if (key.backspace || key.delete) {
62
+ setSearch(prev => prev.slice(0, -1));
63
+ setSelectedIndex(0);
64
+ return;
65
+ }
66
+
67
+ // Type to search (printable characters)
68
+ if (input && input.length === 1 && !key.ctrl && !key.meta) {
69
+ setSearch(prev => prev + input);
70
+ setSelectedIndex(0);
71
+ }
72
+ });
73
+
74
+ return (
75
+ <Box
76
+ flexDirection="column"
77
+ borderStyle="round"
78
+ borderColor="cyan"
79
+ paddingX={1}
80
+ paddingY={0}
81
+ >
82
+ {/* Search input */}
83
+ <Box marginBottom={1}>
84
+ <Text color="cyan" bold>{">"} </Text>
85
+ <Text>{search}</Text>
86
+ <Text color="gray">_</Text>
87
+ </Box>
88
+
89
+ {/* Actions list */}
90
+ <Box flexDirection="column" marginBottom={1}>
91
+ {filteredActions.length === 0 ? (
92
+ <Text dimColor>No matching actions</Text>
93
+ ) : (
94
+ filteredActions.slice(0, 10).map((action, index) => {
95
+ const isSelected = index === selectedIndex;
96
+ return (
97
+ <Box key={action.id}>
98
+ <Text
99
+ backgroundColor={isSelected ? "cyan" : undefined}
100
+ color={isSelected ? "black" : "white"}
101
+ >
102
+ {isSelected ? "▸ " : " "}
103
+ {action.label}
104
+ </Text>
105
+ {action.shortcut && (
106
+ <Text dimColor> [{action.shortcut}]</Text>
107
+ )}
108
+ </Box>
109
+ );
110
+ })
111
+ )}
112
+ </Box>
113
+
114
+ {/* Help */}
115
+ <Box>
116
+ <Text dimColor>↑↓ navigate • Enter select • Esc close</Text>
117
+ </Box>
118
+ </Box>
119
+ );
120
+ }
@@ -0,0 +1,170 @@
1
+ import React from "react";
2
+ import { Box, Text } from "ink";
3
+ import { Account } from "../../core/types";
4
+
5
+ interface DashboardViewProps {
6
+ accounts: Account[];
7
+ selectedIndex: number;
8
+ }
9
+
10
+ // Model families for rate limit display
11
+ const MODEL_FAMILIES = ["claude", "gemini", "gpt", "deepseek", "o1", "o3"];
12
+
13
+ function formatTimeRemaining(resetTime: number): string {
14
+ const now = Date.now();
15
+ if (resetTime <= now) return "";
16
+
17
+ const remaining = resetTime - now;
18
+ const hours = Math.floor(remaining / 3600000);
19
+ const minutes = Math.floor((remaining % 3600000) / 60000);
20
+
21
+ if (hours > 0) {
22
+ return `${hours}h ${minutes}m`;
23
+ }
24
+ return `${minutes}m`;
25
+ }
26
+
27
+ function getAccountStatus(account: Account): { status: string; color: string } {
28
+ if (!account.enabled) {
29
+ return { status: "DISABLED", color: "gray" };
30
+ }
31
+
32
+ const now = Date.now();
33
+ const rateLimits = account.rateLimitResetTimes || {};
34
+ const limitedModels = Object.entries(rateLimits)
35
+ .filter(([_, time]) => time > now);
36
+
37
+ if (limitedModels.length === 0) {
38
+ return { status: "AVAILABLE", color: "green" };
39
+ }
40
+
41
+ return { status: "LIMITED", color: "yellow" };
42
+ }
43
+
44
+ function getRateLimitBar(account: Account, model: string): { bar: string; color: string; time: string } {
45
+ const now = Date.now();
46
+ const resetTime = account.rateLimitResetTimes?.[model] || 0;
47
+
48
+ if (resetTime <= now) {
49
+ return { bar: "████████", color: "green", time: "" };
50
+ }
51
+
52
+ // Calculate remaining time as percentage (assume 24h max)
53
+ const remaining = resetTime - now;
54
+ const maxTime = 24 * 3600000; // 24 hours
55
+ const percentage = Math.min(1, remaining / maxTime);
56
+ const filledBlocks = Math.round((1 - percentage) * 8);
57
+ const emptyBlocks = 8 - filledBlocks;
58
+
59
+ return {
60
+ bar: "█".repeat(filledBlocks) + "░".repeat(emptyBlocks),
61
+ color: percentage > 0.5 ? "red" : "yellow",
62
+ time: formatTimeRemaining(resetTime),
63
+ };
64
+ }
65
+
66
+ export function DashboardView({ accounts, selectedIndex }: DashboardViewProps) {
67
+ if (accounts.length === 0) {
68
+ return (
69
+ <Box flexDirection="column" padding={1}>
70
+ <Text dimColor>No accounts found. Press P to open actions and import accounts.</Text>
71
+ </Box>
72
+ );
73
+ }
74
+
75
+ // Get all unique models from accounts
76
+ const allModels = new Set<string>();
77
+ accounts.forEach(acc => {
78
+ if (acc.rateLimitResetTimes) {
79
+ Object.keys(acc.rateLimitResetTimes).forEach(m => allModels.add(m));
80
+ }
81
+ });
82
+
83
+ // Use predefined families or detected models
84
+ const displayModels = MODEL_FAMILIES.filter(m =>
85
+ accounts.some(acc => acc.rateLimitResetTimes?.[m])
86
+ );
87
+
88
+ if (displayModels.length === 0) {
89
+ displayModels.push("claude", "gemini"); // Default columns
90
+ }
91
+
92
+ return (
93
+ <Box flexDirection="column">
94
+ {/* Header row */}
95
+ <Box>
96
+ <Box width={30}>
97
+ <Text bold color="cyan">ACCOUNT</Text>
98
+ </Box>
99
+ <Box width={12}>
100
+ <Text bold color="cyan">STATUS</Text>
101
+ </Box>
102
+ {displayModels.map(model => (
103
+ <Box key={model} width={14}>
104
+ <Text bold color="cyan">{model.toUpperCase()}</Text>
105
+ </Box>
106
+ ))}
107
+ </Box>
108
+
109
+ {/* Separator */}
110
+ <Box>
111
+ <Text dimColor>{"─".repeat(30 + 12 + displayModels.length * 14)}</Text>
112
+ </Box>
113
+
114
+ {/* Account rows */}
115
+ {accounts.map((account, index) => {
116
+ const isSelected = index === selectedIndex;
117
+ const { status, color } = getAccountStatus(account);
118
+
119
+ // Truncate email
120
+ const emailDisplay = account.email.length > 28
121
+ ? account.email.slice(0, 25) + "..."
122
+ : account.email;
123
+
124
+ return (
125
+ <Box key={account.email}>
126
+ {/* Selection indicator */}
127
+ <Text color={isSelected ? "cyan" : undefined}>
128
+ {isSelected ? "▸ " : " "}
129
+ </Text>
130
+
131
+ {/* Email */}
132
+ <Box width={28}>
133
+ <Text
134
+ color={isSelected ? "cyan" : (account.enabled === false ? "gray" : "white")}
135
+ bold={isSelected}
136
+ >
137
+ {emailDisplay}
138
+ </Text>
139
+ </Box>
140
+
141
+ {/* Status */}
142
+ <Box width={12}>
143
+ <Text color={color}>{status}</Text>
144
+ </Box>
145
+
146
+ {/* Rate limit bars for each model */}
147
+ {displayModels.map(model => {
148
+ const { bar, color: barColor, time } = getRateLimitBar(account, model);
149
+ return (
150
+ <Box key={model} width={14}>
151
+ <Text color={barColor}>{bar}</Text>
152
+ {time && <Text dimColor> {time}</Text>}
153
+ </Box>
154
+ );
155
+ })}
156
+ </Box>
157
+ );
158
+ })}
159
+
160
+ {/* Legend */}
161
+ <Box marginTop={1}>
162
+ <Text dimColor>
163
+ <Text color="green">████</Text> Available
164
+ <Text color="yellow">░░░░</Text> Limited
165
+ <Text color="gray">████</Text> Disabled
166
+ </Text>
167
+ </Box>
168
+ </Box>
169
+ );
170
+ }
@@ -11,3 +11,5 @@ export { PasswordInput } from "./PasswordInput";
11
11
  export { FileBrowser } from "./FileBrowser";
12
12
  export { ExportModal } from "./ExportModal";
13
13
  export { ImportModal } from "./ImportModal";
14
+ export { ActionPalette, PaletteAction } from "./ActionPalette";
15
+ export { DashboardView } from "./DashboardView";