@zhafron/opencode-kiro-auth 1.2.7 → 1.2.8
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 +67 -8
- package/package.json +1 -1
package/dist/plugin/request.js
CHANGED
|
@@ -16,22 +16,36 @@ function sanitizeHistory(history) {
|
|
|
16
16
|
continue;
|
|
17
17
|
if (m.assistantResponseMessage?.toolUses) {
|
|
18
18
|
const next = history[i + 1];
|
|
19
|
-
if (next?.userInputMessage?.userInputMessageContext?.toolResults)
|
|
19
|
+
if (next?.userInputMessage?.userInputMessageContext?.toolResults)
|
|
20
20
|
result.push(m);
|
|
21
|
-
}
|
|
22
21
|
}
|
|
23
22
|
else if (m.userInputMessage?.userInputMessageContext?.toolResults) {
|
|
24
23
|
const prev = result[result.length - 1];
|
|
25
|
-
if (prev?.assistantResponseMessage?.toolUses)
|
|
24
|
+
if (prev?.assistantResponseMessage?.toolUses)
|
|
26
25
|
result.push(m);
|
|
27
|
-
}
|
|
28
26
|
}
|
|
29
|
-
else
|
|
27
|
+
else
|
|
30
28
|
result.push(m);
|
|
31
|
-
}
|
|
32
29
|
}
|
|
33
30
|
return result;
|
|
34
31
|
}
|
|
32
|
+
function findOriginalToolCall(msgs, toolUseId) {
|
|
33
|
+
for (const m of msgs) {
|
|
34
|
+
if (m.role === 'assistant') {
|
|
35
|
+
if (m.tool_calls) {
|
|
36
|
+
for (const tc of m.tool_calls)
|
|
37
|
+
if (tc.id === toolUseId)
|
|
38
|
+
return tc;
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(m.content)) {
|
|
41
|
+
for (const p of m.content)
|
|
42
|
+
if (p.type === 'tool_use' && p.id === toolUseId)
|
|
43
|
+
return p;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
35
49
|
export function transformToCodeWhisperer(url, body, model, auth, think = false, budget = 20000) {
|
|
36
50
|
const req = typeof body === 'string' ? JSON.parse(body) : body;
|
|
37
51
|
const { messages, tools, system } = req;
|
|
@@ -292,15 +306,60 @@ export function transformToCodeWhisperer(url, body, model, auth, think = false,
|
|
|
292
306
|
}
|
|
293
307
|
}
|
|
294
308
|
};
|
|
309
|
+
const toolUsesInHistory = history.flatMap((h) => h.assistantResponseMessage?.toolUses || []);
|
|
310
|
+
const allToolUseIdsInHistory = new Set(toolUsesInHistory.map((tu) => tu.toolUseId));
|
|
311
|
+
const finalCurTrs = [];
|
|
312
|
+
const orphanedTrs = [];
|
|
313
|
+
for (const tr of curTrs) {
|
|
314
|
+
if (allToolUseIdsInHistory.has(tr.toolUseId))
|
|
315
|
+
finalCurTrs.push(tr);
|
|
316
|
+
else {
|
|
317
|
+
const originalCall = findOriginalToolCall(messages, tr.toolUseId);
|
|
318
|
+
if (originalCall) {
|
|
319
|
+
orphanedTrs.push({
|
|
320
|
+
call: {
|
|
321
|
+
name: originalCall.name || originalCall.function?.name || 'tool',
|
|
322
|
+
toolUseId: tr.toolUseId,
|
|
323
|
+
input: originalCall.input ||
|
|
324
|
+
(originalCall.function?.arguments ? JSON.parse(originalCall.function.arguments) : {})
|
|
325
|
+
},
|
|
326
|
+
result: tr
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
curContent += `\n\n[Output for tool call ${tr.toolUseId}]:\n${tr.content?.[0]?.text || ''}`;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (orphanedTrs.length > 0) {
|
|
335
|
+
const prev = history[history.length - 1];
|
|
336
|
+
if (prev && !prev.userInputMessage) {
|
|
337
|
+
history.push({
|
|
338
|
+
userInputMessage: {
|
|
339
|
+
content: 'Running tools...',
|
|
340
|
+
modelId: resolved,
|
|
341
|
+
origin: KIRO_CONSTANTS.ORIGIN_AI_EDITOR
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
history.push({
|
|
346
|
+
assistantResponseMessage: {
|
|
347
|
+
content: 'I will execute the following tools.',
|
|
348
|
+
toolUses: orphanedTrs.map((o) => o.call)
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
finalCurTrs.push(...orphanedTrs.map((o) => o.result));
|
|
352
|
+
}
|
|
295
353
|
if (history.length > 0)
|
|
296
354
|
request.conversationState.history = history;
|
|
297
355
|
const uim = request.conversationState.currentMessage.userInputMessage;
|
|
298
356
|
if (uim) {
|
|
357
|
+
uim.content = curContent;
|
|
299
358
|
if (curImgs.length)
|
|
300
359
|
uim.images = curImgs;
|
|
301
360
|
const ctx = {};
|
|
302
|
-
if (
|
|
303
|
-
ctx.toolResults = deduplicateToolResults(
|
|
361
|
+
if (finalCurTrs.length)
|
|
362
|
+
ctx.toolResults = deduplicateToolResults(finalCurTrs);
|
|
304
363
|
if (cwTools.length)
|
|
305
364
|
ctx.tools = cwTools;
|
|
306
365
|
if (Object.keys(ctx).length)
|