@zhafron/opencode-kiro-auth 1.2.2 → 1.2.4
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/dist/plugin/request.js +45 -3
- package/package.json +1 -1
package/dist/plugin/request.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as crypto from 'crypto';
|
|
|
2
2
|
import * as os from 'os';
|
|
3
3
|
import { KIRO_CONSTANTS } from '../constants.js';
|
|
4
4
|
import { resolveKiroModel } from './models.js';
|
|
5
|
+
import * as logger from './logger.js';
|
|
5
6
|
export function transformToCodeWhisperer(url, body, model, auth, think = false, budget = 20000) {
|
|
6
7
|
const req = typeof body === 'string' ? JSON.parse(body) : body;
|
|
7
8
|
const { messages, tools, system, conversationId } = req;
|
|
@@ -268,6 +269,33 @@ export function transformToCodeWhisperer(url, body, model, auth, think = false,
|
|
|
268
269
|
ctx.tools = cwTools;
|
|
269
270
|
if (Object.keys(ctx).length)
|
|
270
271
|
uim.userInputMessageContext = ctx;
|
|
272
|
+
const hasToolsInHistory = historyHasToolCalling(history);
|
|
273
|
+
if (hasToolsInHistory) {
|
|
274
|
+
const toolNamesInHistory = extractToolNamesFromHistory(history);
|
|
275
|
+
if (toolNamesInHistory.size > 0) {
|
|
276
|
+
const existingTools = uim.userInputMessageContext?.tools || [];
|
|
277
|
+
const existingToolNames = new Set(existingTools.map((t) => t.toolSpecification?.name).filter(Boolean));
|
|
278
|
+
const missingToolNames = Array.from(toolNamesInHistory).filter((name) => !existingToolNames.has(name));
|
|
279
|
+
if (missingToolNames.length > 0) {
|
|
280
|
+
logger.log(`[Kiro] Adding ${missingToolNames.length} missing tool definitions: ${missingToolNames.join(', ')}`);
|
|
281
|
+
const placeholderTools = missingToolNames.map((name) => ({
|
|
282
|
+
toolSpecification: {
|
|
283
|
+
name,
|
|
284
|
+
description: 'Tool',
|
|
285
|
+
inputSchema: {
|
|
286
|
+
json: {
|
|
287
|
+
type: 'object',
|
|
288
|
+
properties: {}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}));
|
|
293
|
+
if (!uim.userInputMessageContext)
|
|
294
|
+
uim.userInputMessageContext = {};
|
|
295
|
+
uim.userInputMessageContext.tools = [...existingTools, ...placeholderTools];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
271
299
|
}
|
|
272
300
|
const machineId = crypto
|
|
273
301
|
.createHash('sha256')
|
|
@@ -332,9 +360,7 @@ export function mergeAdjacentMessages(msgs) {
|
|
|
332
360
|
return merged;
|
|
333
361
|
}
|
|
334
362
|
export function convertToolsToCodeWhisperer(tools) {
|
|
335
|
-
return tools
|
|
336
|
-
.filter((t) => !['web_search', 'websearch'].includes((t.name || t.function?.name || '').toLowerCase()))
|
|
337
|
-
.map((t) => ({
|
|
363
|
+
return tools.map((t) => ({
|
|
338
364
|
toolSpecification: {
|
|
339
365
|
name: t.name || t.function?.name,
|
|
340
366
|
description: (t.description || t.function?.description || '').substring(0, 9216),
|
|
@@ -366,3 +392,19 @@ function deduplicateToolResults(trs) {
|
|
|
366
392
|
}
|
|
367
393
|
return u;
|
|
368
394
|
}
|
|
395
|
+
function historyHasToolCalling(history) {
|
|
396
|
+
return history.some((h) => h.assistantResponseMessage?.toolUses ||
|
|
397
|
+
h.userInputMessage?.userInputMessageContext?.toolResults);
|
|
398
|
+
}
|
|
399
|
+
function extractToolNamesFromHistory(history) {
|
|
400
|
+
const toolNames = new Set();
|
|
401
|
+
for (const h of history) {
|
|
402
|
+
if (h.assistantResponseMessage?.toolUses) {
|
|
403
|
+
for (const tu of h.assistantResponseMessage.toolUses) {
|
|
404
|
+
if (tu.name)
|
|
405
|
+
toolNames.add(tu.name);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return toolNames;
|
|
410
|
+
}
|