@kervnet/opencode-kiro-auth 1.5.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 (106) hide show
  1. package/README.md +159 -0
  2. package/dist/constants.d.ts +24 -0
  3. package/dist/constants.js +55 -0
  4. package/dist/core/account/account-selector.d.ts +25 -0
  5. package/dist/core/account/account-selector.js +84 -0
  6. package/dist/core/account/usage-tracker.d.ts +17 -0
  7. package/dist/core/account/usage-tracker.js +39 -0
  8. package/dist/core/auth/auth-handler.d.ts +15 -0
  9. package/dist/core/auth/auth-handler.js +43 -0
  10. package/dist/core/auth/idc-auth-method.d.ts +17 -0
  11. package/dist/core/auth/idc-auth-method.js +200 -0
  12. package/dist/core/auth/token-refresher.d.ts +22 -0
  13. package/dist/core/auth/token-refresher.js +53 -0
  14. package/dist/core/index.d.ts +9 -0
  15. package/dist/core/index.js +9 -0
  16. package/dist/core/request/error-handler.d.ts +30 -0
  17. package/dist/core/request/error-handler.js +113 -0
  18. package/dist/core/request/request-handler.d.ts +27 -0
  19. package/dist/core/request/request-handler.js +199 -0
  20. package/dist/core/request/response-handler.d.ts +5 -0
  21. package/dist/core/request/response-handler.js +61 -0
  22. package/dist/core/request/retry-strategy.d.ts +18 -0
  23. package/dist/core/request/retry-strategy.js +28 -0
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.js +1 -0
  26. package/dist/infrastructure/database/account-cache.d.ts +14 -0
  27. package/dist/infrastructure/database/account-cache.js +44 -0
  28. package/dist/infrastructure/database/account-repository.d.ts +12 -0
  29. package/dist/infrastructure/database/account-repository.js +64 -0
  30. package/dist/infrastructure/index.d.ts +7 -0
  31. package/dist/infrastructure/index.js +7 -0
  32. package/dist/infrastructure/transformers/event-stream-parser.d.ts +7 -0
  33. package/dist/infrastructure/transformers/event-stream-parser.js +115 -0
  34. package/dist/infrastructure/transformers/history-builder.d.ts +5 -0
  35. package/dist/infrastructure/transformers/history-builder.js +171 -0
  36. package/dist/infrastructure/transformers/message-transformer.d.ts +6 -0
  37. package/dist/infrastructure/transformers/message-transformer.js +102 -0
  38. package/dist/infrastructure/transformers/tool-call-parser.d.ts +4 -0
  39. package/dist/infrastructure/transformers/tool-call-parser.js +45 -0
  40. package/dist/infrastructure/transformers/tool-transformer.d.ts +2 -0
  41. package/dist/infrastructure/transformers/tool-transformer.js +19 -0
  42. package/dist/kiro/auth.d.ts +4 -0
  43. package/dist/kiro/auth.js +25 -0
  44. package/dist/kiro/oauth-idc.d.ts +24 -0
  45. package/dist/kiro/oauth-idc.js +151 -0
  46. package/dist/plugin/accounts.d.ts +29 -0
  47. package/dist/plugin/accounts.js +235 -0
  48. package/dist/plugin/auth-page.d.ts +3 -0
  49. package/dist/plugin/auth-page.js +573 -0
  50. package/dist/plugin/cli.d.ts +8 -0
  51. package/dist/plugin/cli.js +103 -0
  52. package/dist/plugin/config/index.d.ts +3 -0
  53. package/dist/plugin/config/index.js +2 -0
  54. package/dist/plugin/config/loader.d.ts +6 -0
  55. package/dist/plugin/config/loader.js +129 -0
  56. package/dist/plugin/config/schema.d.ts +56 -0
  57. package/dist/plugin/config/schema.js +36 -0
  58. package/dist/plugin/errors.d.ts +17 -0
  59. package/dist/plugin/errors.js +34 -0
  60. package/dist/plugin/health.d.ts +1 -0
  61. package/dist/plugin/health.js +9 -0
  62. package/dist/plugin/image-handler.d.ts +14 -0
  63. package/dist/plugin/image-handler.js +64 -0
  64. package/dist/plugin/logger.d.ts +8 -0
  65. package/dist/plugin/logger.js +63 -0
  66. package/dist/plugin/models.d.ts +1 -0
  67. package/dist/plugin/models.js +8 -0
  68. package/dist/plugin/request.d.ts +2 -0
  69. package/dist/plugin/request.js +239 -0
  70. package/dist/plugin/response.d.ts +3 -0
  71. package/dist/plugin/response.js +95 -0
  72. package/dist/plugin/server.d.ts +24 -0
  73. package/dist/plugin/server.js +166 -0
  74. package/dist/plugin/storage/locked-operations.d.ts +5 -0
  75. package/dist/plugin/storage/locked-operations.js +91 -0
  76. package/dist/plugin/storage/migrations.d.ts +2 -0
  77. package/dist/plugin/storage/migrations.js +109 -0
  78. package/dist/plugin/storage/sqlite.d.ts +17 -0
  79. package/dist/plugin/storage/sqlite.js +134 -0
  80. package/dist/plugin/streaming/index.d.ts +2 -0
  81. package/dist/plugin/streaming/index.js +2 -0
  82. package/dist/plugin/streaming/openai-converter.d.ts +2 -0
  83. package/dist/plugin/streaming/openai-converter.js +68 -0
  84. package/dist/plugin/streaming/stream-parser.d.ts +5 -0
  85. package/dist/plugin/streaming/stream-parser.js +136 -0
  86. package/dist/plugin/streaming/stream-state.d.ts +5 -0
  87. package/dist/plugin/streaming/stream-state.js +59 -0
  88. package/dist/plugin/streaming/stream-transformer.d.ts +1 -0
  89. package/dist/plugin/streaming/stream-transformer.js +248 -0
  90. package/dist/plugin/streaming/types.d.ts +25 -0
  91. package/dist/plugin/streaming/types.js +2 -0
  92. package/dist/plugin/sync/aws-sso.d.ts +2 -0
  93. package/dist/plugin/sync/aws-sso.js +50 -0
  94. package/dist/plugin/sync/kiro-cli-parser.d.ts +8 -0
  95. package/dist/plugin/sync/kiro-cli-parser.js +72 -0
  96. package/dist/plugin/sync/kiro-cli.d.ts +2 -0
  97. package/dist/plugin/sync/kiro-cli.js +197 -0
  98. package/dist/plugin/token.d.ts +2 -0
  99. package/dist/plugin/token.js +79 -0
  100. package/dist/plugin/types.d.ts +109 -0
  101. package/dist/plugin/types.js +0 -0
  102. package/dist/plugin/usage.d.ts +3 -0
  103. package/dist/plugin/usage.js +45 -0
  104. package/dist/plugin.d.ts +32 -0
  105. package/dist/plugin.js +37 -0
  106. package/package.json +65 -0
@@ -0,0 +1,129 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { dirname, join } from 'node:path';
4
+ import * as logger from '../logger';
5
+ import { AccountSelectionStrategySchema, DEFAULT_CONFIG, KiroConfigSchema, RegionSchema } from './schema';
6
+ function getConfigDir() {
7
+ const platform = process.platform;
8
+ if (platform === 'win32') {
9
+ return join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'opencode');
10
+ }
11
+ const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
12
+ return join(xdgConfig, 'opencode');
13
+ }
14
+ export function getUserConfigPath() {
15
+ return join(getConfigDir(), 'kiro.json');
16
+ }
17
+ function ensureUserConfigTemplate() {
18
+ const path = getUserConfigPath();
19
+ if (!existsSync(path)) {
20
+ try {
21
+ mkdirSync(dirname(path), { recursive: true });
22
+ writeFileSync(path, JSON.stringify(DEFAULT_CONFIG, null, 2), 'utf-8');
23
+ logger.log(`Created default config template at ${path}`);
24
+ }
25
+ catch (error) {
26
+ logger.warn(`Failed to create config template at ${path}: ${String(error)}`);
27
+ }
28
+ }
29
+ }
30
+ export function getProjectConfigPath(directory) {
31
+ return join(directory, '.opencode', 'kiro.json');
32
+ }
33
+ function loadConfigFile(path) {
34
+ try {
35
+ if (!existsSync(path)) {
36
+ return null;
37
+ }
38
+ const content = readFileSync(path, 'utf-8');
39
+ const rawConfig = JSON.parse(content);
40
+ const result = KiroConfigSchema.partial().safeParse(rawConfig);
41
+ if (!result.success) {
42
+ const issues = result.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join(', ');
43
+ logger.warn(`Config validation error at ${path}: ${issues}`);
44
+ return null;
45
+ }
46
+ return result.data;
47
+ }
48
+ catch (error) {
49
+ if (error instanceof SyntaxError) {
50
+ logger.warn(`Invalid JSON in config file ${path}: ${error.message}`);
51
+ }
52
+ else {
53
+ logger.warn(`Failed to load config file ${path}: ${String(error)}`);
54
+ }
55
+ return null;
56
+ }
57
+ }
58
+ function mergeConfigs(base, override) {
59
+ return {
60
+ ...base,
61
+ ...override
62
+ };
63
+ }
64
+ function parseBooleanEnv(value, fallback) {
65
+ if (value === undefined) {
66
+ return fallback;
67
+ }
68
+ if (value === '1' || value === 'true') {
69
+ return true;
70
+ }
71
+ if (value === '0' || value === 'false') {
72
+ return false;
73
+ }
74
+ return fallback;
75
+ }
76
+ function parseNumberEnv(value, fallback) {
77
+ if (value === undefined) {
78
+ return fallback;
79
+ }
80
+ const parsed = Number(value);
81
+ if (isNaN(parsed)) {
82
+ return fallback;
83
+ }
84
+ return parsed;
85
+ }
86
+ function applyEnvOverrides(config) {
87
+ const env = process.env;
88
+ return {
89
+ ...config,
90
+ account_selection_strategy: env.KIRO_ACCOUNT_SELECTION_STRATEGY
91
+ ? AccountSelectionStrategySchema.catch('lowest-usage').parse(env.KIRO_ACCOUNT_SELECTION_STRATEGY)
92
+ : config.account_selection_strategy,
93
+ default_region: env.KIRO_DEFAULT_REGION
94
+ ? RegionSchema.catch('us-east-1').parse(env.KIRO_DEFAULT_REGION)
95
+ : config.default_region,
96
+ rate_limit_retry_delay_ms: parseNumberEnv(env.KIRO_RATE_LIMIT_RETRY_DELAY_MS, config.rate_limit_retry_delay_ms),
97
+ rate_limit_max_retries: parseNumberEnv(env.KIRO_RATE_LIMIT_MAX_RETRIES, config.rate_limit_max_retries),
98
+ max_request_iterations: parseNumberEnv(env.KIRO_MAX_REQUEST_ITERATIONS, config.max_request_iterations),
99
+ request_timeout_ms: parseNumberEnv(env.KIRO_REQUEST_TIMEOUT_MS, config.request_timeout_ms),
100
+ token_expiry_buffer_ms: parseNumberEnv(env.KIRO_TOKEN_EXPIRY_BUFFER_MS, config.token_expiry_buffer_ms),
101
+ usage_sync_max_retries: parseNumberEnv(env.KIRO_USAGE_SYNC_MAX_RETRIES, config.usage_sync_max_retries),
102
+ auth_server_port_start: parseNumberEnv(env.KIRO_AUTH_SERVER_PORT_START, config.auth_server_port_start),
103
+ auth_server_port_range: parseNumberEnv(env.KIRO_AUTH_SERVER_PORT_RANGE, config.auth_server_port_range),
104
+ usage_tracking_enabled: parseBooleanEnv(env.KIRO_USAGE_TRACKING_ENABLED, config.usage_tracking_enabled),
105
+ enable_log_api_request: parseBooleanEnv(env.KIRO_ENABLE_LOG_API_REQUEST, config.enable_log_api_request)
106
+ };
107
+ }
108
+ export function loadConfig(directory) {
109
+ ensureUserConfigTemplate();
110
+ let config = { ...DEFAULT_CONFIG };
111
+ const userConfigPath = getUserConfigPath();
112
+ const userConfig = loadConfigFile(userConfigPath);
113
+ if (userConfig) {
114
+ config = mergeConfigs(config, userConfig);
115
+ }
116
+ const projectConfigPath = getProjectConfigPath(directory);
117
+ const projectConfig = loadConfigFile(projectConfigPath);
118
+ if (projectConfig) {
119
+ config = mergeConfigs(config, projectConfig);
120
+ }
121
+ config = applyEnvOverrides(config);
122
+ return config;
123
+ }
124
+ export function configExists(path) {
125
+ return existsSync(path);
126
+ }
127
+ export function getDefaultLogsDir() {
128
+ return join(getConfigDir(), 'kiro-logs');
129
+ }
@@ -0,0 +1,56 @@
1
+ import { z } from 'zod';
2
+ export declare const AccountSelectionStrategySchema: z.ZodEnum<["sticky", "round-robin", "lowest-usage"]>;
3
+ export type AccountSelectionStrategy = z.infer<typeof AccountSelectionStrategySchema>;
4
+ export declare const RegionSchema: z.ZodEnum<["us-east-1", "us-west-2"]>;
5
+ export type Region = z.infer<typeof RegionSchema>;
6
+ export declare const KiroConfigSchema: z.ZodObject<{
7
+ $schema: z.ZodOptional<z.ZodString>;
8
+ account_selection_strategy: z.ZodDefault<z.ZodEnum<["sticky", "round-robin", "lowest-usage"]>>;
9
+ default_region: z.ZodDefault<z.ZodEnum<["us-east-1", "us-west-2"]>>;
10
+ rate_limit_retry_delay_ms: z.ZodDefault<z.ZodNumber>;
11
+ rate_limit_max_retries: z.ZodDefault<z.ZodNumber>;
12
+ max_request_iterations: z.ZodDefault<z.ZodNumber>;
13
+ request_timeout_ms: z.ZodDefault<z.ZodNumber>;
14
+ token_expiry_buffer_ms: z.ZodDefault<z.ZodNumber>;
15
+ usage_sync_max_retries: z.ZodDefault<z.ZodNumber>;
16
+ auth_server_port_start: z.ZodDefault<z.ZodNumber>;
17
+ auth_server_port_range: z.ZodDefault<z.ZodNumber>;
18
+ usage_tracking_enabled: z.ZodDefault<z.ZodBoolean>;
19
+ auto_sync_kiro_cli: z.ZodDefault<z.ZodBoolean>;
20
+ auto_sync_aws_sso: z.ZodDefault<z.ZodBoolean>;
21
+ enable_log_api_request: z.ZodDefault<z.ZodBoolean>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ account_selection_strategy: "sticky" | "round-robin" | "lowest-usage";
24
+ default_region: "us-east-1" | "us-west-2";
25
+ rate_limit_retry_delay_ms: number;
26
+ rate_limit_max_retries: number;
27
+ max_request_iterations: number;
28
+ request_timeout_ms: number;
29
+ token_expiry_buffer_ms: number;
30
+ usage_sync_max_retries: number;
31
+ auth_server_port_start: number;
32
+ auth_server_port_range: number;
33
+ usage_tracking_enabled: boolean;
34
+ auto_sync_kiro_cli: boolean;
35
+ auto_sync_aws_sso: boolean;
36
+ enable_log_api_request: boolean;
37
+ $schema?: string | undefined;
38
+ }, {
39
+ $schema?: string | undefined;
40
+ account_selection_strategy?: "sticky" | "round-robin" | "lowest-usage" | undefined;
41
+ default_region?: "us-east-1" | "us-west-2" | undefined;
42
+ rate_limit_retry_delay_ms?: number | undefined;
43
+ rate_limit_max_retries?: number | undefined;
44
+ max_request_iterations?: number | undefined;
45
+ request_timeout_ms?: number | undefined;
46
+ token_expiry_buffer_ms?: number | undefined;
47
+ usage_sync_max_retries?: number | undefined;
48
+ auth_server_port_start?: number | undefined;
49
+ auth_server_port_range?: number | undefined;
50
+ usage_tracking_enabled?: boolean | undefined;
51
+ auto_sync_kiro_cli?: boolean | undefined;
52
+ auto_sync_aws_sso?: boolean | undefined;
53
+ enable_log_api_request?: boolean | undefined;
54
+ }>;
55
+ export type KiroConfig = z.infer<typeof KiroConfigSchema>;
56
+ export declare const DEFAULT_CONFIG: KiroConfig;
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ export const AccountSelectionStrategySchema = z.enum(['sticky', 'round-robin', 'lowest-usage']);
3
+ export const RegionSchema = z.enum(['us-east-1', 'us-west-2']);
4
+ export const KiroConfigSchema = z.object({
5
+ $schema: z.string().optional(),
6
+ account_selection_strategy: AccountSelectionStrategySchema.default('lowest-usage'),
7
+ default_region: RegionSchema.default('us-east-1'),
8
+ rate_limit_retry_delay_ms: z.number().min(1000).max(60000).default(5000),
9
+ rate_limit_max_retries: z.number().min(0).max(10).default(3),
10
+ max_request_iterations: z.number().min(5).max(1000).default(20),
11
+ request_timeout_ms: z.number().min(30000).max(600000).default(120000),
12
+ token_expiry_buffer_ms: z.number().min(30000).max(300000).default(120000),
13
+ usage_sync_max_retries: z.number().min(0).max(5).default(3),
14
+ auth_server_port_start: z.number().min(1024).max(65535).default(19847),
15
+ auth_server_port_range: z.number().min(1).max(100).default(10),
16
+ usage_tracking_enabled: z.boolean().default(true),
17
+ auto_sync_kiro_cli: z.boolean().default(true),
18
+ auto_sync_aws_sso: z.boolean().default(true),
19
+ enable_log_api_request: z.boolean().default(false)
20
+ });
21
+ export const DEFAULT_CONFIG = {
22
+ account_selection_strategy: 'lowest-usage',
23
+ default_region: 'us-east-1',
24
+ rate_limit_retry_delay_ms: 5000,
25
+ rate_limit_max_retries: 3,
26
+ max_request_iterations: 20,
27
+ request_timeout_ms: 120000,
28
+ token_expiry_buffer_ms: 120000,
29
+ usage_sync_max_retries: 3,
30
+ auth_server_port_start: 19847,
31
+ auth_server_port_range: 10,
32
+ usage_tracking_enabled: true,
33
+ auto_sync_kiro_cli: true,
34
+ auto_sync_aws_sso: true,
35
+ enable_log_api_request: false
36
+ };
@@ -0,0 +1,17 @@
1
+ export declare class KiroTokenRefreshError extends Error {
2
+ code?: string;
3
+ originalError?: Error;
4
+ constructor(message: string, code?: string, originalError?: Error);
5
+ }
6
+ export declare class KiroQuotaExhaustedError extends Error {
7
+ recoveryTime?: number;
8
+ constructor(message: string, recoveryTime?: number);
9
+ }
10
+ export declare class KiroRateLimitError extends Error {
11
+ retryAfter?: number;
12
+ constructor(message: string, retryAfter?: number);
13
+ }
14
+ export declare class KiroAuthError extends Error {
15
+ statusCode?: number;
16
+ constructor(message: string, statusCode?: number);
17
+ }
@@ -0,0 +1,34 @@
1
+ export class KiroTokenRefreshError extends Error {
2
+ code;
3
+ originalError;
4
+ constructor(message, code, originalError) {
5
+ super(message);
6
+ this.name = 'KiroTokenRefreshError';
7
+ this.code = code;
8
+ this.originalError = originalError;
9
+ }
10
+ }
11
+ export class KiroQuotaExhaustedError extends Error {
12
+ recoveryTime;
13
+ constructor(message, recoveryTime) {
14
+ super(message);
15
+ this.name = 'KiroQuotaExhaustedError';
16
+ this.recoveryTime = recoveryTime;
17
+ }
18
+ }
19
+ export class KiroRateLimitError extends Error {
20
+ retryAfter;
21
+ constructor(message, retryAfter) {
22
+ super(message);
23
+ this.name = 'KiroRateLimitError';
24
+ this.retryAfter = retryAfter;
25
+ }
26
+ }
27
+ export class KiroAuthError extends Error {
28
+ statusCode;
29
+ constructor(message, statusCode) {
30
+ super(message);
31
+ this.name = 'KiroAuthError';
32
+ this.statusCode = statusCode;
33
+ }
34
+ }
@@ -0,0 +1 @@
1
+ export declare function isPermanentError(reason?: string): boolean;
@@ -0,0 +1,9 @@
1
+ export function isPermanentError(reason) {
2
+ if (!reason)
3
+ return false;
4
+ return (reason.includes('Invalid refresh token') ||
5
+ reason.includes('ExpiredTokenException') ||
6
+ reason.includes('InvalidTokenException') ||
7
+ reason.includes('HTTP_401') ||
8
+ reason.includes('HTTP_403'));
9
+ }
@@ -0,0 +1,14 @@
1
+ interface UnifiedImage {
2
+ mediaType: string;
3
+ data: string;
4
+ }
5
+ interface KiroImage {
6
+ format: string;
7
+ source: {
8
+ bytes: string;
9
+ };
10
+ }
11
+ export declare function extractAllImages(content: any): UnifiedImage[];
12
+ export declare function convertImagesToKiroFormat(images: UnifiedImage[]): KiroImage[];
13
+ export declare function extractTextFromParts(parts: any[]): string;
14
+ export {};
@@ -0,0 +1,64 @@
1
+ function extractImagesFromAnthropicFormat(content) {
2
+ const images = [];
3
+ for (const item of content) {
4
+ if (item.type === 'image' && item.source?.type === 'base64') {
5
+ images.push({
6
+ mediaType: item.source.media_type || 'image/jpeg',
7
+ data: item.source.data
8
+ });
9
+ }
10
+ }
11
+ return images;
12
+ }
13
+ function extractImagesFromOpenAI(content) {
14
+ const images = [];
15
+ for (const item of content) {
16
+ if (item.type === 'image_url' && item.image_url?.url) {
17
+ const url = item.image_url.url;
18
+ if (url.startsWith('data:')) {
19
+ try {
20
+ const [header, data] = url.split(',', 2);
21
+ if (!data)
22
+ continue;
23
+ const mediaType = header.split(';')[0].replace('data:', '');
24
+ images.push({
25
+ mediaType: mediaType || 'image/jpeg',
26
+ data: data
27
+ });
28
+ }
29
+ catch (e) {
30
+ continue;
31
+ }
32
+ }
33
+ }
34
+ }
35
+ return images;
36
+ }
37
+ export function extractAllImages(content) {
38
+ if (!Array.isArray(content))
39
+ return [];
40
+ return [...extractImagesFromAnthropicFormat(content), ...extractImagesFromOpenAI(content)];
41
+ }
42
+ export function convertImagesToKiroFormat(images) {
43
+ return images.map((img) => {
44
+ const format = img.mediaType.split('/')[1] || 'png';
45
+ return {
46
+ format,
47
+ source: {
48
+ bytes: img.data
49
+ }
50
+ };
51
+ });
52
+ }
53
+ export function extractTextFromParts(parts) {
54
+ const textParts = [];
55
+ for (const part of parts) {
56
+ if (part.text && typeof part.text === 'string') {
57
+ textParts.push(part.text);
58
+ }
59
+ else if (part.type === 'text' && part.text) {
60
+ textParts.push(part.text);
61
+ }
62
+ }
63
+ return textParts.join('');
64
+ }
@@ -0,0 +1,8 @@
1
+ export declare function log(message: string, ...args: unknown[]): void;
2
+ export declare function error(message: string, ...args: unknown[]): void;
3
+ export declare function warn(message: string, ...args: unknown[]): void;
4
+ export declare function debug(message: string, ...args: unknown[]): void;
5
+ export declare function logApiRequest(data: any, timestamp: string): void;
6
+ export declare function logApiResponse(data: any, timestamp: string): void;
7
+ export declare function logApiError(requestData: any, responseData: any, timestamp: string): void;
8
+ export declare function getTimestamp(): string;
@@ -0,0 +1,63 @@
1
+ import { appendFileSync, mkdirSync, writeFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ const getLogDir = () => {
5
+ const platform = process.platform;
6
+ const base = platform === 'win32'
7
+ ? join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'opencode')
8
+ : join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'opencode');
9
+ return join(base, 'kiro-logs');
10
+ };
11
+ const writeToFile = (level, message, ...args) => {
12
+ try {
13
+ const dir = getLogDir();
14
+ mkdirSync(dir, { recursive: true });
15
+ const path = join(dir, 'plugin.log');
16
+ const timestamp = new Date().toISOString();
17
+ const content = `[${timestamp}] ${level}: ${message} ${args.map((a) => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ')}\n`;
18
+ appendFileSync(path, content);
19
+ }
20
+ catch (e) { }
21
+ };
22
+ const writeApiLog = (type, data, timestamp, isError = false) => {
23
+ try {
24
+ const dir = getLogDir();
25
+ mkdirSync(dir, { recursive: true });
26
+ const prefix = isError ? 'error_' : '';
27
+ const filename = `${prefix}${timestamp}_${type}.json`;
28
+ const path = join(dir, filename);
29
+ const content = JSON.stringify(data, null, 2);
30
+ writeFileSync(path, content);
31
+ }
32
+ catch (e) { }
33
+ };
34
+ export function log(message, ...args) {
35
+ writeToFile('INFO', message, ...args);
36
+ }
37
+ export function error(message, ...args) {
38
+ writeToFile('ERROR', message, ...args);
39
+ }
40
+ export function warn(message, ...args) {
41
+ writeToFile('WARN', message, ...args);
42
+ }
43
+ export function debug(message, ...args) {
44
+ if (process.env.DEBUG) {
45
+ writeToFile('DEBUG', message, ...args);
46
+ }
47
+ }
48
+ export function logApiRequest(data, timestamp) {
49
+ writeApiLog('request', data, timestamp);
50
+ }
51
+ export function logApiResponse(data, timestamp) {
52
+ writeApiLog('response', data, timestamp);
53
+ }
54
+ export function logApiError(requestData, responseData, timestamp) {
55
+ writeApiLog('request', requestData, timestamp, true);
56
+ writeApiLog('response', responseData, timestamp, true);
57
+ const errorType = responseData.status ? `HTTP ${responseData.status}` : 'Network Error';
58
+ const email = requestData.email || 'unknown';
59
+ error(`${errorType} on ${email} - See error_${timestamp}_request.json`);
60
+ }
61
+ export function getTimestamp() {
62
+ return new Date().toISOString().replace(/[:.]/g, '-');
63
+ }
@@ -0,0 +1 @@
1
+ export declare function resolveKiroModel(model: string): string;
@@ -0,0 +1,8 @@
1
+ import { MODEL_MAPPING, SUPPORTED_MODELS } from '../constants';
2
+ export function resolveKiroModel(model) {
3
+ const resolved = MODEL_MAPPING[model];
4
+ if (!resolved) {
5
+ throw new Error(`Unsupported model: ${model}. Supported models: ${SUPPORTED_MODELS.join(', ')}`);
6
+ }
7
+ return resolved;
8
+ }
@@ -0,0 +1,2 @@
1
+ import type { KiroAuthDetails, PreparedRequest } from './types';
2
+ export declare function transformToCodeWhisperer(url: string, body: any, model: string, auth: KiroAuthDetails, think?: boolean, budget?: number, reductionFactor?: number): PreparedRequest;