@zhafron/opencode-kiro-auth 1.2.1 → 1.2.3

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 CHANGED
@@ -1,4 +1,7 @@
1
1
  # OpenCode Kiro Auth Plugin
2
+ [![npm version](https://img.shields.io/npm/v/@zhafron/opencode-kiro-auth)](https://www.npmjs.com/package/@zhafron/opencode-kiro-auth)
3
+ [![npm downloads](https://img.shields.io/npm/dm/@zhafron/opencode-kiro-auth)](https://www.npmjs.com/package/@zhafron/opencode-kiro-auth)
4
+ [![license](https://img.shields.io/npm/l/@zhafron/opencode-kiro-auth)](https://www.npmjs.com/package/@zhafron/opencode-kiro-auth)
2
5
 
3
6
  OpenCode plugin for AWS Kiro (CodeWhisperer) providing access to the latest Claude 3.5/4.5 models with substantial trial quotas.
4
7
 
@@ -4,4 +4,5 @@ export declare function warn(message: string, ...args: unknown[]): void;
4
4
  export declare function debug(message: string, ...args: unknown[]): void;
5
5
  export declare function logApiRequest(data: any, timestamp: string): void;
6
6
  export declare function logApiResponse(data: any, timestamp: string): void;
7
+ export declare function logApiError(requestData: any, responseData: any, timestamp: string): void;
7
8
  export declare function getTimestamp(): string;
@@ -19,11 +19,12 @@ const writeToFile = (level, message, ...args) => {
19
19
  }
20
20
  catch (e) { }
21
21
  };
22
- const writeApiLog = (type, data, timestamp) => {
22
+ const writeApiLog = (type, data, timestamp, isError = false) => {
23
23
  try {
24
24
  const dir = getLogDir();
25
25
  mkdirSync(dir, { recursive: true });
26
- const filename = `${timestamp}_${type}.json`;
26
+ const prefix = isError ? 'error_' : '';
27
+ const filename = `${prefix}${timestamp}_${type}.json`;
27
28
  const path = join(dir, filename);
28
29
  const content = JSON.stringify(data, null, 2);
29
30
  writeFileSync(path, content);
@@ -50,6 +51,13 @@ export function logApiRequest(data, timestamp) {
50
51
  export function logApiResponse(data, timestamp) {
51
52
  writeApiLog('response', data, timestamp);
52
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
+ }
53
61
  export function getTimestamp() {
54
62
  return new Date().toISOString().replace(/[:.]/g, '-');
55
63
  }
@@ -332,9 +332,7 @@ export function mergeAdjacentMessages(msgs) {
332
332
  return merged;
333
333
  }
334
334
  export function convertToolsToCodeWhisperer(tools) {
335
- return tools
336
- .filter((t) => !['web_search', 'websearch'].includes((t.name || t.function?.name || '').toLowerCase()))
337
- .map((t) => ({
335
+ return tools.map((t) => ({
338
336
  toolSpecification: {
339
337
  name: t.name || t.function?.name,
340
338
  description: (t.description || t.function?.description || '').substring(0, 9216),
package/dist/plugin.js CHANGED
@@ -113,24 +113,26 @@ export const createKiroPlugin = (id) => async ({ client, directory }) => {
113
113
  }
114
114
  const prep = transformToCodeWhisperer(url, init?.body, model, auth, think, budget);
115
115
  const apiTimestamp = config.enable_log_api_request ? logger.getTimestamp() : null;
116
- if (config.enable_log_api_request && apiTimestamp) {
117
- let parsedBody = null;
118
- if (prep.init.body && typeof prep.init.body === 'string') {
119
- try {
120
- parsedBody = JSON.parse(prep.init.body);
121
- }
122
- catch (e) {
123
- parsedBody = prep.init.body;
124
- }
116
+ let parsedBody = null;
117
+ if (prep.init.body && typeof prep.init.body === 'string') {
118
+ try {
119
+ parsedBody = JSON.parse(prep.init.body);
120
+ }
121
+ catch (e) {
122
+ parsedBody = prep.init.body;
125
123
  }
126
- logger.logApiRequest({
127
- url: prep.url,
128
- method: prep.init.method,
129
- headers: prep.init.headers,
130
- body: parsedBody,
131
- conversationId: prep.conversationId,
132
- model: prep.effectiveModel
133
- }, apiTimestamp);
124
+ }
125
+ const requestData = {
126
+ url: prep.url,
127
+ method: prep.init.method,
128
+ headers: prep.init.headers,
129
+ body: parsedBody,
130
+ conversationId: prep.conversationId,
131
+ model: prep.effectiveModel,
132
+ email: acc.realEmail || acc.email
133
+ };
134
+ if (config.enable_log_api_request && apiTimestamp) {
135
+ logger.logApiRequest(requestData, apiTimestamp);
134
136
  }
135
137
  try {
136
138
  const res = await fetch(prep.url, prep.init);
@@ -215,7 +217,6 @@ export const createKiroPlugin = (id) => async ({ client, directory }) => {
215
217
  });
216
218
  }
217
219
  if (res.status === 401 && retry < config.rate_limit_max_retries) {
218
- logger.warn(`Unauthorized (401) on ${acc.realEmail || acc.email}, retrying...`);
219
220
  retry++;
220
221
  continue;
221
222
  }
@@ -239,30 +240,28 @@ export const createKiroPlugin = (id) => async ({ client, directory }) => {
239
240
  await am.saveToDisk();
240
241
  continue;
241
242
  }
243
+ const responseHeaders = {};
244
+ res.headers.forEach((value, key) => {
245
+ responseHeaders[key] = value;
246
+ });
247
+ const responseData = {
248
+ status: res.status,
249
+ statusText: res.statusText,
250
+ headers: responseHeaders,
251
+ error: `Kiro Error: ${res.status}`,
252
+ conversationId: prep.conversationId,
253
+ model: prep.effectiveModel
254
+ };
242
255
  if (config.enable_log_api_request && apiTimestamp) {
243
- const responseHeaders = {};
244
- res.headers.forEach((value, key) => {
245
- responseHeaders[key] = value;
246
- });
247
- logger.logApiResponse({
248
- status: res.status,
249
- statusText: res.statusText,
250
- headers: responseHeaders,
251
- error: `Kiro Error: ${res.status}`,
252
- conversationId: prep.conversationId,
253
- model: prep.effectiveModel
254
- }, apiTimestamp);
256
+ logger.logApiResponse(responseData, apiTimestamp);
257
+ }
258
+ else {
259
+ const errorTimestamp = logger.getTimestamp();
260
+ logger.logApiError(requestData, responseData, errorTimestamp);
255
261
  }
256
262
  throw new Error(`Kiro Error: ${res.status}`);
257
263
  }
258
264
  catch (e) {
259
- if (config.enable_log_api_request && apiTimestamp) {
260
- logger.logApiResponse({
261
- error: String(e),
262
- conversationId: prep.conversationId,
263
- model: prep.effectiveModel
264
- }, apiTimestamp);
265
- }
266
265
  if (isNetworkError(e) && retry < config.rate_limit_max_retries) {
267
266
  const delay = 5000 * Math.pow(2, retry);
268
267
  showToast(`Network error. Retrying in ${Math.ceil(delay / 1000)}s...`, 'warning');
@@ -270,6 +269,18 @@ export const createKiroPlugin = (id) => async ({ client, directory }) => {
270
269
  retry++;
271
270
  continue;
272
271
  }
272
+ const networkErrorData = {
273
+ error: String(e),
274
+ conversationId: prep.conversationId,
275
+ model: prep.effectiveModel
276
+ };
277
+ if (config.enable_log_api_request && apiTimestamp) {
278
+ logger.logApiResponse(networkErrorData, apiTimestamp);
279
+ }
280
+ else {
281
+ const errorTimestamp = logger.getTimestamp();
282
+ logger.logApiError(requestData, networkErrorData, errorTimestamp);
283
+ }
273
284
  throw e;
274
285
  }
275
286
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhafron/opencode-kiro-auth",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "OpenCode plugin for AWS Kiro (CodeWhisperer) providing access to Claude models",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",