@kapybara/zerosub 1.5.0 → 1.18.2

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 (56) hide show
  1. package/README.md +222 -27
  2. package/client/accounts-surface.tsx +344 -110
  3. package/client/add-account.tsx +335 -23
  4. package/client/api-account.tsx +250 -0
  5. package/client/azure-account.tsx +311 -0
  6. package/client/commands.ts +44 -8
  7. package/client/composer-item.tsx +203 -0
  8. package/client/fork-confirm.tsx +71 -0
  9. package/client/fork-settings.tsx +148 -0
  10. package/client/pace.tsx +196 -0
  11. package/client/pi-accounts.tsx +571 -0
  12. package/client/pills.ts +63 -25
  13. package/client/reset-confirm.tsx +12 -3
  14. package/client/settings-screen.tsx +48 -9
  15. package/client/store.ts +148 -19
  16. package/client/switch-row.tsx +28 -8
  17. package/client/ui.tsx +11 -0
  18. package/index.client.tsx +4 -1
  19. package/index.server.ts +53 -10
  20. package/package.json +5 -2
  21. package/server/account-identity.ts +11 -0
  22. package/server/adapter.ts +115 -8
  23. package/server/api-usage.ts +144 -0
  24. package/server/azure.ts +346 -0
  25. package/server/binaries.ts +41 -3
  26. package/server/claude.ts +276 -21
  27. package/server/codex-same-conversation.ts +71 -0
  28. package/server/codex.ts +35 -7
  29. package/server/continuations.ts +128 -18
  30. package/server/cursor.ts +222 -0
  31. package/server/families.ts +105 -8
  32. package/server/grok.ts +225 -0
  33. package/server/handoff.ts +221 -30
  34. package/server/homes.ts +1263 -35
  35. package/server/json-file.ts +39 -8
  36. package/server/launchers.ts +319 -0
  37. package/server/limits.ts +80 -3
  38. package/server/main-proxy.ts +238 -0
  39. package/server/modes.ts +20 -4
  40. package/server/paths.ts +81 -1
  41. package/server/pi.ts +528 -0
  42. package/server/placement.ts +133 -0
  43. package/server/process.ts +18 -1
  44. package/server/processes.ts +66 -0
  45. package/server/provider-env.ts +28 -0
  46. package/server/proxy.ts +282 -0
  47. package/server/reopen.ts +50 -8
  48. package/server/routing.ts +337 -30
  49. package/server/service.ts +4320 -803
  50. package/server/state.ts +305 -24
  51. package/server/usage.ts +2 -0
  52. package/shared/format.ts +170 -2
  53. package/shared/model.ts +339 -2
  54. package/shared/preferences.ts +22 -1
  55. package/shared/rpc.ts +130 -8
  56. package/shared/timeline.ts +11 -0
@@ -0,0 +1,250 @@
1
+ import type { PluginSurfaceProps } from "@getpaseo/plugin/client";
2
+ import { Modal, TextInput, useToast } from "@getpaseo/plugin/client/react-native";
3
+ import { SettingsCard, SettingsSelect, SettingsSwitch } from "@getpaseo/plugin/client/ui";
4
+ import { useCallback, useMemo, useState, type ReactNode } from "react";
5
+ import { Text, View } from "react-native";
6
+ import type { AccountView, ApiKeyKind, TrafficSwitches } from "../shared/model";
7
+ import { addApiAccount, updateApiAccount } from "../shared/rpc";
8
+ import { describe, type ZeroSubStore } from "./store";
9
+ import { Button, useText } from "./ui";
10
+
11
+ type Theme = PluginSurfaceProps["theme"];
12
+
13
+ const KEY_KINDS: readonly { label: string; value: ApiKeyKind }[] = [
14
+ { label: "API key (x-api-key)", value: "api_key" },
15
+ { label: "Auth token (Authorization: Bearer)", value: "auth_token" },
16
+ ];
17
+
18
+ /**
19
+ * The fields of an API account. Adding asks for a name, key and optional proxy too; editing keeps
20
+ * the key unless a new one is typed, and the proxy has its own button on the card. A Pi account
21
+ * takes an Anthropic API key and base URL only: Claude Code's traffic switches don't apply to Pi.
22
+ */
23
+ export function ApiAccountForm({
24
+ theme,
25
+ store,
26
+ account,
27
+ onDone,
28
+ onCancel,
29
+ }: {
30
+ theme: Theme;
31
+ store: ZeroSubStore;
32
+ /** The account being edited; absent when adding one. */
33
+ account?: AccountView;
34
+ onDone(accountId: string): void;
35
+ onCancel(): void;
36
+ }) {
37
+ const text = useText(theme);
38
+ const editing = Boolean(account);
39
+ const current = account?.api ?? null;
40
+ const [label, setLabel] = useState("");
41
+ const [keyKind, setKeyKind] = useState<ApiKeyKind>(current?.keyKind ?? "api_key");
42
+ const [key, setKey] = useState("");
43
+ const [baseUrl, setBaseUrl] = useState(current?.baseUrl ?? "");
44
+ const [proxy, setProxy] = useState("");
45
+ const [switches, setSwitches] = useState<TrafficSwitches>({
46
+ disableTelemetry: current?.disableTelemetry ?? false,
47
+ disableErrorReporting: current?.disableErrorReporting ?? false,
48
+ disableNonessentialTraffic: current?.disableNonessentialTraffic ?? false,
49
+ });
50
+ const [saving, setSaving] = useState(false);
51
+ const [error, setError] = useState<string | null>(null);
52
+ const toggle = (field: keyof TrafficSwitches) => (value: boolean) => setSwitches((previous) => ({ ...previous, [field]: value }));
53
+
54
+ const ready = editing ? true : Boolean(label.trim() && key.trim());
55
+ const submit = useCallback(async () => {
56
+ if (!ready) return;
57
+ setSaving(true);
58
+ setError(null);
59
+ try {
60
+ const fields = { keyKind, baseUrl: baseUrl.trim(), ...switches };
61
+ if (account) {
62
+ await store.rpc(updateApiAccount, { accountId: account.id, ...fields, key: key.trim() || undefined });
63
+ await store.refresh();
64
+ onDone(account.id);
65
+ } else {
66
+ const result = await store.rpc(addApiAccount, {
67
+ ...fields,
68
+ family: "claude",
69
+ label: label.trim(),
70
+ key: key.trim(),
71
+ proxy: proxy.trim() || undefined,
72
+ });
73
+ await store.refresh();
74
+ onDone(result.accountId);
75
+ }
76
+ } catch (failure) {
77
+ setError(describe(failure));
78
+ } finally {
79
+ setSaving(false);
80
+ }
81
+ }, [ready, keyKind, baseUrl, switches, account, store, key, label, proxy, onDone]);
82
+
83
+ const inputStyle = useMemo(
84
+ () => ({
85
+ color: theme.colors.foreground,
86
+ backgroundColor: theme.colors.surface2,
87
+ borderColor: theme.colors.border,
88
+ borderWidth: 1,
89
+ borderRadius: 8,
90
+ paddingHorizontal: 12,
91
+ paddingVertical: 10,
92
+ fontSize: 14,
93
+ }),
94
+ [theme],
95
+ );
96
+ const input = (props: {
97
+ value: string;
98
+ onChangeText(value: string): void;
99
+ placeholder: string;
100
+ label: string;
101
+ /** As long as the RPC takes, so a longer value can't be typed in only to be refused. */
102
+ maxLength: number;
103
+ secure?: boolean;
104
+ autoFocus?: boolean;
105
+ }) => (
106
+ <TextInput
107
+ value={props.value}
108
+ onChangeText={props.onChangeText}
109
+ maxLength={props.maxLength}
110
+ placeholder={props.placeholder}
111
+ placeholderTextColor={theme.colors.foregroundMuted}
112
+ autoCapitalize="none"
113
+ autoCorrect={false}
114
+ autoFocus={props.autoFocus}
115
+ secureTextEntry={props.secure}
116
+ style={inputStyle}
117
+ accessibilityLabel={props.label}
118
+ />
119
+ );
120
+
121
+ return (
122
+ <View style={{ gap: 12 }}>
123
+ {editing ? null : (
124
+ <Field theme={theme} title="Name">
125
+ {input({ value: label, onChangeText: setLabel, placeholder: "e.g. API or Gateway", label: "Account name", maxLength: 40, autoFocus: true })}
126
+ </Field>
127
+ )}
128
+ <SettingsCard>
129
+ <SettingsSelect<ApiKeyKind> label="Key type" value={keyKind} options={KEY_KINDS} onValueChange={(value) => setKeyKind(value)} />
130
+ </SettingsCard>
131
+ <Field theme={theme} title={keyKind === "api_key" ? "API key" : "Auth token"}>
132
+ {input({
133
+ value: key,
134
+ onChangeText: setKey,
135
+ placeholder: current
136
+ ? `Leave empty to keep the current one${current.keyHint ? ` (…${current.keyHint})` : ""}; needed again for a new base URL`
137
+ : "sk-ant-…",
138
+ label: keyKind === "api_key" ? "API key" : "Auth token",
139
+ maxLength: 4096,
140
+ secure: true,
141
+ })}
142
+ </Field>
143
+ <Field theme={theme} title="Base URL (optional)">
144
+ {input({
145
+ value: baseUrl,
146
+ onChangeText: setBaseUrl,
147
+ placeholder: "Empty: Anthropic's API · e.g. https://gateway.example.com",
148
+ label: "Base URL",
149
+ maxLength: 2048,
150
+ })}
151
+ {/^http:\/\//i.test(baseUrl.trim()) && !/^http:\/\/(localhost|127\.[\d.]+|\[::1\])(?=[:/]|$)/i.test(baseUrl.trim()) ? (
152
+ <Text style={text.small}>
153
+ Over http:// the key travels unencrypted. Use https:// unless the gateway is on a network you trust.
154
+ </Text>
155
+ ) : null}
156
+ </Field>
157
+ {editing ? null : (
158
+ <Field theme={theme} title="Proxy (optional)">
159
+ {input({ value: proxy, onChangeText: setProxy, placeholder: "http://127.0.0.1:7890", label: "Proxy URL", maxLength: 2048 })}
160
+ </Field>
161
+ )}
162
+ <View style={{ gap: 6 }}>
163
+ <Text style={text.strong}>Traffic to Anthropic</Text>
164
+ <Text style={text.small}>
165
+ Each is off unless you turn it on. With a base URL, model requests go there either way; these decide what else
166
+ Claude Code sends to Anthropic directly.
167
+ </Text>
168
+ <SettingsCard>
169
+ <SettingsSwitch
170
+ label="Turn off telemetry"
171
+ hint="DISABLE_TELEMETRY: no usage analytics or feature-flag fetches."
172
+ value={switches.disableTelemetry}
173
+ onValueChange={toggle("disableTelemetry")}
174
+ />
175
+ <SettingsSwitch
176
+ label="Turn off error reporting"
177
+ hint="DISABLE_ERROR_REPORTING: no crash reports."
178
+ value={switches.disableErrorReporting}
179
+ onValueChange={toggle("disableErrorReporting")}
180
+ />
181
+ <SettingsSwitch
182
+ label="Turn off all nonessential traffic"
183
+ hint="CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: only model requests go out. Also stops telemetry, error reports, auto-updates, plugin downloads and similar extras."
184
+ value={switches.disableNonessentialTraffic}
185
+ onValueChange={toggle("disableNonessentialTraffic")}
186
+ />
187
+ </SettingsCard>
188
+ </View>
189
+ <Text style={text.small}>
190
+ Billed per use, so ZeroSub never moves agents onto it by itself: it's used only as the default or when you pick it
191
+ for an agent. The key stays on this host.
192
+ </Text>
193
+ {error ? <Text style={text.danger}>{error}</Text> : null}
194
+ <View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8, justifyContent: "flex-end" }}>
195
+ <Button theme={theme} label="Cancel" tooltip={editing ? "Keep the current settings" : "Close without adding an account"} tooltipAlign="end" onPress={onCancel} />
196
+ <Button
197
+ theme={theme}
198
+ tone="primary"
199
+ label={editing ? "Save" : "Add account"}
200
+ tooltip={editing ? "Save these settings" : "Add this API account"}
201
+ tooltipAlign="end"
202
+ busy={saving}
203
+ disabled={!ready}
204
+ onPress={() => void submit()}
205
+ />
206
+ </View>
207
+ </View>
208
+ );
209
+ }
210
+
211
+ /** Edits an API account from its card. */
212
+ export function ApiAccountModal({
213
+ theme,
214
+ store,
215
+ account,
216
+ onClose,
217
+ }: {
218
+ theme: Theme;
219
+ store: ZeroSubStore;
220
+ account: AccountView;
221
+ onClose(): void;
222
+ }) {
223
+ const toast = useToast();
224
+ return (
225
+ <Modal title={`API settings for ${account.label}`} open onOpenChange={(open) => (open ? undefined : onClose())}>
226
+ <Modal.Content>
227
+ <ApiAccountForm
228
+ theme={theme}
229
+ store={store}
230
+ account={account}
231
+ onCancel={onClose}
232
+ onDone={() => {
233
+ toast.show(`${account.label} updated. Agents started from now on use it.`, { variant: "success" });
234
+ onClose();
235
+ }}
236
+ />
237
+ </Modal.Content>
238
+ </Modal>
239
+ );
240
+ }
241
+
242
+ function Field({ theme, title, children }: { theme: Theme; title: string; children: ReactNode }) {
243
+ const text = useText(theme);
244
+ return (
245
+ <View style={{ gap: 6 }}>
246
+ <Text style={text.strong}>{title}</Text>
247
+ {children}
248
+ </View>
249
+ );
250
+ }
@@ -0,0 +1,311 @@
1
+ import type { PluginSurfaceProps } from "@getpaseo/plugin/client";
2
+ import { Modal, TextInput, useToast } from "@getpaseo/plugin/client/react-native";
3
+ import { useCallback, useMemo, useState, type ReactNode } from "react";
4
+ import { Text, View } from "react-native";
5
+ import { apiUsageLines } from "../shared/format";
6
+ import type { AccountView, ApiPrice } from "../shared/model";
7
+ import { addAzureAccount, updateAzureAccount } from "../shared/rpc";
8
+ import { describe, type ZeroSubStore } from "./store";
9
+ import { Button, IconButton, useText } from "./ui";
10
+
11
+ type Theme = PluginSurfaceProps["theme"];
12
+
13
+ /**
14
+ * Azure OpenAI accounts: ChatGPT (Codex) accounts that run Codex on an Azure OpenAI resource with an
15
+ * API key. The key is typed here and never comes back from the host; the app sees only its last four
16
+ * characters.
17
+ */
18
+
19
+ const ENDPOINT_PLACEHOLDER = "https://<resource>.openai.azure.com/openai/v1";
20
+
21
+ /** The card's line about an Azure account: where it goes and which key it uses. */
22
+ export function azureCardDetails(account: AccountView): string | null {
23
+ const azure = account.azure;
24
+ if (!azure) return null;
25
+ return `${azure.host} · Key${azure.keyHint ? ` …${azure.keyHint}` : ""}`;
26
+ }
27
+
28
+ /** This month's tokens and estimated cost, in place of the usage bars of a subscription account. */
29
+ export function AzureUsage({ theme, account, paidFallback }: { theme: Theme; account: AccountView; paidFallback: boolean }) {
30
+ const text = useText(theme);
31
+ if (!account.azure) return null;
32
+ const { tokens, cost, note } = apiUsageLines(account.azure);
33
+ return (
34
+ <View style={{ gap: 4 }}>
35
+ <Text style={text.small}>{tokens}</Text>
36
+ <Text style={text.small}>{cost}</Text>
37
+ {note ? <Text style={text.small}>{note}</Text> : null}
38
+ <Text style={text.small}>
39
+ {paidFallback
40
+ ? "Billed per token · used by itself only when every ChatGPT subscription account is out, or when picked"
41
+ : "Billed per token · used only as the default or when picked for an agent"}
42
+ </Text>
43
+ </View>
44
+ );
45
+ }
46
+
47
+ interface PriceRow {
48
+ model: string;
49
+ input: string;
50
+ cachedInput: string;
51
+ output: string;
52
+ }
53
+
54
+ function toRows(prices: Readonly<Record<string, ApiPrice>>): PriceRow[] {
55
+ const show = (value: number | null) => (value === null ? "" : String(value));
56
+ return Object.entries(prices).map(([model, price]) => ({ model, input: show(price.input), cachedInput: show(price.cachedInput), output: show(price.output) }));
57
+ }
58
+
59
+ /** The table typed in, or the first problem with it. */
60
+ function fromRows(rows: readonly PriceRow[]): Record<string, ApiPrice> | string {
61
+ const prices: Record<string, ApiPrice> = {};
62
+ for (const row of rows) {
63
+ const model = row.model.trim();
64
+ if (!model) continue;
65
+ const parse = (value: string): number | null | undefined => {
66
+ if (!value.trim()) return null;
67
+ const number = Number(value.trim());
68
+ return Number.isFinite(number) && number >= 0 ? number : undefined;
69
+ };
70
+ const input = parse(row.input);
71
+ const cachedInput = parse(row.cachedInput);
72
+ const output = parse(row.output);
73
+ if (input === undefined || cachedInput === undefined || output === undefined) return `Prices for ${model} must be numbers (USD per 1M tokens).`;
74
+ // Azure OpenAI has no cache writes.
75
+ prices[model] = { input, cachedInput, cacheWrite: null, output };
76
+ }
77
+ return prices;
78
+ }
79
+
80
+ /**
81
+ * The fields of an Azure OpenAI account. Adding asks for a name, the endpoint and the key; editing
82
+ * keeps the key unless a new one is typed (a new endpoint needs it again), and adds the price table
83
+ * the card's cost estimate comes from.
84
+ */
85
+ export function AzureAccountForm({
86
+ theme,
87
+ store,
88
+ account,
89
+ paidFallback,
90
+ onDone,
91
+ onCancel,
92
+ }: {
93
+ theme: Theme;
94
+ store: ZeroSubStore;
95
+ /** The account being edited; absent when adding one. */
96
+ account?: AccountView;
97
+ /** Paid API accounts may take work over by themselves once every subscription is out. */
98
+ paidFallback: boolean;
99
+ onDone(accountId: string, warning: string | null): void;
100
+ onCancel(): void;
101
+ }) {
102
+ const text = useText(theme);
103
+ const current = account?.azure ?? null;
104
+ const editing = Boolean(account);
105
+ const [label, setLabel] = useState("");
106
+ const [endpoint, setEndpoint] = useState(current?.endpoint ?? "");
107
+ const [key, setKey] = useState("");
108
+ const [rows, setRows] = useState<PriceRow[]>(() => toRows(current?.prices ?? {}));
109
+ const [saving, setSaving] = useState(false);
110
+ const [error, setError] = useState<string | null>(null);
111
+ const ready = editing ? Boolean(endpoint.trim()) : Boolean(label.trim() && endpoint.trim() && key.trim());
112
+
113
+ const submit = useCallback(async () => {
114
+ if (!ready) return;
115
+ setSaving(true);
116
+ setError(null);
117
+ try {
118
+ if (account) {
119
+ const prices = fromRows(rows);
120
+ if (typeof prices === "string") throw new Error(prices);
121
+ const result = await store.rpc(updateAzureAccount, { accountId: account.id, endpoint: endpoint.trim(), key: key.trim() || undefined, prices });
122
+ await store.refresh();
123
+ onDone(account.id, result.warning);
124
+ } else {
125
+ const result = await store.rpc(addAzureAccount, { label: label.trim(), endpoint: endpoint.trim(), key: key.trim() });
126
+ await store.refresh();
127
+ onDone(result.accountId, result.warning);
128
+ }
129
+ } catch (failure) {
130
+ setError(describe(failure));
131
+ } finally {
132
+ setSaving(false);
133
+ }
134
+ }, [ready, account, rows, store, endpoint, key, label, onDone]);
135
+
136
+ const inputStyle = useMemo(
137
+ () => ({
138
+ color: theme.colors.foreground,
139
+ backgroundColor: theme.colors.surface2,
140
+ borderColor: theme.colors.border,
141
+ borderWidth: 1,
142
+ borderRadius: 8,
143
+ paddingHorizontal: 12,
144
+ paddingVertical: 10,
145
+ fontSize: 14,
146
+ }),
147
+ [theme],
148
+ );
149
+ const input = (props: {
150
+ value: string;
151
+ onChangeText(value: string): void;
152
+ placeholder: string;
153
+ label: string;
154
+ /** As long as the RPC takes, so a longer value can't be typed in only to be refused. */
155
+ maxLength: number;
156
+ secure?: boolean;
157
+ autoFocus?: boolean;
158
+ flex?: number;
159
+ }) => (
160
+ <TextInput
161
+ value={props.value}
162
+ onChangeText={props.onChangeText}
163
+ maxLength={props.maxLength}
164
+ placeholder={props.placeholder}
165
+ placeholderTextColor={theme.colors.foregroundMuted}
166
+ autoCapitalize="none"
167
+ autoCorrect={false}
168
+ autoFocus={props.autoFocus}
169
+ secureTextEntry={props.secure}
170
+ style={props.flex ? [inputStyle, { flex: props.flex, minWidth: 0 }] : inputStyle}
171
+ accessibilityLabel={props.label}
172
+ />
173
+ );
174
+ const cell = (index: number, field: keyof PriceRow, placeholder: string, flex: number) =>
175
+ input({
176
+ value: rows[index]![field],
177
+ onChangeText: (value) => setRows((all) => all.map((row, at) => (at === index ? { ...row, [field]: value } : row))),
178
+ placeholder,
179
+ label: field === "model" ? "Model" : `${placeholder} price of ${rows[index]!.model}`,
180
+ maxLength: field === "model" ? 200 : 12,
181
+ flex,
182
+ });
183
+ const used = Object.keys(current?.usage?.models ?? {});
184
+
185
+ return (
186
+ <View style={{ gap: 12 }}>
187
+ {editing ? null : (
188
+ <Field theme={theme} title="Name">
189
+ {input({ value: label, onChangeText: setLabel, placeholder: "e.g. Azure", label: "Account name", maxLength: 40, autoFocus: true })}
190
+ </Field>
191
+ )}
192
+ <Field theme={theme} title="Endpoint">
193
+ {input({ value: endpoint, onChangeText: setEndpoint, placeholder: ENDPOINT_PLACEHOLDER, label: "Endpoint URL", maxLength: 2048 })}
194
+ <Text style={text.small}>Your resource's v1 API, https:// only. A bare resource URL gets /openai/v1 added.</Text>
195
+ </Field>
196
+ <Field theme={theme} title="API key">
197
+ {input({
198
+ value: key,
199
+ onChangeText: setKey,
200
+ placeholder: current
201
+ ? `Leave empty to keep the current one${current.keyHint ? ` (…${current.keyHint})` : ""}; needed again for a new endpoint`
202
+ : "Key 1 or Key 2 of the resource",
203
+ label: "API key",
204
+ maxLength: 4096,
205
+ secure: true,
206
+ })}
207
+ </Field>
208
+ {editing ? (
209
+ <Field theme={theme} title="Prices (optional, USD per 1M tokens)">
210
+ <Text style={text.small}>
211
+ Per model (deployment name), for the cost estimate on the card. Without prices the card shows tokens only. Cached input
212
+ without a price counts at the input price.
213
+ </Text>
214
+ {rows.map((row, index) => (
215
+ <View key={index} style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
216
+ {cell(index, "model", "Model", 2)}
217
+ {cell(index, "input", "Input", 1)}
218
+ {cell(index, "cachedInput", "Cached", 1)}
219
+ {cell(index, "output", "Output", 1)}
220
+ <IconButton
221
+ theme={theme}
222
+ icon="Trash2"
223
+ label="Remove price"
224
+ tooltip="Remove this model's prices"
225
+ onPress={() => setRows((all) => all.filter((_, at) => at !== index))}
226
+ />
227
+ </View>
228
+ ))}
229
+ <View style={{ flexDirection: "row" }}>
230
+ <Button
231
+ theme={theme}
232
+ size="small"
233
+ icon="Plus"
234
+ label="Add model"
235
+ tooltip="Add prices for another model"
236
+ tooltipAlign="start"
237
+ onPress={() =>
238
+ setRows((all) => [...all, { model: used.find((model) => !all.some((row) => row.model === model)) ?? "", input: "", cachedInput: "", output: "" }])
239
+ }
240
+ />
241
+ </View>
242
+ </Field>
243
+ ) : null}
244
+ <Text style={text.small}>
245
+ {paidFallback
246
+ ? "Billed per token by Azure. With paid API accounts turned on, ZeroSub moves ChatGPT agents onto it by itself only when every ChatGPT subscription account is out; you can always pick it for an agent or make it the default."
247
+ : "Billed per token by Azure, so ZeroSub never moves agents onto it by itself: it's used only as the default or when you pick it for an agent."}{" "}
248
+ The key is checked against the endpoint and stays on this host, readable only by you.
249
+ </Text>
250
+ {error ? <Text style={text.danger}>{error}</Text> : null}
251
+ <View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8, justifyContent: "flex-end" }}>
252
+ <Button theme={theme} label="Cancel" tooltip={editing ? "Keep the current settings" : "Close without adding an account"} tooltipAlign="end" onPress={onCancel} />
253
+ <Button
254
+ theme={theme}
255
+ tone="primary"
256
+ label={editing ? "Save" : "Add account"}
257
+ tooltip={editing ? "Save these settings" : "Check the key and add this account"}
258
+ tooltipAlign="end"
259
+ busy={saving}
260
+ disabled={!ready}
261
+ onPress={() => void submit()}
262
+ />
263
+ </View>
264
+ </View>
265
+ );
266
+ }
267
+
268
+ /** Edits an Azure OpenAI account from its card: endpoint, key and prices. */
269
+ export function AzureAccountModal({
270
+ theme,
271
+ store,
272
+ account,
273
+ paidFallback,
274
+ onClose,
275
+ }: {
276
+ theme: Theme;
277
+ store: ZeroSubStore;
278
+ account: AccountView;
279
+ paidFallback: boolean;
280
+ onClose(): void;
281
+ }) {
282
+ const toast = useToast();
283
+ return (
284
+ <Modal title={`Azure settings for ${account.label}`} open onOpenChange={(open) => (open ? undefined : onClose())}>
285
+ <Modal.Content>
286
+ <AzureAccountForm
287
+ theme={theme}
288
+ store={store}
289
+ account={account}
290
+ paidFallback={paidFallback}
291
+ onCancel={onClose}
292
+ onDone={(_, warning) => {
293
+ if (warning) toast.show(warning, { variant: "warning", durationMs: 8_000 });
294
+ else toast.show(`${account.label} updated. Agents started from now on use it.`, { variant: "success" });
295
+ onClose();
296
+ }}
297
+ />
298
+ </Modal.Content>
299
+ </Modal>
300
+ );
301
+ }
302
+
303
+ function Field({ theme, title, children }: { theme: Theme; title: string; children: ReactNode }) {
304
+ const text = useText(theme);
305
+ return (
306
+ <View style={{ gap: 6 }}>
307
+ <Text style={text.strong}>{title}</Text>
308
+ {children}
309
+ </View>
310
+ );
311
+ }
@@ -1,7 +1,8 @@
1
1
  import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { describeReopen, limitedPick, moveProblem } from "../shared/format";
2
3
  import { FAMILY_LABEL, type AccountView, type StateView } from "../shared/model";
3
- import { setAgentAccount, setDefaultAccount } from "../shared/rpc";
4
- import type { ZeroSubStore } from "./store";
4
+ import { setAgentAccount, setDefaultAccount, setNextAgentAccount, type ReopenSummary } from "../shared/rpc";
5
+ import { stoppedWaiting, type ZeroSubStore } from "./store";
5
6
 
6
7
  /** Command Center entries and the `/account` slash command. */
7
8
  export function contributeCommands(client: PluginClientContext, store: ZeroSubStore): () => void {
@@ -12,7 +13,7 @@ export function contributeCommands(client: PluginClientContext, store: ZeroSubSt
12
13
  id: "open-accounts",
13
14
  title: "Manage subscription accounts (ZeroSub)",
14
15
  icon: "Users",
15
- keywords: ["zerosub", "claude", "chatgpt", "codex", "account", "subscription", "login", "switch"],
16
+ keywords: ["zerosub", "claude", "chatgpt", "codex", "pi", "grok", "cursor", "account", "subscription", "login", "switch"],
16
17
  context: "global",
17
18
  onSelect({ openSurface }) {
18
19
  openSurface("accounts");
@@ -29,15 +30,20 @@ export function contributeCommands(client: PluginClientContext, store: ZeroSubSt
29
30
  async onSubmit({ args, agent, openSurface }) {
30
31
  const state = await currentState(store);
31
32
  const family = state.providers[agent.provider];
32
- if (!family) throw new Error(`${agent.provider} agents don't use Claude or ChatGPT subscription accounts.`);
33
+ if (!family) throw new Error(`${agent.provider} agents don't use Claude, ChatGPT, Grok or Cursor subscription accounts.`);
33
34
  const query = args.trim();
34
35
  if (!query) {
35
36
  openSurface("accounts");
36
37
  return;
37
38
  }
38
39
  const accounts = state.accounts.filter((account) => account.family === family);
40
+ // Paseo shows what a command throws: a refusal, or that the agent couldn't be reloaded.
41
+ const move = async (accountId: string | null, to: string) => {
42
+ const problem = moveProblem(await stillMoving(store.rpc(setAgentAccount, { agentId: agent.id, accountId })), to);
43
+ if (problem) throw new Error(problem);
44
+ };
39
45
  if (/^default$/i.test(query)) {
40
- await store.rpc(setAgentAccount, { agentId: agent.id, accountId: null });
46
+ await move(null, accounts.find((account) => account.isDefault)?.label ?? "the default account");
41
47
  return;
42
48
  }
43
49
  const match = findAccount(accounts, query);
@@ -47,7 +53,8 @@ export function contributeCommands(client: PluginClientContext, store: ZeroSubSt
47
53
  }
48
54
  if (match.status === "signed_out") throw new Error(`${match.label} is signed out. Sign it in from Accounts first.`);
49
55
  if (match.status === "disabled") throw new Error(`${match.label} is disabled. Enable it in Accounts first.`);
50
- await store.rpc(setAgentAccount, { agentId: agent.id, accountId: match.id });
56
+ if (match.status === "limited" && state.autoSwitch) throw new Error(limitedPick(match.label));
57
+ await move(match.id, match.label);
51
58
  },
52
59
  }),
53
60
  );
@@ -57,13 +64,32 @@ export function contributeCommands(client: PluginClientContext, store: ZeroSubSt
57
64
  let signature = "";
58
65
  const syncDynamic = () => {
59
66
  const state = store.current.state;
60
- const next = state ? JSON.stringify(state.accounts.map((a) => [a.id, a.label, a.isDefault, a.status])) : "";
67
+ const next = state ? JSON.stringify(state.accounts.map((a) => [a.id, a.label, a.isDefault, a.status, a.nextAgentUntil])) : "";
61
68
  if (next === signature) return;
62
69
  signature = next;
63
70
  for (const remove of dynamic) remove();
64
71
  dynamic = [];
65
72
  if (!state) return;
66
73
  state.accounts.forEach((account, index) => {
74
+ const pending = Boolean(account.nextAgentUntil);
75
+ // A waiting pick can always be canceled, whatever has become of its account since.
76
+ if (pending || (account.status !== "signed_out" && account.status !== "disabled")) {
77
+ dynamic.push(
78
+ client.addCommandCenterItem({
79
+ id: `next-agent-${index}`,
80
+ title: pending
81
+ ? `Cancel: next new ${FAMILY_LABEL[account.family]} agent on ${account.label}`
82
+ : `Next new ${FAMILY_LABEL[account.family]} agent: use ${account.label}`,
83
+ icon: pending ? "CircleX" : "SquarePlus",
84
+ keywords: ["account", "next", "new agent", "workspace", account.email ?? "", account.family],
85
+ context: "global",
86
+ async onSelect() {
87
+ await store.rpc(setNextAgentAccount, { accountId: account.id, enabled: !pending });
88
+ await store.refresh();
89
+ },
90
+ }),
91
+ );
92
+ }
67
93
  if (account.isDefault || account.status === "signed_out" || account.status === "disabled") return;
68
94
  dynamic.push(
69
95
  client.addCommandCenterItem({
@@ -73,7 +99,9 @@ export function contributeCommands(client: PluginClientContext, store: ZeroSubSt
73
99
  keywords: ["account", "default", "switch", account.email ?? "", account.family],
74
100
  context: "global",
75
101
  async onSelect() {
76
- await store.rpc(setDefaultAccount, { accountId: account.id });
102
+ const summary = await stillMoving(store.rpc(setDefaultAccount, { accountId: account.id }));
103
+ // Only a reload that didn't work needs saying; Paseo shows what this throws.
104
+ if (summary.failed.length > 0) throw new Error(describeReopen(`${account.label} is now the default`, summary));
77
105
  },
78
106
  }),
79
107
  );
@@ -89,6 +117,14 @@ export function contributeCommands(client: PluginClientContext, store: ZeroSubSt
89
117
  };
90
118
  }
91
119
 
120
+ /** A move's outcome; nothing to report when Paseo stopped waiting for it, since it goes on regardless. */
121
+ async function stillMoving(request: Promise<ReopenSummary>): Promise<ReopenSummary> {
122
+ return request.catch((error: unknown) => {
123
+ if (stoppedWaiting(error)) return { reopened: [], deferred: [], failed: [], pending: [], continuedIn: null };
124
+ throw error;
125
+ });
126
+ }
127
+
92
128
  async function currentState(store: ZeroSubStore): Promise<StateView> {
93
129
  if (!store.current.state) await store.refresh();
94
130
  const state = store.current.state;