@lightharu/krouter 1.8.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 (61) hide show
  1. package/LICENSE +679 -0
  2. package/README.md +238 -0
  3. package/dist-web/assets/index-CM4-0adf.css +1 -0
  4. package/dist-web/assets/index-DCslvfUR.js +139 -0
  5. package/dist-web/favicon.svg +9 -0
  6. package/dist-web/icon.svg +9 -0
  7. package/dist-web/index.html +19 -0
  8. package/out-server/main/kiroAuthSync.js +249 -0
  9. package/out-server/main/kproxy/certManager.js +262 -0
  10. package/out-server/main/kproxy/index.js +254 -0
  11. package/out-server/main/kproxy/mitmProxy.js +475 -0
  12. package/out-server/main/kproxy/types.js +23 -0
  13. package/out-server/main/proxy/accountPool.js +543 -0
  14. package/out-server/main/proxy/clientConfig.js +596 -0
  15. package/out-server/main/proxy/index.js +25 -0
  16. package/out-server/main/proxy/kiroApi.js +1996 -0
  17. package/out-server/main/proxy/logger.js +407 -0
  18. package/out-server/main/proxy/modelCatalog.js +75 -0
  19. package/out-server/main/proxy/promptCacheTracker.js +301 -0
  20. package/out-server/main/proxy/proxyServer.js +3543 -0
  21. package/out-server/main/proxy/selfSignedCert.js +179 -0
  22. package/out-server/main/proxy/systemProxy.js +250 -0
  23. package/out-server/main/proxy/tokenCounter.js +164 -0
  24. package/out-server/main/proxy/toolNameRegistry.js +57 -0
  25. package/out-server/main/proxy/translator.js +1084 -0
  26. package/out-server/main/proxy/types.js +3 -0
  27. package/out-server/main/registration/browser-identity.js +184 -0
  28. package/out-server/main/registration/chainProxy.js +349 -0
  29. package/out-server/main/registration/config.js +58 -0
  30. package/out-server/main/registration/email-service.js +801 -0
  31. package/out-server/main/registration/fingerprint.js +352 -0
  32. package/out-server/main/registration/http-utils.js +148 -0
  33. package/out-server/main/registration/jwe.js +74 -0
  34. package/out-server/main/registration/names.js +142 -0
  35. package/out-server/main/registration/proton-mail-window.js +339 -0
  36. package/out-server/main/registration/registrar.js +1715 -0
  37. package/out-server/main/registration/tlsClientPool.js +70 -0
  38. package/out-server/main/registration/xxtea.js +161 -0
  39. package/out-server/main/runtimePaths.js +19 -0
  40. package/out-server/main/utils/redact.js +95 -0
  41. package/out-server/server/index.js +1272 -0
  42. package/out-server/server/services/accountExtras.js +105 -0
  43. package/out-server/server/services/accountProfileHydration.js +95 -0
  44. package/out-server/server/services/authFlows.js +509 -0
  45. package/out-server/server/services/dashboardTunnel.js +315 -0
  46. package/out-server/server/services/diagnostics.js +326 -0
  47. package/out-server/server/services/kiroAccounts.js +431 -0
  48. package/out-server/server/services/kiroSettings.js +260 -0
  49. package/out-server/server/services/kproxyRuntime.js +264 -0
  50. package/out-server/server/services/localKiroCredentials.js +320 -0
  51. package/out-server/server/services/machineIdRuntime.js +327 -0
  52. package/out-server/server/services/protonBrowserRuntime.js +724 -0
  53. package/out-server/server/services/proxyRuntime.js +523 -0
  54. package/out-server/server/services/registrationRuntime.js +106 -0
  55. package/out-server/server/store.js +266 -0
  56. package/package.json +113 -0
  57. package/resources/tls-client-xgo-1.14.0-windows-amd64.dll +0 -0
  58. package/scripts/kiro-manager-cli.cjs +3 -0
  59. package/scripts/krouter-cli.cjs +509 -0
  60. package/src/renderer/src/assets/krouter-logo.svg +11 -0
  61. package/src/renderer/src/assets/krouter-mark.svg +9 -0
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.accountGetModels = accountGetModels;
4
+ exports.accountGetSubscriptions = accountGetSubscriptions;
5
+ exports.accountGetSubscriptionUrl = accountGetSubscriptionUrl;
6
+ exports.accountSetOverage = accountSetOverage;
7
+ const kiroApi_1 = require("../../main/proxy/kiroApi");
8
+ const modelCatalog_1 = require("../../main/proxy/modelCatalog");
9
+ function accountFromArgs(args, fallbackId) {
10
+ const [accessToken, , region, profileArn, machineId, provider, authMethod, accountId] = args;
11
+ if (!accessToken)
12
+ return null;
13
+ return {
14
+ id: accountId || fallbackId,
15
+ accessToken,
16
+ region: region || 'us-east-1',
17
+ profileArn,
18
+ machineId,
19
+ provider,
20
+ authMethod
21
+ };
22
+ }
23
+ async function accountGetModels(args) {
24
+ const account = accountFromArgs([args[0], undefined, args[1], args[2], args[3], args[4], args[5], args[6]], 'model-list-request');
25
+ if (!account)
26
+ return { success: false, error: 'Missing access token', models: [] };
27
+ try {
28
+ const models = await (0, kiroApi_1.fetchKiroModels)(account);
29
+ const output = models.map((model) => ({
30
+ id: model.modelId,
31
+ name: model.modelName,
32
+ description: model.description,
33
+ inputTypes: model.supportedInputTypes,
34
+ maxInputTokens: model.tokenLimits?.maxInputTokens,
35
+ maxOutputTokens: model.tokenLimits?.maxOutputTokens,
36
+ rateMultiplier: model.rateMultiplier,
37
+ rateUnit: model.rateUnit
38
+ }));
39
+ const seen = new Set(output.map((model) => String(model.id)));
40
+ for (const preset of modelCatalog_1.KIRO_PROXY_MODEL_PRESETS) {
41
+ if (!seen.has(preset.id)) {
42
+ seen.add(preset.id);
43
+ output.push({
44
+ id: preset.id,
45
+ name: preset.name,
46
+ description: preset.description,
47
+ inputTypes: preset.inputTypes,
48
+ maxInputTokens: preset.maxInputTokens,
49
+ maxOutputTokens: preset.maxOutputTokens,
50
+ rateMultiplier: undefined,
51
+ rateUnit: undefined
52
+ });
53
+ }
54
+ }
55
+ return {
56
+ success: true,
57
+ models: output
58
+ };
59
+ }
60
+ catch (error) {
61
+ return { success: false, error: error instanceof Error ? error.message : 'Failed to get models', models: [] };
62
+ }
63
+ }
64
+ async function accountGetSubscriptions(args) {
65
+ const account = accountFromArgs(args, 'subscription-request');
66
+ if (!account)
67
+ return { success: false, error: 'Missing access token', plans: [] };
68
+ try {
69
+ const result = await (0, kiroApi_1.fetchAvailableSubscriptions)(account);
70
+ if (result.subscriptionPlans)
71
+ return { success: true, plans: result.subscriptionPlans, disclaimer: result.disclaimer };
72
+ return { success: false, error: 'No subscription plans returned', plans: [] };
73
+ }
74
+ catch (error) {
75
+ return { success: false, error: error instanceof Error ? error.message : 'Failed to get subscriptions', plans: [] };
76
+ }
77
+ }
78
+ async function accountGetSubscriptionUrl(args) {
79
+ const account = accountFromArgs([args[0], undefined, args[2], args[3], args[4], args[5], args[6], args[7]], 'subscription-request');
80
+ if (!account)
81
+ return { success: false, error: 'Missing access token' };
82
+ try {
83
+ const result = await (0, kiroApi_1.fetchSubscriptionToken)(account, args[1]);
84
+ if (result.encodedVerificationUrl)
85
+ return { success: true, url: result.encodedVerificationUrl, status: result.status };
86
+ return { success: false, error: result.message || 'No subscription URL returned' };
87
+ }
88
+ catch (error) {
89
+ return { success: false, error: error instanceof Error ? error.message : 'Failed to get subscription URL' };
90
+ }
91
+ }
92
+ async function accountSetOverage(args) {
93
+ const overageStatus = args[1];
94
+ if (overageStatus !== 'ENABLED' && overageStatus !== 'DISABLED')
95
+ return { success: false, error: 'Invalid overage status' };
96
+ const account = accountFromArgs([args[0], undefined, args[2], args[3], args[4], args[5], args[6], args[7]], 'subscription-request');
97
+ if (!account)
98
+ return { success: false, error: 'Missing access token' };
99
+ try {
100
+ return await (0, kiroApi_1.setUserPreference)(account, overageStatus);
101
+ }
102
+ catch (error) {
103
+ return { success: false, error: error instanceof Error ? error.message : 'Failed to set overage' };
104
+ }
105
+ }
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hydrateAccountDataProfileArns = hydrateAccountDataProfileArns;
4
+ const kiroAccounts_1 = require("./kiroAccounts");
5
+ function shouldResolveProfileArn(account) {
6
+ const credentials = account.credentials || {};
7
+ const provider = String(credentials.provider || account.idp || '').trim().toLowerCase();
8
+ const authMethod = String(credentials.authMethod || '').trim().toLowerCase();
9
+ if (provider === 'builderid' || provider === 'builder_id')
10
+ return true;
11
+ if (provider === 'github' || provider === 'google')
12
+ return true;
13
+ if (authMethod === 'social')
14
+ return true;
15
+ if (authMethod === 'idc' || authMethod === 'external_idp')
16
+ return true;
17
+ if (provider.includes('enterprise') || provider.includes('iam') || provider.includes('idc') || provider.includes('sso')) {
18
+ return true;
19
+ }
20
+ return false;
21
+ }
22
+ async function ensureAccessToken(account) {
23
+ const credentials = account.credentials || {};
24
+ let accessToken = credentials.accessToken;
25
+ let changed = false;
26
+ const expiresAt = Number(credentials.expiresAt || 0);
27
+ const needsRefresh = Boolean(credentials.refreshToken) && (!accessToken || expiresAt < Date.now() + 300000);
28
+ if (!needsRefresh)
29
+ return { accessToken, changed };
30
+ const refresh = await (0, kiroAccounts_1.refreshTokenByMethod)({
31
+ refreshToken: credentials.refreshToken || '',
32
+ clientId: credentials.clientId,
33
+ clientSecret: credentials.clientSecret,
34
+ region: credentials.region || 'us-east-1',
35
+ authMethod: credentials.authMethod,
36
+ provider: credentials.provider || account.idp,
37
+ machineId: account.machineId
38
+ }).catch(() => null);
39
+ if (refresh?.success && refresh.accessToken) {
40
+ accessToken = refresh.accessToken;
41
+ credentials.accessToken = refresh.accessToken;
42
+ credentials.refreshToken = refresh.refreshToken || credentials.refreshToken;
43
+ credentials.expiresAt = Date.now() + (refresh.expiresIn || 3600) * 1000;
44
+ changed = true;
45
+ }
46
+ return { accessToken, changed };
47
+ }
48
+ async function hydrateAccountDataProfileArns(rawData) {
49
+ const accountData = rawData;
50
+ const accounts = Object.values(accountData.accounts || {});
51
+ let changed = false;
52
+ let resolvedCount = 0;
53
+ for (const account of accounts) {
54
+ const normalized = (0, kiroAccounts_1.normalizeProfileArn)(account.profileArn || account.credentials?.profileArn);
55
+ if (normalized) {
56
+ if (account.profileArn !== normalized) {
57
+ account.profileArn = normalized;
58
+ changed = true;
59
+ }
60
+ continue;
61
+ }
62
+ if (account.status && account.status !== 'active')
63
+ continue;
64
+ if (!account.credentials || !shouldResolveProfileArn(account))
65
+ continue;
66
+ const token = await ensureAccessToken(account);
67
+ if (token.changed)
68
+ changed = true;
69
+ if (!token.accessToken)
70
+ continue;
71
+ const profileArn = await (0, kiroAccounts_1.resolveStreamingProfileArn)({
72
+ accessToken: token.accessToken,
73
+ machineId: account.machineId,
74
+ region: account.credentials.region || 'us-east-1',
75
+ authMethod: account.credentials.authMethod,
76
+ provider: account.credentials.provider || account.idp
77
+ }).catch(() => undefined);
78
+ if (!profileArn)
79
+ continue;
80
+ let accountChanged = false;
81
+ if (account.profileArn !== profileArn) {
82
+ account.profileArn = profileArn;
83
+ accountChanged = true;
84
+ }
85
+ if (account.credentials.profileArn !== profileArn) {
86
+ account.credentials.profileArn = profileArn;
87
+ accountChanged = true;
88
+ }
89
+ if (accountChanged) {
90
+ changed = true;
91
+ resolvedCount++;
92
+ }
93
+ }
94
+ return { data: rawData, changed, resolvedCount };
95
+ }