@tokentop/ttop 0.3.0 → 0.5.0

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.
Files changed (83) hide show
  1. package/package.json +9 -4
  2. package/src/agents/aggregator.ts +8 -1
  3. package/src/agents/types.ts +3 -0
  4. package/src/cli.ts +2 -2
  5. package/src/demo/simulator.ts +1 -1
  6. package/src/plugins/agents/index.ts +2 -0
  7. package/src/plugins/auth-sources.ts +2 -3
  8. package/src/plugins/lifecycle.ts +17 -13
  9. package/src/plugins/loader.test.ts +1 -1
  10. package/src/plugins/loader.ts +15 -7
  11. package/src/plugins/notification-bus.ts +5 -2
  12. package/src/plugins/notifications/terminal-bell.ts +9 -2
  13. package/src/plugins/notifications/visual-flash.ts +13 -3
  14. package/src/plugins/plugin-context-factory.ts +4 -19
  15. package/src/plugins/providers/anthropic.ts +2 -2
  16. package/src/plugins/providers/antigravity.ts +1 -1
  17. package/src/plugins/providers/chutes.ts +189 -0
  18. package/src/plugins/providers/codex.ts +1 -1
  19. package/src/plugins/providers/gemini.ts +1 -1
  20. package/src/plugins/providers/github-copilot.ts +1 -1
  21. package/src/plugins/providers/index.ts +1 -0
  22. package/src/plugins/providers/minimax.ts +1 -1
  23. package/src/plugins/providers/openai-api.ts +1 -1
  24. package/src/plugins/providers/opencode-zen.ts +1 -1
  25. package/src/plugins/providers/perplexity.ts +1 -1
  26. package/src/plugins/providers/zai.ts +4 -2
  27. package/src/plugins/registry.ts +51 -46
  28. package/src/plugins/sandbox-guard.test.ts +1 -1
  29. package/src/plugins/sandbox-guard.ts +1 -1
  30. package/src/plugins/sandbox.ts +1 -1
  31. package/src/plugins/themes/catppuccin-latte.ts +1 -1
  32. package/src/plugins/themes/catppuccin-mocha.ts +1 -1
  33. package/src/plugins/themes/claude-code.ts +1 -1
  34. package/src/plugins/themes/dracula.ts +1 -1
  35. package/src/plugins/themes/github-light.ts +1 -1
  36. package/src/plugins/themes/gruvbox-dark.ts +1 -1
  37. package/src/plugins/themes/gruvbox-light.ts +1 -1
  38. package/src/plugins/themes/kanagawa.ts +1 -1
  39. package/src/plugins/themes/nord.ts +1 -1
  40. package/src/plugins/themes/one-dark.ts +1 -1
  41. package/src/plugins/themes/opencode.ts +1 -1
  42. package/src/plugins/themes/rose-pine-dawn.ts +1 -1
  43. package/src/plugins/themes/rose-pine.ts +1 -1
  44. package/src/plugins/themes/solarized-light.ts +1 -1
  45. package/src/plugins/themes/tokyo-night.ts +1 -1
  46. package/src/plugins/update-checker.ts +2 -2
  47. package/src/pricing/estimator.test.ts +1 -1
  48. package/src/pricing/estimator.ts +1 -1
  49. package/src/pricing/fallback.ts +1 -1
  50. package/src/pricing/index.ts +1 -1
  51. package/src/pricing/models-dev.ts +1 -1
  52. package/src/storage/index.ts +6 -0
  53. package/src/storage/migrations/index.ts +17 -0
  54. package/src/storage/persistence-service.ts +206 -0
  55. package/src/storage/repos/pluginStorage.ts +35 -0
  56. package/src/storage/retention.ts +146 -0
  57. package/src/tui/App.tsx +1 -1
  58. package/src/tui/components/DebugPanel.tsx +23 -10
  59. package/src/tui/components/ProviderCard.tsx +1 -1
  60. package/src/tui/components/ProviderDetailPanel.tsx +1 -1
  61. package/src/tui/components/SessionDetailsDrawer.tsx +10 -0
  62. package/src/tui/components/SessionsTable.tsx +15 -4
  63. package/src/tui/components/SettingsModal.tsx +383 -76
  64. package/src/tui/components/ThemePicker.tsx +1 -1
  65. package/src/tui/contexts/AgentSessionContext.tsx +44 -80
  66. package/src/tui/contexts/PluginContext.tsx +13 -3
  67. package/src/tui/contexts/RealTimeActivityContext.tsx +33 -20
  68. package/src/tui/contexts/StorageContext.tsx +42 -130
  69. package/src/tui/contexts/ThemeContext.tsx +3 -3
  70. package/src/tui/hooks/useExitAnimation.ts +4 -0
  71. package/src/tui/hooks/useSessionEnrichedProviders.ts +1 -1
  72. package/src/tui/views/Dashboard.tsx +40 -3
  73. package/src/tui/views/ProjectsView.tsx +29 -6
  74. package/src/tui/views/RealTimeDashboard.tsx +29 -8
  75. package/src/tui/views/SettingsView.tsx +9 -4
  76. package/src/version.ts +1 -1
  77. package/src/plugins/types/agent.ts +0 -108
  78. package/src/plugins/types/base.ts +0 -278
  79. package/src/plugins/types/index.ts +0 -19
  80. package/src/plugins/types/notification.ts +0 -51
  81. package/src/plugins/types/provider.ts +0 -237
  82. package/src/plugins/types/theme.ts +0 -78
  83. package/src/storage/database.ts +0 -623
@@ -1,237 +0,0 @@
1
- import type { BasePlugin, PluginHttpClient, PluginLogger } from "./base.ts";
2
-
3
- export interface ProviderCapabilities {
4
- usageLimits: boolean;
5
- apiRateLimits: boolean;
6
- tokenUsage: boolean;
7
- actualCosts: boolean;
8
- }
9
-
10
- // ---------------------------------------------------------------------------
11
- // Credential types
12
- // ---------------------------------------------------------------------------
13
-
14
- export interface Credentials {
15
- apiKey?: string;
16
- oauth?: OAuthCredentials;
17
- groupId?: string;
18
- source: "env" | "opencode" | "external" | "config";
19
- }
20
-
21
- export interface OAuthCredentials {
22
- accessToken: string;
23
- refreshToken?: string;
24
- expiresAt?: number;
25
- accountId?: string;
26
- managedProjectId?: string;
27
- }
28
-
29
- export interface RefreshedCredentials {
30
- accessToken: string;
31
- refreshToken: string;
32
- expiresAt: number;
33
- }
34
-
35
- // ---------------------------------------------------------------------------
36
- // Auth (plugin-owned discovery)
37
- // ---------------------------------------------------------------------------
38
-
39
- /** Result of a credential discovery attempt. */
40
- export interface CredentialResult {
41
- ok: boolean;
42
- credentials?: Credentials;
43
- reason?: "missing" | "expired" | "invalid" | "error";
44
- message?: string;
45
- }
46
-
47
- /**
48
- * Shape of an entry in OpenCode's auth.json file.
49
- * Used by AuthSources.opencode.getProviderEntry().
50
- */
51
- export interface OpenCodeAuthEntry {
52
- type: "api" | "oauth" | "codex" | "github" | "wellknown";
53
- key?: string;
54
- access?: string;
55
- refresh?: string;
56
- expires?: number;
57
- token?: string;
58
- accessToken?: string;
59
- refreshToken?: string;
60
- expiresAt?: number;
61
- accountId?: string;
62
- groupId?: string;
63
- }
64
-
65
- /**
66
- * Sandboxed auth source helpers injected into plugins.
67
- * All methods respect the plugin's declared permissions.
68
- */
69
- export interface AuthSources {
70
- /** Read an environment variable (sandboxed to `permissions.env.vars`). */
71
- env: {
72
- get(name: string): string | undefined;
73
- };
74
-
75
- /** Read files from the filesystem (sandboxed to `permissions.filesystem.paths`). */
76
- files: {
77
- readText(path: string): Promise<string | null>;
78
- readJson<T = unknown>(path: string): Promise<T | null>;
79
- exists(path: string): Promise<boolean>;
80
- };
81
-
82
- /**
83
- * Read from OpenCode's auth storage.
84
- * Core handles locating the auth file; plugin provides the provider key.
85
- */
86
- opencode: {
87
- getProviderEntry(key: string): Promise<OpenCodeAuthEntry | null>;
88
- };
89
-
90
- /** Platform information for cross-platform credential path resolution. */
91
- platform: {
92
- os: "darwin" | "linux" | "win32";
93
- homedir: string;
94
- arch: string;
95
- };
96
- }
97
-
98
- /** Per-plugin key-value storage (namespaced by plugin ID). */
99
- export interface PluginStorage {
100
- get(key: string): Promise<string | null>;
101
- set(key: string, value: string): Promise<void>;
102
- delete(key: string): Promise<void>;
103
- has(key: string): Promise<boolean>;
104
- }
105
-
106
- /** Full runtime context provided to plugin methods like `auth.discover()`. */
107
- export interface PluginContext {
108
- /** Plugin's validated configuration values. */
109
- readonly config: Record<string, unknown>;
110
- /** Scoped logger. */
111
- readonly logger: PluginLogger;
112
- /** Sandboxed HTTP client. */
113
- readonly http: PluginHttpClient;
114
- /** Credential discovery helpers. */
115
- readonly authSources: AuthSources;
116
- /** Per-plugin persistent key-value storage. */
117
- readonly storage: PluginStorage;
118
- /** Abort signal — fired when the plugin is being stopped or the app is shutting down. */
119
- readonly signal: AbortSignal;
120
- }
121
-
122
- export interface ProviderAuth {
123
- /** Discover credentials using the provided context helpers. */
124
- discover(ctx: PluginContext): Promise<CredentialResult>;
125
- /** Check whether discovered credentials are sufficient to operate. */
126
- isConfigured(credentials: Credentials): boolean;
127
- }
128
-
129
- // ---------------------------------------------------------------------------
130
- // Pricing
131
- // ---------------------------------------------------------------------------
132
-
133
- export interface ModelPricing {
134
- input: number;
135
- output: number;
136
- cacheRead?: number;
137
- cacheWrite?: number;
138
- source?: string;
139
- }
140
-
141
- /** Pricing configuration for a provider's models. */
142
- export interface ProviderPricing {
143
- /**
144
- * Map a model ID to the identifier used by the pricing service.
145
- * Return `undefined` to use the model ID as-is.
146
- */
147
- mapModelId?(modelId: string): string | undefined;
148
- /**
149
- * The provider ID to use when querying models.dev.
150
- * Defaults to `plugin.id` if not specified.
151
- */
152
- modelsDevProviderId?: string;
153
- /** Static fallback prices keyed by model ID. */
154
- staticPrices?: Record<string, ModelPricing>;
155
- }
156
-
157
- // ---------------------------------------------------------------------------
158
- // Usage data
159
- // ---------------------------------------------------------------------------
160
-
161
- export interface UsageLimit {
162
- usedPercent: number | null;
163
- resetsAt?: number;
164
- label?: string;
165
- windowMinutes?: number;
166
- }
167
-
168
- export interface CostBreakdown {
169
- total: number;
170
- input?: number;
171
- output?: number;
172
- cacheRead?: number;
173
- cacheWrite?: number;
174
- currency: string;
175
- }
176
-
177
- export interface ProviderUsageData {
178
- planType?: string;
179
- allowed?: boolean;
180
- limitReached?: boolean;
181
- limits?: {
182
- primary?: UsageLimit;
183
- secondary?: UsageLimit;
184
- items?: UsageLimit[];
185
- };
186
- tokens?: {
187
- input: number;
188
- output: number;
189
- cacheRead?: number;
190
- cacheWrite?: number;
191
- };
192
- credits?: {
193
- hasCredits: boolean;
194
- unlimited: boolean;
195
- balance?: string;
196
- };
197
- cost?: {
198
- actual?: CostBreakdown;
199
- estimated?: CostBreakdown;
200
- /** Session-derived daily cost (today only). Set by enrichment hook. */
201
- estimatedDaily?: CostBreakdown;
202
- /** Session-derived monthly cost (MTD). Set by enrichment hook. */
203
- estimatedMonthly?: CostBreakdown;
204
- source: "api" | "estimated";
205
- };
206
- fetchedAt: number;
207
- error?: string;
208
- }
209
-
210
- // ---------------------------------------------------------------------------
211
- // Fetch context
212
- // ---------------------------------------------------------------------------
213
-
214
- export interface ProviderFetchContext {
215
- readonly credentials: Credentials;
216
- readonly http: PluginHttpClient;
217
- readonly logger: PluginLogger;
218
- readonly config: Record<string, unknown>;
219
- readonly signal: AbortSignal;
220
- readonly options?: {
221
- timePeriod?: "session" | "daily" | "weekly" | "monthly";
222
- sessionId?: string;
223
- };
224
- }
225
-
226
- // ---------------------------------------------------------------------------
227
- // Provider Plugin
228
- // ---------------------------------------------------------------------------
229
-
230
- export interface ProviderPlugin extends BasePlugin {
231
- readonly type: "provider";
232
- readonly capabilities: ProviderCapabilities;
233
- readonly auth: ProviderAuth;
234
- readonly pricing?: ProviderPricing;
235
- fetchUsage(ctx: ProviderFetchContext): Promise<ProviderUsageData>;
236
- refreshToken?(auth: OAuthCredentials): Promise<RefreshedCredentials>;
237
- }
@@ -1,78 +0,0 @@
1
- import { z } from "zod";
2
- import type { BasePlugin } from "./base.ts";
3
-
4
- export const ThemeColorsSchema = z.object({
5
- background: z.string(),
6
- foreground: z.string(),
7
- text: z.string(),
8
- textMuted: z.string(),
9
- textSubtle: z.string(),
10
- primary: z.string(),
11
- secondary: z.string(),
12
- accent: z.string(),
13
- success: z.string(),
14
- warning: z.string(),
15
- error: z.string(),
16
- info: z.string(),
17
- border: z.string(),
18
- borderMuted: z.string(),
19
- selection: z.string(),
20
- highlight: z.string(),
21
- gaugeBackground: z.string(),
22
- gaugeFill: z.string(),
23
- gaugeWarning: z.string(),
24
- gaugeDanger: z.string(),
25
- });
26
-
27
- export type ThemeColors = z.infer<typeof ThemeColorsSchema>;
28
-
29
- export const ThemeComponentsSchema = z.object({
30
- header: z
31
- .object({
32
- background: z.string().optional(),
33
- foreground: z.string().optional(),
34
- titleColor: z.string().optional(),
35
- titleAccentColor: z.string().optional(),
36
- })
37
- .optional(),
38
- statusBar: z
39
- .object({
40
- background: z.string().optional(),
41
- foreground: z.string().optional(),
42
- })
43
- .optional(),
44
- commandPalette: z
45
- .object({
46
- background: z.string().optional(),
47
- border: z.string().optional(),
48
- })
49
- .optional(),
50
- gauge: z
51
- .object({
52
- height: z.number().optional(),
53
- borderRadius: z.number().optional(),
54
- })
55
- .optional(),
56
- });
57
-
58
- export type ThemeComponents = z.infer<typeof ThemeComponentsSchema>;
59
-
60
- export type ColorScheme = "light" | "dark";
61
-
62
- export type ColorSchemePreference = "auto" | "light" | "dark";
63
-
64
- export interface ThemePlugin extends BasePlugin {
65
- readonly type: "theme";
66
- readonly family: string;
67
- readonly colorScheme: ColorScheme;
68
- readonly colors: ThemeColors;
69
- readonly components?: ThemeComponents;
70
- }
71
-
72
- export interface ResolvedTheme {
73
- id: string;
74
- name: string;
75
- colorScheme: ColorScheme;
76
- colors: ThemeColors;
77
- components: ThemeComponents;
78
- }