@tokenite/shared 1.0.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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -0
  3. package/dist/catalog/agent-runtime.d.ts +3 -0
  4. package/dist/catalog/agent-runtime.js +3 -0
  5. package/dist/catalog/bindings/anthropic.d.ts +2 -0
  6. package/dist/catalog/bindings/anthropic.js +11 -0
  7. package/dist/catalog/bindings/bedrock.d.ts +2 -0
  8. package/dist/catalog/bindings/bedrock.js +10 -0
  9. package/dist/catalog/bindings/google.d.ts +2 -0
  10. package/dist/catalog/bindings/google.js +12 -0
  11. package/dist/catalog/bindings/grok.d.ts +2 -0
  12. package/dist/catalog/bindings/grok.js +14 -0
  13. package/dist/catalog/bindings/index.d.ts +18 -0
  14. package/dist/catalog/bindings/index.js +36 -0
  15. package/dist/catalog/bindings/openai.d.ts +2 -0
  16. package/dist/catalog/bindings/openai.js +14 -0
  17. package/dist/catalog/bindings/types.d.ts +15 -0
  18. package/dist/catalog/bindings/types.js +11 -0
  19. package/dist/catalog/capabilities.d.ts +12 -0
  20. package/dist/catalog/capabilities.js +9 -0
  21. package/dist/catalog/flavors/anthropic.d.ts +3 -0
  22. package/dist/catalog/flavors/anthropic.js +26 -0
  23. package/dist/catalog/flavors/gemini.d.ts +3 -0
  24. package/dist/catalog/flavors/gemini.js +16 -0
  25. package/dist/catalog/flavors/index.d.ts +10 -0
  26. package/dist/catalog/flavors/index.js +10 -0
  27. package/dist/catalog/flavors/openai.d.ts +3 -0
  28. package/dist/catalog/flavors/openai.js +20 -0
  29. package/dist/catalog/flavors/types.d.ts +22 -0
  30. package/dist/catalog/flavors/types.js +2 -0
  31. package/dist/catalog/helpers.d.ts +5 -0
  32. package/dist/catalog/helpers.js +5 -0
  33. package/dist/catalog/index.d.ts +9 -0
  34. package/dist/catalog/index.js +8 -0
  35. package/dist/catalog/models/anthropic.d.ts +7 -0
  36. package/dist/catalog/models/anthropic.js +10 -0
  37. package/dist/catalog/models/google.d.ts +8 -0
  38. package/dist/catalog/models/google.js +11 -0
  39. package/dist/catalog/models/grok.d.ts +10 -0
  40. package/dist/catalog/models/grok.js +13 -0
  41. package/dist/catalog/models/index.d.ts +20 -0
  42. package/dist/catalog/models/index.js +19 -0
  43. package/dist/catalog/models/openai.d.ts +12 -0
  44. package/dist/catalog/models/openai.js +15 -0
  45. package/dist/catalog/models/types.d.ts +17 -0
  46. package/dist/catalog/models/types.js +45 -0
  47. package/dist/catalog/providers/anthropic.d.ts +2 -0
  48. package/dist/catalog/providers/anthropic.js +13 -0
  49. package/dist/catalog/providers/bedrock.d.ts +2 -0
  50. package/dist/catalog/providers/bedrock.js +20 -0
  51. package/dist/catalog/providers/google.d.ts +2 -0
  52. package/dist/catalog/providers/google.js +12 -0
  53. package/dist/catalog/providers/grok.d.ts +2 -0
  54. package/dist/catalog/providers/grok.js +12 -0
  55. package/dist/catalog/providers/index.d.ts +17 -0
  56. package/dist/catalog/providers/index.js +28 -0
  57. package/dist/catalog/providers/openai.d.ts +2 -0
  58. package/dist/catalog/providers/openai.js +12 -0
  59. package/dist/catalog/providers/types.d.ts +32 -0
  60. package/dist/catalog/providers/types.js +2 -0
  61. package/dist/catalog/tiers.d.ts +12 -0
  62. package/dist/catalog/tiers.js +9 -0
  63. package/dist/config.d.ts +3 -0
  64. package/dist/config.js +11 -0
  65. package/dist/constants.d.ts +31 -0
  66. package/dist/constants.js +11 -0
  67. package/dist/index.d.ts +20 -0
  68. package/dist/index.js +20 -0
  69. package/dist/parse.d.ts +2 -0
  70. package/dist/parse.js +12 -0
  71. package/dist/providers/index.d.ts +3 -0
  72. package/dist/providers/index.js +3 -0
  73. package/dist/result.d.ts +18 -0
  74. package/dist/result.js +9 -0
  75. package/dist/schemas/access-token.d.ts +32 -0
  76. package/dist/schemas/access-token.js +20 -0
  77. package/dist/schemas/account-invitation.d.ts +39 -0
  78. package/dist/schemas/account-invitation.js +20 -0
  79. package/dist/schemas/account-member.d.ts +19 -0
  80. package/dist/schemas/account-member.js +15 -0
  81. package/dist/schemas/account.d.ts +45 -0
  82. package/dist/schemas/account.js +25 -0
  83. package/dist/schemas/api-key.d.ts +44 -0
  84. package/dist/schemas/api-key.js +17 -0
  85. package/dist/schemas/app.d.ts +185 -0
  86. package/dist/schemas/app.js +41 -0
  87. package/dist/schemas/budget.d.ts +10 -0
  88. package/dist/schemas/budget.js +9 -0
  89. package/dist/schemas/cli-login.d.ts +42 -0
  90. package/dist/schemas/cli-login.js +25 -0
  91. package/dist/schemas/discovery.d.ts +7 -0
  92. package/dist/schemas/discovery.js +6 -0
  93. package/dist/schemas/error-codes.d.ts +154 -0
  94. package/dist/schemas/error-codes.js +62 -0
  95. package/dist/schemas/error.d.ts +20 -0
  96. package/dist/schemas/error.js +12 -0
  97. package/dist/schemas/provider.d.ts +11 -0
  98. package/dist/schemas/provider.js +4 -0
  99. package/dist/schemas/proxy-response.d.ts +49 -0
  100. package/dist/schemas/proxy-response.js +15 -0
  101. package/dist/schemas/sponsored-api-key.d.ts +65 -0
  102. package/dist/schemas/sponsored-api-key.js +30 -0
  103. package/dist/schemas/usage.d.ts +25 -0
  104. package/dist/schemas/usage.js +19 -0
  105. package/dist/schemas/user.d.ts +20 -0
  106. package/dist/schemas/user.js +13 -0
  107. package/package.json +60 -0
@@ -0,0 +1,45 @@
1
+ const slugify = (s) => s.toLowerCase().replace(/\./g, '-').replace(/\s+/g, '-');
2
+ export const defineFamily = (prefix, entries) => {
3
+ const out = {};
4
+ for (const key in entries) {
5
+ const [tiers, capabilities] = entries[key];
6
+ const displayName = `${prefix}${humanize(key)}`;
7
+ out[key] = {
8
+ __tag: 'model',
9
+ slug: slugify(displayName),
10
+ displayName,
11
+ tiers,
12
+ capabilities,
13
+ };
14
+ }
15
+ return out;
16
+ };
17
+ export const humanize = (key) => {
18
+ const parts = key.split('_').filter((p) => p.length > 0);
19
+ const out = [];
20
+ let numBuf = [];
21
+ const flush = () => {
22
+ if (numBuf.length) {
23
+ out.push(numBuf.join('.'));
24
+ numBuf = [];
25
+ }
26
+ };
27
+ for (const p of parts) {
28
+ if (/^\d+$/.test(p))
29
+ numBuf.push(p);
30
+ else {
31
+ flush();
32
+ out.push(p);
33
+ }
34
+ }
35
+ flush();
36
+ return out.join(' ');
37
+ };
38
+ export const model = (displayName, tiers, capabilities) => ({
39
+ __tag: 'model',
40
+ slug: slugify(displayName),
41
+ displayName,
42
+ tiers,
43
+ capabilities,
44
+ });
45
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,2 @@
1
+ export declare const anthropic: import("./types.js").Provider;
2
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { defineProvider } from './types.js';
2
+ export const anthropic = defineProvider({
3
+ displayName: 'Anthropic',
4
+ color: '#d97706',
5
+ logoUrl: '/providers/anthropic.svg',
6
+ logoStyle: 'symbol',
7
+ flavor: 'anthropic',
8
+ baseUrl: 'https://api.anthropic.com',
9
+ auth: { kind: 'header', name: 'x-api-key' },
10
+ defaultHeaders: { 'anthropic-version': '2023-06-01' },
11
+ keyPrefixHints: ['sk-ant-'],
12
+ });
13
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1,2 @@
1
+ export declare const bedrock: import("./types.js").Provider;
2
+ //# sourceMappingURL=bedrock.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { defineProvider } from './types.js';
2
+ const adaptToBedrock = (_flavorPath, body, model) => {
3
+ const { model: _, ...rest } = body;
4
+ return {
5
+ path: `/model/${encodeURIComponent(model)}/invoke`,
6
+ body: { ...rest, anthropic_version: 'bedrock-2023-05-31' },
7
+ };
8
+ };
9
+ export const bedrock = defineProvider({
10
+ displayName: 'Bedrock',
11
+ color: '#ff9900',
12
+ logoUrl: '/providers/bedrock.svg',
13
+ logoStyle: 'symbol',
14
+ flavor: 'anthropic',
15
+ baseUrl: 'https://bedrock-runtime.us-east-1.amazonaws.com',
16
+ auth: { kind: 'sigv4', service: 'bedrock', defaultRegion: 'us-east-1' },
17
+ keyPrefixHints: ['AKIA'],
18
+ adaptRequest: adaptToBedrock,
19
+ });
20
+ //# sourceMappingURL=bedrock.js.map
@@ -0,0 +1,2 @@
1
+ export declare const google: import("./types.js").Provider;
2
+ //# sourceMappingURL=google.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { defineProvider } from './types.js';
2
+ export const google = defineProvider({
3
+ displayName: 'Gemini',
4
+ color: '#4285f4',
5
+ logoUrl: '/providers/google.svg',
6
+ logoStyle: 'symbol',
7
+ flavor: 'gemini',
8
+ baseUrl: 'https://generativelanguage.googleapis.com',
9
+ auth: { kind: 'query', param: 'key' },
10
+ keyPrefixHints: ['AIza'],
11
+ });
12
+ //# sourceMappingURL=google.js.map
@@ -0,0 +1,2 @@
1
+ export declare const grok: import("./types.js").Provider;
2
+ //# sourceMappingURL=grok.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { defineProvider } from './types.js';
2
+ export const grok = defineProvider({
3
+ displayName: 'Grok',
4
+ color: '#000000',
5
+ logoUrl: '/providers/grok.svg',
6
+ logoStyle: 'symbol',
7
+ flavor: 'openai',
8
+ baseUrl: 'https://api.x.ai',
9
+ auth: { kind: 'header', name: 'authorization', format: (key) => `Bearer ${key}` },
10
+ keyPrefixHints: ['xai-'],
11
+ });
12
+ //# sourceMappingURL=grok.js.map
@@ -0,0 +1,17 @@
1
+ import type { Provider } from './types.js';
2
+ export { type Provider, type ProviderAuth, defineProvider } from './types.js';
3
+ export declare const PROVIDERS: {
4
+ readonly anthropic: Provider;
5
+ readonly openai: Provider;
6
+ readonly google: Provider;
7
+ readonly grok: Provider;
8
+ readonly bedrock: Provider;
9
+ };
10
+ export type ProviderId = keyof typeof PROVIDERS;
11
+ export declare const PROVIDER_IDS: [ProviderId, ...ProviderId[]];
12
+ export declare const providerName: (p: Provider) => ProviderId;
13
+ export declare const getProvider: (id: ProviderId) => Provider;
14
+ export declare const tryGetProvider: (id: string) => Provider | null;
15
+ export declare const listProviders: () => readonly Provider[];
16
+ export declare const guessProviderFromKey: (apiKey: string) => ProviderId | null;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,28 @@
1
+ import { anthropic } from './anthropic.js';
2
+ import { openai } from './openai.js';
3
+ import { google } from './google.js';
4
+ import { grok } from './grok.js';
5
+ import { bedrock } from './bedrock.js';
6
+ export { defineProvider } from './types.js';
7
+ export const PROVIDERS = {
8
+ anthropic,
9
+ openai,
10
+ google,
11
+ grok,
12
+ bedrock,
13
+ };
14
+ export const PROVIDER_IDS = Object.keys(PROVIDERS);
15
+ const PROVIDER_NAME = new Map(Object.entries(PROVIDERS).map(([k, v]) => [v, k]));
16
+ export const providerName = (p) => PROVIDER_NAME.get(p);
17
+ export const getProvider = (id) => PROVIDERS[id];
18
+ export const tryGetProvider = (id) => PROVIDERS[id] ?? null;
19
+ export const listProviders = () => Object.values(PROVIDERS);
20
+ export const guessProviderFromKey = (apiKey) => {
21
+ for (const id of PROVIDER_IDS) {
22
+ const hints = PROVIDERS[id].keyPrefixHints;
23
+ if (hints?.some((prefix) => apiKey.startsWith(prefix)))
24
+ return id;
25
+ }
26
+ return null;
27
+ };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export declare const openai: import("./types.js").Provider;
2
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { defineProvider } from './types.js';
2
+ export const openai = defineProvider({
3
+ displayName: 'OpenAI',
4
+ color: '#10a37f',
5
+ logoUrl: '/providers/openai.svg',
6
+ logoStyle: 'symbol',
7
+ flavor: 'openai',
8
+ baseUrl: 'https://api.openai.com',
9
+ auth: { kind: 'header', name: 'authorization', format: (key) => `Bearer ${key}` },
10
+ keyPrefixHints: ['sk-proj-', 'sk-'],
11
+ });
12
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1,32 @@
1
+ import type { FlavorId } from '../flavors/index.js';
2
+ export type ProviderAuth = {
3
+ readonly kind: 'header';
4
+ readonly name: string;
5
+ readonly format?: (key: string) => string;
6
+ } | {
7
+ readonly kind: 'query';
8
+ readonly param: string;
9
+ } | {
10
+ readonly kind: 'sigv4';
11
+ readonly service: string;
12
+ readonly defaultRegion: string;
13
+ };
14
+ export type RequestShape = {
15
+ readonly path: string;
16
+ readonly body: Readonly<Record<string, unknown>>;
17
+ };
18
+ export type Provider = {
19
+ readonly __tag: 'provider';
20
+ readonly displayName: string;
21
+ readonly color: string;
22
+ readonly logoUrl: string;
23
+ readonly logoStyle: 'symbol' | 'wordmark';
24
+ readonly flavor: FlavorId;
25
+ readonly baseUrl: string;
26
+ readonly auth: ProviderAuth;
27
+ readonly defaultHeaders?: Readonly<Record<string, string>>;
28
+ readonly keyPrefixHints?: readonly string[];
29
+ readonly adaptRequest?: (flavorPath: string, flavorBody: Readonly<Record<string, unknown>>, vendorModelName: string) => RequestShape;
30
+ };
31
+ export declare const defineProvider: <T extends Provider>(p: Omit<T, "__tag">) => T;
32
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export const defineProvider = (p) => ({ __tag: 'provider', ...p });
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,12 @@
1
+ export type Tier = {
2
+ readonly __tag: 'tier';
3
+ };
4
+ export declare const TIERS: {
5
+ readonly cheap: Tier;
6
+ readonly fast: Tier;
7
+ readonly smart: Tier;
8
+ readonly reasoning: Tier;
9
+ };
10
+ export type TierId = keyof typeof TIERS;
11
+ export declare const tierName: (t: Tier) => TierId;
12
+ //# sourceMappingURL=tiers.d.ts.map
@@ -0,0 +1,9 @@
1
+ export const TIERS = {
2
+ cheap: {},
3
+ fast: {},
4
+ smart: {},
5
+ reasoning: {},
6
+ };
7
+ const TIER_NAME = new Map(Object.entries(TIERS).map(([k, v]) => [v, k]));
8
+ export const tierName = (t) => TIER_NAME.get(t);
9
+ //# sourceMappingURL=tiers.js.map
@@ -0,0 +1,3 @@
1
+ export declare const requireEnv: (name: string, fallback?: string) => string;
2
+ export declare const optionalEnv: (name: string) => string | undefined;
3
+ //# sourceMappingURL=config.d.ts.map
package/dist/config.js ADDED
@@ -0,0 +1,11 @@
1
+ const isProduction = () => process.env['NODE_ENV'] === 'production';
2
+ export const requireEnv = (name, fallback) => {
3
+ const value = process.env[name];
4
+ if (value)
5
+ return value;
6
+ if (fallback && !isProduction())
7
+ return fallback;
8
+ throw new Error(`Missing required environment variable: ${name}`);
9
+ };
10
+ export const optionalEnv = (name) => process.env[name];
11
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,31 @@
1
+ export declare const rateLimits: {
2
+ readonly login: {
3
+ readonly maxRequests: 5;
4
+ readonly windowSeconds: 900;
5
+ readonly keyPrefix: "login";
6
+ };
7
+ readonly register: {
8
+ readonly maxRequests: 3;
9
+ readonly windowSeconds: 3600;
10
+ readonly keyPrefix: "register";
11
+ };
12
+ readonly token: {
13
+ readonly maxRequests: 10;
14
+ readonly windowSeconds: 3600;
15
+ readonly keyPrefix: "token";
16
+ };
17
+ readonly keys: {
18
+ readonly maxRequests: 20;
19
+ readonly windowSeconds: 3600;
20
+ readonly keyPrefix: "keys";
21
+ };
22
+ readonly apps: {
23
+ readonly maxRequests: 10;
24
+ readonly windowSeconds: 3600;
25
+ readonly keyPrefix: "apps";
26
+ };
27
+ };
28
+ export declare const ACCESS_TOKEN_LIFETIME_DAYS = 30;
29
+ export declare const OAUTH_CODE_TTL_SECONDS = 300;
30
+ export declare const TOKEN_CACHE_TTL_SECONDS = 300;
31
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,11 @@
1
+ export const rateLimits = {
2
+ login: { maxRequests: 5, windowSeconds: 900, keyPrefix: 'login' },
3
+ register: { maxRequests: 3, windowSeconds: 3600, keyPrefix: 'register' },
4
+ token: { maxRequests: 10, windowSeconds: 3600, keyPrefix: 'token' },
5
+ keys: { maxRequests: 20, windowSeconds: 3600, keyPrefix: 'keys' },
6
+ apps: { maxRequests: 10, windowSeconds: 3600, keyPrefix: 'apps' },
7
+ };
8
+ export const ACCESS_TOKEN_LIFETIME_DAYS = 30;
9
+ export const OAUTH_CODE_TTL_SECONDS = 300;
10
+ export const TOKEN_CACHE_TTL_SECONDS = 300;
11
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,20 @@
1
+ export { type Result, ok, err, type AppError } from './result.js';
2
+ export { providerSchema, type Provider, } from './schemas/provider.js';
3
+ export { userSchema, createUserRequest, userResponse, type User, type CreateUserRequest, type UserResponse, } from './schemas/user.js';
4
+ export { accountTypeSchema, accountSchema, createAccountRequest, updateAccountRequest, type AccountType, type Account, type CreateAccountRequest, type UpdateAccountRequest, } from './schemas/account.js';
5
+ export { accountRoleSchema, accountMemberSchema, hasAtLeastRole, type AccountRole, type AccountMember, } from './schemas/account-member.js';
6
+ export { accountInvitationSchema, createInvitationRequest, invitationWithClaimUrl, type AccountInvitation, type CreateInvitationRequest, type InvitationWithClaimUrl, } from './schemas/account-invitation.js';
7
+ export { appSchema, createAppRequest, updateAppRequest, appResponse, modelStrategySchema, tierSchema, type App, type CreateAppRequest, type UpdateAppRequest, type AppResponse, type ModelStrategy, type RequiredTier, } from './schemas/app.js';
8
+ export { apiKeySchema, addApiKeyRequest, apiKeyResponse, type ApiKey, type AddApiKeyRequest, type ApiKeyResponse, } from './schemas/api-key.js';
9
+ export { sponsoredApiKeySchema, addSponsoredApiKeyRequest, sponsoredApiKeyResponse, sponsoredKeyConsumerSchema, type SponsoredApiKey, type AddSponsoredApiKeyRequest, type SponsoredApiKeyResponse, type SponsoredKeyConsumer, } from './schemas/sponsored-api-key.js';
10
+ export { budgetSchema, type Budget, DEBT_TOLERANCE_USD, isBudgetAvailable, remainingBudget, } from './schemas/budget.js';
11
+ export { accessTokenSchema, authorizeAppRequest, updateConnectionRequest, connectionResponse, type AccessToken, type AuthorizeAppRequest, type UpdateConnectionRequest, type ConnectionResponse, } from './schemas/access-token.js';
12
+ export { usageLogSchema, type UsageLog, PLATFORM_FEE_RATE, calculatePlatformFee, calculateTotalDebit, } from './schemas/usage.js';
13
+ export { errorResponseSchema, errorSourceSchema, proxyErrorCodes, providerErrorCodes, apiErrorCodes, type ErrorResponse, type ErrorSource, type ProxyErrorCode, type ProviderErrorCode, type ApiErrorCode, type ErrorCode, } from './schemas/error.js';
14
+ export { proxyUsageSchema, proxySuccessSchema, proxyResponseSchema, type ProxyUsage, type ProxySuccess, type ProxyResponse, } from './schemas/proxy-response.js';
15
+ export { discoverySchema, type Discovery, } from './schemas/discovery.js';
16
+ export { CliLoopbackHost, cliLoginParamsSchema, cliLoginMintRequestSchema, cliLoginMintResponseSchema, cliLoginExchangeRequestSchema, cliLoginExchangeResponseSchema, type CliLoginParams, type CliLoginMintRequest, type CliLoginMintResponse, type CliLoginExchangeRequest, type CliLoginExchangeResponse, } from './schemas/cli-login.js';
17
+ export { requireEnv, optionalEnv } from './config.js';
18
+ export { safeParseJson } from './parse.js';
19
+ export { rateLimits, ACCESS_TOKEN_LIFETIME_DAYS, OAUTH_CODE_TTL_SECONDS, TOKEN_CACHE_TTL_SECONDS } from './constants.js';
20
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ export { ok, err } from './result.js';
2
+ export { providerSchema, } from './schemas/provider.js';
3
+ export { userSchema, createUserRequest, userResponse, } from './schemas/user.js';
4
+ export { accountTypeSchema, accountSchema, createAccountRequest, updateAccountRequest, } from './schemas/account.js';
5
+ export { accountRoleSchema, accountMemberSchema, hasAtLeastRole, } from './schemas/account-member.js';
6
+ export { accountInvitationSchema, createInvitationRequest, invitationWithClaimUrl, } from './schemas/account-invitation.js';
7
+ export { appSchema, createAppRequest, updateAppRequest, appResponse, modelStrategySchema, tierSchema, } from './schemas/app.js';
8
+ export { apiKeySchema, addApiKeyRequest, apiKeyResponse, } from './schemas/api-key.js';
9
+ export { sponsoredApiKeySchema, addSponsoredApiKeyRequest, sponsoredApiKeyResponse, sponsoredKeyConsumerSchema, } from './schemas/sponsored-api-key.js';
10
+ export { budgetSchema, DEBT_TOLERANCE_USD, isBudgetAvailable, remainingBudget, } from './schemas/budget.js';
11
+ export { accessTokenSchema, authorizeAppRequest, updateConnectionRequest, connectionResponse, } from './schemas/access-token.js';
12
+ export { usageLogSchema, PLATFORM_FEE_RATE, calculatePlatformFee, calculateTotalDebit, } from './schemas/usage.js';
13
+ export { errorResponseSchema, errorSourceSchema, proxyErrorCodes, providerErrorCodes, apiErrorCodes, } from './schemas/error.js';
14
+ export { proxyUsageSchema, proxySuccessSchema, proxyResponseSchema, } from './schemas/proxy-response.js';
15
+ export { discoverySchema, } from './schemas/discovery.js';
16
+ export { CliLoopbackHost, cliLoginParamsSchema, cliLoginMintRequestSchema, cliLoginMintResponseSchema, cliLoginExchangeRequestSchema, cliLoginExchangeResponseSchema, } from './schemas/cli-login.js';
17
+ export { requireEnv, optionalEnv } from './config.js';
18
+ export { safeParseJson } from './parse.js';
19
+ export { rateLimits, ACCESS_TOKEN_LIFETIME_DAYS, OAUTH_CODE_TTL_SECONDS, TOKEN_CACHE_TTL_SECONDS } from './constants.js';
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export declare const safeParseJson: (text: string) => Record<string, unknown> | null;
2
+ //# sourceMappingURL=parse.d.ts.map
package/dist/parse.js ADDED
@@ -0,0 +1,12 @@
1
+ export const safeParseJson = (text) => {
2
+ try {
3
+ const parsed = JSON.parse(text);
4
+ if (typeof parsed === 'object' && parsed !== null)
5
+ return parsed;
6
+ return null;
7
+ }
8
+ catch {
9
+ return null;
10
+ }
11
+ };
12
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1,3 @@
1
+ export { PROVIDERS, PROVIDER_IDS, type Provider, type ProviderAuth, type ProviderId, getProvider, tryGetProvider, listProviders, providerName, guessProviderFromKey, } from '../catalog/providers/index.js';
2
+ export { type UsageInfo, type UsageExtractor, type RequestedModelExtractor, type ErrorBody, type FlavorHandler, type FlavorId, getFlavor, } from '../catalog/flavors/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { PROVIDERS, PROVIDER_IDS, getProvider, tryGetProvider, listProviders, providerName, guessProviderFromKey, } from '../catalog/providers/index.js';
2
+ export { getFlavor, } from '../catalog/flavors/index.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ import type { ErrorCode } from './schemas/error-codes.js';
2
+ export type Result<T, E = AppError> = {
3
+ readonly ok: true;
4
+ readonly data: T;
5
+ } | {
6
+ readonly ok: false;
7
+ readonly error: E;
8
+ };
9
+ export type AppError = {
10
+ readonly code: ErrorCode;
11
+ readonly message: string;
12
+ readonly status: number;
13
+ readonly source?: 'proxy' | 'provider';
14
+ readonly details?: Record<string, unknown>;
15
+ };
16
+ export declare const ok: <T>(data: T) => Result<T, never>;
17
+ export declare const err: <E = AppError>(error: E) => Result<never, E>;
18
+ //# sourceMappingURL=result.d.ts.map
package/dist/result.js ADDED
@@ -0,0 +1,9 @@
1
+ export const ok = (data) => ({
2
+ ok: true,
3
+ data,
4
+ });
5
+ export const err = (error) => ({
6
+ ok: false,
7
+ error,
8
+ });
9
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod';
2
+ export declare const accessTokenSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ userId: z.ZodString;
5
+ appId: z.ZodString;
6
+ tokenHash: z.ZodString;
7
+ budgetLimit: z.ZodNumber;
8
+ budgetSpent: z.ZodDefault<z.ZodNumber>;
9
+ isRevoked: z.ZodDefault<z.ZodBoolean>;
10
+ createdAt: z.ZodString;
11
+ }, z.core.$strip>;
12
+ export type AccessToken = z.infer<typeof accessTokenSchema>;
13
+ export declare const authorizeAppRequest: z.ZodObject<{
14
+ appId: z.ZodString;
15
+ budgetLimit: z.ZodNumber;
16
+ }, z.core.$strip>;
17
+ export type AuthorizeAppRequest = z.infer<typeof authorizeAppRequest>;
18
+ export declare const updateConnectionRequest: z.ZodObject<{
19
+ budgetLimit: z.ZodOptional<z.ZodNumber>;
20
+ }, z.core.$strip>;
21
+ export type UpdateConnectionRequest = z.infer<typeof updateConnectionRequest>;
22
+ export declare const connectionResponse: z.ZodObject<{
23
+ id: z.ZodString;
24
+ createdAt: z.ZodString;
25
+ userId: z.ZodString;
26
+ appId: z.ZodString;
27
+ budgetLimit: z.ZodNumber;
28
+ budgetSpent: z.ZodDefault<z.ZodNumber>;
29
+ isRevoked: z.ZodDefault<z.ZodBoolean>;
30
+ }, z.core.$strip>;
31
+ export type ConnectionResponse = z.infer<typeof connectionResponse>;
32
+ //# sourceMappingURL=access-token.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+ export const accessTokenSchema = z.object({
3
+ id: z.string().uuid(),
4
+ userId: z.string().uuid(),
5
+ appId: z.string().uuid(),
6
+ tokenHash: z.string(),
7
+ budgetLimit: z.number().positive(),
8
+ budgetSpent: z.number().default(0),
9
+ isRevoked: z.boolean().default(false),
10
+ createdAt: z.string().datetime(),
11
+ });
12
+ export const authorizeAppRequest = z.object({
13
+ appId: z.string().uuid(),
14
+ budgetLimit: z.number().positive(),
15
+ });
16
+ export const updateConnectionRequest = z.object({
17
+ budgetLimit: z.number().positive().optional(),
18
+ });
19
+ export const connectionResponse = accessTokenSchema.omit({ tokenHash: true });
20
+ //# sourceMappingURL=access-token.js.map
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ export declare const accountInvitationSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ accountId: z.ZodString;
5
+ email: z.ZodString;
6
+ role: z.ZodEnum<{
7
+ owner: "owner";
8
+ member: "member";
9
+ }>;
10
+ invitedByUserId: z.ZodString;
11
+ expiresAt: z.ZodString;
12
+ acceptedAt: z.ZodNullable<z.ZodString>;
13
+ createdAt: z.ZodString;
14
+ }, z.core.$strip>;
15
+ export type AccountInvitation = z.infer<typeof accountInvitationSchema>;
16
+ export declare const createInvitationRequest: z.ZodObject<{
17
+ email: z.ZodString;
18
+ role: z.ZodDefault<z.ZodEnum<{
19
+ owner: "owner";
20
+ member: "member";
21
+ }>>;
22
+ }, z.core.$strip>;
23
+ export type CreateInvitationRequest = z.infer<typeof createInvitationRequest>;
24
+ export declare const invitationWithClaimUrl: z.ZodObject<{
25
+ id: z.ZodString;
26
+ accountId: z.ZodString;
27
+ email: z.ZodString;
28
+ role: z.ZodEnum<{
29
+ owner: "owner";
30
+ member: "member";
31
+ }>;
32
+ invitedByUserId: z.ZodString;
33
+ expiresAt: z.ZodString;
34
+ acceptedAt: z.ZodNullable<z.ZodString>;
35
+ createdAt: z.ZodString;
36
+ claimUrl: z.ZodString;
37
+ }, z.core.$strip>;
38
+ export type InvitationWithClaimUrl = z.infer<typeof invitationWithClaimUrl>;
39
+ //# sourceMappingURL=account-invitation.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+ import { accountRoleSchema } from './account-member.js';
3
+ export const accountInvitationSchema = z.object({
4
+ id: z.string().uuid(),
5
+ accountId: z.string().uuid(),
6
+ email: z.string().email(),
7
+ role: accountRoleSchema,
8
+ invitedByUserId: z.string().uuid(),
9
+ expiresAt: z.string().datetime(),
10
+ acceptedAt: z.string().datetime().nullable(),
11
+ createdAt: z.string().datetime(),
12
+ });
13
+ export const createInvitationRequest = z.object({
14
+ email: z.string().email(),
15
+ role: accountRoleSchema.default('member'),
16
+ });
17
+ export const invitationWithClaimUrl = accountInvitationSchema.extend({
18
+ claimUrl: z.string().url(),
19
+ });
20
+ //# sourceMappingURL=account-invitation.js.map
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ export declare const accountRoleSchema: z.ZodEnum<{
3
+ owner: "owner";
4
+ member: "member";
5
+ }>;
6
+ export type AccountRole = z.infer<typeof accountRoleSchema>;
7
+ export declare const accountMemberSchema: z.ZodObject<{
8
+ accountId: z.ZodString;
9
+ userId: z.ZodString;
10
+ role: z.ZodEnum<{
11
+ owner: "owner";
12
+ member: "member";
13
+ }>;
14
+ monthlyCapUsd: z.ZodNullable<z.ZodNumber>;
15
+ joinedAt: z.ZodString;
16
+ }, z.core.$strip>;
17
+ export type AccountMember = z.infer<typeof accountMemberSchema>;
18
+ export declare const hasAtLeastRole: (actual: AccountRole, required: AccountRole) => boolean;
19
+ //# sourceMappingURL=account-member.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ export const accountRoleSchema = z.enum(['owner', 'member']);
3
+ export const accountMemberSchema = z.object({
4
+ accountId: z.string().uuid(),
5
+ userId: z.string().uuid(),
6
+ role: accountRoleSchema,
7
+ monthlyCapUsd: z.number().nullable(),
8
+ joinedAt: z.string().datetime(),
9
+ });
10
+ const roleRank = {
11
+ member: 0,
12
+ owner: 1,
13
+ };
14
+ export const hasAtLeastRole = (actual, required) => roleRank[actual] >= roleRank[required];
15
+ //# sourceMappingURL=account-member.js.map
@@ -0,0 +1,45 @@
1
+ import { z } from 'zod';
2
+ export declare const accountTypeSchema: z.ZodEnum<{
3
+ personal: "personal";
4
+ business: "business";
5
+ }>;
6
+ export type AccountType = z.infer<typeof accountTypeSchema>;
7
+ export declare const poolResetPeriodSchema: z.ZodNullable<z.ZodEnum<{
8
+ monthly: "monthly";
9
+ }>>;
10
+ export type PoolResetPeriod = z.infer<typeof poolResetPeriodSchema>;
11
+ export declare const accountSchema: z.ZodObject<{
12
+ id: z.ZodString;
13
+ type: z.ZodEnum<{
14
+ personal: "personal";
15
+ business: "business";
16
+ }>;
17
+ name: z.ZodString;
18
+ ownerUserId: z.ZodString;
19
+ poolBudgetLimitUsd: z.ZodNullable<z.ZodNumber>;
20
+ poolBudgetSpentUsd: z.ZodDefault<z.ZodNumber>;
21
+ poolResetPeriod: z.ZodNullable<z.ZodEnum<{
22
+ monthly: "monthly";
23
+ }>>;
24
+ poolLastResetAt: z.ZodNullable<z.ZodString>;
25
+ deletedAt: z.ZodNullable<z.ZodString>;
26
+ createdAt: z.ZodString;
27
+ }, z.core.$strip>;
28
+ export type Account = z.infer<typeof accountSchema>;
29
+ export declare const createAccountRequest: z.ZodObject<{
30
+ type: z.ZodEnum<{
31
+ personal: "personal";
32
+ business: "business";
33
+ }>;
34
+ name: z.ZodString;
35
+ }, z.core.$strip>;
36
+ export type CreateAccountRequest = z.infer<typeof createAccountRequest>;
37
+ export declare const updateAccountRequest: z.ZodObject<{
38
+ name: z.ZodOptional<z.ZodString>;
39
+ poolBudgetLimitUsd: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
40
+ poolResetPeriod: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
41
+ monthly: "monthly";
42
+ }>>>;
43
+ }, z.core.$strip>;
44
+ export type UpdateAccountRequest = z.infer<typeof updateAccountRequest>;
45
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod';
2
+ export const accountTypeSchema = z.enum(['personal', 'business']);
3
+ export const poolResetPeriodSchema = z.enum(['monthly']).nullable();
4
+ export const accountSchema = z.object({
5
+ id: z.string().uuid(),
6
+ type: accountTypeSchema,
7
+ name: z.string().min(1).max(100),
8
+ ownerUserId: z.string().uuid(),
9
+ poolBudgetLimitUsd: z.number().nullable(),
10
+ poolBudgetSpentUsd: z.number().default(0),
11
+ poolResetPeriod: poolResetPeriodSchema,
12
+ poolLastResetAt: z.string().datetime().nullable(),
13
+ deletedAt: z.string().datetime().nullable(),
14
+ createdAt: z.string().datetime(),
15
+ });
16
+ export const createAccountRequest = z.object({
17
+ type: accountTypeSchema,
18
+ name: z.string().min(1).max(100),
19
+ });
20
+ export const updateAccountRequest = z.object({
21
+ name: z.string().min(1).max(100).optional(),
22
+ poolBudgetLimitUsd: z.number().nonnegative().nullable().optional(),
23
+ poolResetPeriod: poolResetPeriodSchema.optional(),
24
+ });
25
+ //# sourceMappingURL=account.js.map