@kapybara/zerosub 1.18.3 → 1.19.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.
- package/README.md +58 -1
- package/client/accounts-surface.tsx +49 -11
- package/client/add-account.tsx +36 -9
- package/client/bedrock-account.tsx +455 -0
- package/client/settings-screen.tsx +1 -1
- package/client/switch-row.tsx +4 -2
- package/index.server.ts +17 -0
- package/package.json +1 -1
- package/server/api-usage.ts +47 -4
- package/server/bedrock.ts +437 -0
- package/server/claude.ts +17 -0
- package/server/codex.ts +1 -1
- package/server/homes.ts +8 -1
- package/server/limits.ts +111 -0
- package/server/routing.ts +22 -7
- package/server/service.ts +532 -47
- package/server/state.ts +4 -1
- package/shared/model.ts +60 -3
- package/shared/preferences.ts +3 -3
- package/shared/rpc.ts +56 -1
- package/shared/timeline.ts +2 -0
package/server/state.ts
CHANGED
|
@@ -16,7 +16,8 @@ export const StoredAccountSchema = z.object({
|
|
|
16
16
|
auth: AuthKindSchema.default("subscription"),
|
|
17
17
|
/**
|
|
18
18
|
* The paid API an `api` account stands in for a subscription on (an Azure OpenAI account's
|
|
19
|
-
* `azure`), set when it's added. Missing for every other
|
|
19
|
+
* `azure`, an AWS Bedrock account's `bedrock`), set when it's added. Missing for every other
|
|
20
|
+
* account, API-key ones included.
|
|
20
21
|
*/
|
|
21
22
|
provider: ApiProviderSchema.optional(),
|
|
22
23
|
/** Credential home (`CLAUDE_CONFIG_DIR` / `CODEX_HOME`). `null` for the CLI's own login. */
|
|
@@ -39,6 +40,8 @@ export const StoredAccountSchema = z.object({
|
|
|
39
40
|
* saved by earlier versions, which count as a turn's.
|
|
40
41
|
*/
|
|
41
42
|
limitSource: z.enum(["turn", "reading"]).optional(),
|
|
43
|
+
/** What the provider said when it refused an Azure or Bedrock account, shown on its card while it's signed out. */
|
|
44
|
+
apiError: z.string().nullable().optional(),
|
|
42
45
|
/**
|
|
43
46
|
* Limits of one model's own window ("Weekly · Fable"), keyed by the lowercase scope name. They keep
|
|
44
47
|
* agents on that model off the account; the account itself stays usable for every other model.
|
package/shared/model.ts
CHANGED
|
@@ -128,8 +128,9 @@ export const AuthKindSchema = z.enum([
|
|
|
128
128
|
"subscription",
|
|
129
129
|
/**
|
|
130
130
|
* An API key or token (a Claude account's, optionally against another base URL; an added Pi
|
|
131
|
-
* account's Anthropic key; an Azure OpenAI account's), billed per use, so never
|
|
132
|
-
* automatically. An Azure OpenAI account can be, as a last resort, once
|
|
131
|
+
* account's Anthropic key; an Azure OpenAI or AWS Bedrock account's), billed per use, so never
|
|
132
|
+
* picked automatically. An Azure OpenAI or Bedrock account can be, as a last resort, once
|
|
133
|
+
* `paidApiFallback` is on.
|
|
133
134
|
*/
|
|
134
135
|
"api",
|
|
135
136
|
]);
|
|
@@ -142,6 +143,8 @@ export type AuthKind = z.infer<typeof AuthKindSchema>;
|
|
|
142
143
|
export const ApiProviderSchema = z.enum([
|
|
143
144
|
/** An Azure OpenAI resource, under ChatGPT (Codex). */
|
|
144
145
|
"azure",
|
|
146
|
+
/** Amazon Bedrock with AWS credentials, under Claude. */
|
|
147
|
+
"bedrock",
|
|
145
148
|
]);
|
|
146
149
|
export type ApiProvider = z.infer<typeof ApiProviderSchema>;
|
|
147
150
|
|
|
@@ -150,6 +153,14 @@ export function isAzureAccount(account: { family: Family; provider?: ApiProvider
|
|
|
150
153
|
return account.family === "codex" && account.provider === "azure";
|
|
151
154
|
}
|
|
152
155
|
|
|
156
|
+
/**
|
|
157
|
+
* An AWS Bedrock account: a Claude account added as one, marked `provider: "bedrock"`. A Claude
|
|
158
|
+
* account on an API key or token without the marker (#65's) is never one.
|
|
159
|
+
*/
|
|
160
|
+
export function isBedrockAccount(account: { family: Family; provider?: ApiProvider }): boolean {
|
|
161
|
+
return account.family === "claude" && account.provider === "bedrock";
|
|
162
|
+
}
|
|
163
|
+
|
|
153
164
|
export const ApiKeyKindSchema = z.enum([
|
|
154
165
|
/** `ANTHROPIC_API_KEY`, sent as `x-api-key`. */
|
|
155
166
|
"api_key",
|
|
@@ -279,6 +290,48 @@ export const AzureSummarySchema = z.object({
|
|
|
279
290
|
});
|
|
280
291
|
export type AzureSummary = z.infer<typeof AzureSummarySchema>;
|
|
281
292
|
|
|
293
|
+
/** Where an AWS Bedrock account's AWS credentials come from. */
|
|
294
|
+
export const BedrockSourceSchema = z.enum([
|
|
295
|
+
/** The host's own: the AWS default chain (environment, ~/.aws, an instance or task role). Nothing is stored. */
|
|
296
|
+
"host",
|
|
297
|
+
/** A named profile in the host's ~/.aws config. Only its name is stored. */
|
|
298
|
+
"profile",
|
|
299
|
+
/** An access key (secret, optional session token) kept in the account's home. */
|
|
300
|
+
"keys",
|
|
301
|
+
]);
|
|
302
|
+
export type BedrockSource = z.infer<typeof BedrockSourceSchema>;
|
|
303
|
+
|
|
304
|
+
/** Model overrides for a Bedrock account (model or inference-profile IDs); empty keeps Claude Code's own. */
|
|
305
|
+
export const BedrockModelsSchema = z.object({
|
|
306
|
+
/** `ANTHROPIC_MODEL`. */
|
|
307
|
+
model: z.string().default(""),
|
|
308
|
+
/** `ANTHROPIC_DEFAULT_OPUS_MODEL`. */
|
|
309
|
+
opus: z.string().default(""),
|
|
310
|
+
/** `ANTHROPIC_DEFAULT_SONNET_MODEL`. */
|
|
311
|
+
sonnet: z.string().default(""),
|
|
312
|
+
/** `ANTHROPIC_DEFAULT_HAIKU_MODEL`. */
|
|
313
|
+
haiku: z.string().default(""),
|
|
314
|
+
});
|
|
315
|
+
export type BedrockModels = z.infer<typeof BedrockModelsSchema>;
|
|
316
|
+
|
|
317
|
+
/** An AWS Bedrock account (a Claude account on AWS) as the app sees it. Secrets never leave the host. */
|
|
318
|
+
export const BedrockSummarySchema = z.object({
|
|
319
|
+
region: z.string(),
|
|
320
|
+
source: BedrockSourceSchema,
|
|
321
|
+
/** The profile's name, for `profile`. */
|
|
322
|
+
profile: z.string().nullable(),
|
|
323
|
+
/** The access key ID's last four characters, for `keys`. */
|
|
324
|
+
keyHint: z.string().nullable(),
|
|
325
|
+
/** Whether a session token is kept with the access key. */
|
|
326
|
+
sessionToken: z.boolean().default(false),
|
|
327
|
+
models: BedrockModelsSchema,
|
|
328
|
+
/** USD per million tokens, by model as Claude Code names it. */
|
|
329
|
+
prices: z.record(z.string(), ApiPriceSchema).default({}),
|
|
330
|
+
/** This month's tokens; null before the first counted turn. */
|
|
331
|
+
usage: ApiMonthSchema.nullable().default(null),
|
|
332
|
+
});
|
|
333
|
+
export type BedrockSummary = z.infer<typeof BedrockSummarySchema>;
|
|
334
|
+
|
|
282
335
|
/** The address an account's requests come from, as the provider's edge sees it. */
|
|
283
336
|
export const EgressSchema = z.object({
|
|
284
337
|
/** From the last check that worked. */
|
|
@@ -367,6 +420,10 @@ export const AccountViewSchema = z.object({
|
|
|
367
420
|
externalHome: z.boolean().default(false),
|
|
368
421
|
/** Set for an Azure OpenAI account (a ChatGPT/Codex account on an API key); null for any other. */
|
|
369
422
|
azure: AzureSummarySchema.nullable().default(null),
|
|
423
|
+
/** Set for an AWS Bedrock account (a Claude account on AWS); null for any other. */
|
|
424
|
+
bedrock: BedrockSummarySchema.nullable().default(null),
|
|
425
|
+
/** What the provider said when it last refused an Azure or Bedrock account, while it's signed out for it. */
|
|
426
|
+
apiError: z.string().nullable().default(null),
|
|
370
427
|
/** The account's home is due to move to `to`, and hasn't yet: what it waits for, or what went wrong. */
|
|
371
428
|
moving: z.object({ to: z.string(), waiting: z.string().nullable(), error: z.string().nullable() }).nullable().default(null),
|
|
372
429
|
/** How pacing reads this account; null unless spreading is on and it's one of two or more accounts that can stand in. */
|
|
@@ -495,7 +552,7 @@ export const StateViewSchema = z.object({
|
|
|
495
552
|
* to create the agent on an older host.
|
|
496
553
|
*/
|
|
497
554
|
agentMetadata: z.boolean().optional(),
|
|
498
|
-
/** Paid API accounts (Azure OpenAI) may take work over by themselves once every subscription is out. */
|
|
555
|
+
/** Paid API accounts (Azure OpenAI, AWS Bedrock) may take work over by themselves once every subscription is out. */
|
|
499
556
|
paidApiFallback: z.boolean().optional(),
|
|
500
557
|
warnings: z.array(z.string()),
|
|
501
558
|
});
|
package/shared/preferences.ts
CHANGED
|
@@ -52,9 +52,9 @@ export const preferences = defineSettings({
|
|
|
52
52
|
/**
|
|
53
53
|
* Off unless turned on. When every subscription account of a provider is out (at its limit,
|
|
54
54
|
* signed out or disabled), routing may move agents onto a paid API account that stands in for
|
|
55
|
-
* one (an Azure OpenAI account under ChatGPT
|
|
56
|
-
* `autoRedeem` is on. Off, such an account is only used
|
|
57
|
-
* default, like any API-key account.
|
|
55
|
+
* one (an Azure OpenAI account under ChatGPT, an AWS Bedrock account under Claude), billed per
|
|
56
|
+
* token; a banked reset goes first when `autoRedeem` is on. Off, such an account is only used
|
|
57
|
+
* when picked for an agent or made the default, like any API-key account.
|
|
58
58
|
*/
|
|
59
59
|
paidApiFallback: z.boolean().default(false),
|
|
60
60
|
/** Show the account pill in the composer of Claude and Codex agents. */
|
package/shared/rpc.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineRpc } from "@getpaseo/plugin";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { ApiKeyKindSchema, ApiPriceSchema, FamilySchema, LoginMethodSchema, LoginViewSchema, StateViewSchema, TrafficSwitchesSchema } from "./model";
|
|
3
|
+
import { ApiKeyKindSchema, ApiPriceSchema, BedrockSourceSchema, FamilySchema, LoginMethodSchema, LoginViewSchema, StateViewSchema, TrafficSwitchesSchema } from "./model";
|
|
4
4
|
|
|
5
5
|
export const getState = defineRpc({
|
|
6
6
|
name: "zerosub.state",
|
|
@@ -98,6 +98,61 @@ export const updateAzureAccount = defineRpc({
|
|
|
98
98
|
output: z.object({ ok: z.literal(true), warning: z.string().nullable() }),
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
+
const BedrockFields = {
|
|
102
|
+
/** An AWS region code, like `eu-central-1`. */
|
|
103
|
+
region: z.string().trim().min(1).max(40),
|
|
104
|
+
source: BedrockSourceSchema,
|
|
105
|
+
/** For `profile`: a profile in the host's ~/.aws config. Only its name is stored. */
|
|
106
|
+
profile: z.string().trim().max(128).optional(),
|
|
107
|
+
/** For `keys`. The secret and session token are written to the account's home and never sent back. */
|
|
108
|
+
accessKeyId: z.string().trim().max(128).optional(),
|
|
109
|
+
secretAccessKey: z.string().trim().max(1024).optional(),
|
|
110
|
+
sessionToken: z.string().trim().max(4096).optional(),
|
|
111
|
+
/** Model or inference-profile IDs for ANTHROPIC_MODEL and the Opus, Sonnet and Haiku defaults; empty keeps Claude Code's. */
|
|
112
|
+
models: z
|
|
113
|
+
.object({
|
|
114
|
+
model: z.string().trim().max(200).optional(),
|
|
115
|
+
opus: z.string().trim().max(200).optional(),
|
|
116
|
+
sonnet: z.string().trim().max(200).optional(),
|
|
117
|
+
haiku: z.string().trim().max(200).optional(),
|
|
118
|
+
})
|
|
119
|
+
.optional(),
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Adds an AWS Bedrock account under Claude. Its credentials are checked with the host's `aws` CLI
|
|
124
|
+
* first, when it has one; refused ones aren't saved, and `warning` says when they couldn't be checked.
|
|
125
|
+
*/
|
|
126
|
+
export const addBedrockAccount = defineRpc({
|
|
127
|
+
name: "zerosub.accounts.bedrock.add",
|
|
128
|
+
input: z.object({ label: z.string().trim().min(1).max(40), ...BedrockFields }),
|
|
129
|
+
output: z.object({ accountId: z.string(), warning: z.string().nullable() }),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/** Changes an AWS Bedrock account's region, credentials (an empty secret keeps it), models or price table. */
|
|
133
|
+
export const updateBedrockAccount = defineRpc({
|
|
134
|
+
name: "zerosub.accounts.bedrock.update",
|
|
135
|
+
input: z.object({
|
|
136
|
+
accountId: z.string(),
|
|
137
|
+
...BedrockFields,
|
|
138
|
+
region: BedrockFields.region.optional(),
|
|
139
|
+
source: BedrockFields.source.optional(),
|
|
140
|
+
prices: z.record(z.string().trim().max(200), ApiPriceSchema).optional(),
|
|
141
|
+
}),
|
|
142
|
+
output: z.object({ ok: z.literal(true), warning: z.string().nullable() }),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The AWS region the host's own setup names (its environment, ~/.aws/config, or the EC2 instance it
|
|
147
|
+
* runs on), to fill in the Bedrock form. Asked for only when that form opens, and answered within a
|
|
148
|
+
* couple of seconds, with null when the host names none.
|
|
149
|
+
*/
|
|
150
|
+
export const detectBedrockRegion = defineRpc({
|
|
151
|
+
name: "zerosub.accounts.bedrock.region",
|
|
152
|
+
input: z.object({}),
|
|
153
|
+
output: z.object({ region: z.string().nullable(), source: z.enum(["environment", "config", "instance"]).nullable() }),
|
|
154
|
+
});
|
|
155
|
+
|
|
101
156
|
/** Sets a Claude or Pi account's proxy (their CLI logins' included); an empty value clears it. */
|
|
102
157
|
export const setAccountProxy = defineRpc({
|
|
103
158
|
name: "zerosub.accounts.proxy",
|
package/shared/timeline.ts
CHANGED
|
@@ -25,6 +25,8 @@ export const SwitchRowSchema = z.object({
|
|
|
25
25
|
"enabled",
|
|
26
26
|
/** Every account of this provider is at its limit; nothing to switch to. */
|
|
27
27
|
"exhausted",
|
|
28
|
+
/** `from` is a paid API account (AWS Bedrock) it moved onto by itself, and a subscription account has room again. */
|
|
29
|
+
"room",
|
|
28
30
|
/** `from` still works but is projected past the 5-hour pacing gate; a cold idle agent moved off it. */
|
|
29
31
|
"pacing",
|
|
30
32
|
]),
|