@zhafron/opencode-kiro-auth 1.6.0 → 1.6.2
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/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const VALID_REGIONS = ['us-east-1', 'us-west-2'];
|
|
1
|
+
const VALID_REGIONS = ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'af-south-1', 'ap-east-1', 'ap-south-2', 'ap-southeast-3', 'ap-southeast-5', 'ap-southeast-4', 'ap-south-1', 'ap-southeast-6', 'ap-northeast-3', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-east-2', 'ap-southeast-7', 'ap-northeast-1', 'ca-central-1', 'ca-west-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-south-1', 'eu-west-3', 'eu-south-2', 'eu-north-1', 'eu-central-2', 'il-central-1', 'mx-central-1', 'me-south-1', 'me-central-1', 'sa-east-1'];
|
|
2
2
|
export function isValidRegion(region) {
|
|
3
3
|
return VALID_REGIONS.includes(region);
|
|
4
4
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CodeWhispererMessage } from '../../plugin/types';
|
|
2
|
-
export declare function buildHistory(msgs: any[], resolved: string,
|
|
2
|
+
export declare function buildHistory(msgs: any[], resolved: string, toolResultLimit: number): CodeWhispererMessage[];
|
|
3
|
+
export declare function injectSystemPrompt(history: CodeWhispererMessage[], system: string | undefined, resolved: string): CodeWhispererMessage[];
|
|
3
4
|
export declare function truncateHistory(history: CodeWhispererMessage[], historyLimit: number): CodeWhispererMessage[];
|
|
4
5
|
export declare function historyHasToolCalling(history: CodeWhispererMessage[]): boolean;
|
|
5
6
|
export declare function extractToolNamesFromHistory(history: CodeWhispererMessage[]): Set<string>;
|
|
@@ -2,38 +2,8 @@ import { KIRO_CONSTANTS } from '../../constants.js';
|
|
|
2
2
|
import { convertImagesToKiroFormat, extractAllImages, extractTextFromParts } from '../../plugin/image-handler.js';
|
|
3
3
|
import { getContentText, sanitizeHistory, truncate } from './message-transformer.js';
|
|
4
4
|
import { deduplicateToolResults } from './tool-transformer.js';
|
|
5
|
-
export function buildHistory(msgs, resolved,
|
|
5
|
+
export function buildHistory(msgs, resolved, toolResultLimit) {
|
|
6
6
|
let history = [];
|
|
7
|
-
let firstUserIndex = -1;
|
|
8
|
-
for (let i = 0; i < msgs.length; i++) {
|
|
9
|
-
if (msgs[i].role === 'user') {
|
|
10
|
-
firstUserIndex = i;
|
|
11
|
-
break;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
if (system) {
|
|
15
|
-
if (firstUserIndex !== -1) {
|
|
16
|
-
const m = msgs[firstUserIndex];
|
|
17
|
-
const oldContent = getContentText(m);
|
|
18
|
-
if (Array.isArray(m.content)) {
|
|
19
|
-
m.content = [
|
|
20
|
-
{ type: 'text', text: `${system}\n\n${oldContent}` },
|
|
21
|
-
...m.content.filter((p) => p.type !== 'text')
|
|
22
|
-
];
|
|
23
|
-
}
|
|
24
|
-
else
|
|
25
|
-
m.content = `${system}\n\n${oldContent}`;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
history.push({
|
|
29
|
-
userInputMessage: {
|
|
30
|
-
content: system,
|
|
31
|
-
modelId: resolved,
|
|
32
|
-
origin: KIRO_CONSTANTS.ORIGIN_AI_EDITOR
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
7
|
for (let i = 0; i < msgs.length - 1; i++) {
|
|
38
8
|
const m = msgs[i];
|
|
39
9
|
if (!m)
|
|
@@ -137,6 +107,25 @@ export function buildHistory(msgs, resolved, system, toolResultLimit) {
|
|
|
137
107
|
}
|
|
138
108
|
return history;
|
|
139
109
|
}
|
|
110
|
+
export function injectSystemPrompt(history, system, resolved) {
|
|
111
|
+
if (!system)
|
|
112
|
+
return history;
|
|
113
|
+
const firstUserMsg = history.find((h) => !!h.userInputMessage);
|
|
114
|
+
if (firstUserMsg && firstUserMsg.userInputMessage) {
|
|
115
|
+
const oldContent = firstUserMsg.userInputMessage.content || '';
|
|
116
|
+
firstUserMsg.userInputMessage.content = `${system}\n\n${oldContent}`;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
history.unshift({
|
|
120
|
+
userInputMessage: {
|
|
121
|
+
content: system,
|
|
122
|
+
modelId: resolved,
|
|
123
|
+
origin: KIRO_CONSTANTS.ORIGIN_AI_EDITOR
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return history;
|
|
128
|
+
}
|
|
140
129
|
export function truncateHistory(history, historyLimit) {
|
|
141
130
|
let sanitized = sanitizeHistory(history);
|
|
142
131
|
let historySize = JSON.stringify(sanitized).length;
|
package/dist/plugin/request.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as crypto from 'crypto';
|
|
2
2
|
import * as os from 'os';
|
|
3
3
|
import { KIRO_CONSTANTS } from '../constants.js';
|
|
4
|
-
import { buildHistory, extractToolNamesFromHistory, historyHasToolCalling, truncateHistory } from '../infrastructure/transformers/history-builder.js';
|
|
4
|
+
import { buildHistory, extractToolNamesFromHistory, historyHasToolCalling, injectSystemPrompt, truncateHistory } from '../infrastructure/transformers/history-builder.js';
|
|
5
5
|
import { findOriginalToolCall, getContentText, mergeAdjacentMessages, truncate } from '../infrastructure/transformers/message-transformer.js';
|
|
6
6
|
import { convertToolsToCodeWhisperer, deduplicateToolResults } from '../infrastructure/transformers/tool-transformer.js';
|
|
7
7
|
import { convertImagesToKiroFormat, extractAllImages, extractTextFromParts } from './image-handler.js';
|
|
@@ -13,20 +13,27 @@ export function transformToCodeWhisperer(url, body, model, auth, think = false,
|
|
|
13
13
|
if (!messages || messages.length === 0)
|
|
14
14
|
throw new Error('No messages');
|
|
15
15
|
const resolved = resolveKiroModel(model);
|
|
16
|
+
const systemMsgs = messages.filter((m) => m.role === 'system');
|
|
17
|
+
const otherMsgs = messages.filter((m) => m.role !== 'system');
|
|
16
18
|
let sys = system || '';
|
|
19
|
+
if (systemMsgs.length > 0) {
|
|
20
|
+
const extractedSystem = systemMsgs.map((m) => getContentText(m)).join('\n\n');
|
|
21
|
+
sys = sys ? `${sys}\n\n${extractedSystem}` : extractedSystem;
|
|
22
|
+
}
|
|
17
23
|
if (think) {
|
|
18
24
|
const pfx = `<thinking_mode>enabled</thinking_mode><max_thinking_length>${budget}</max_thinking_length>`;
|
|
19
25
|
sys = sys.includes('<thinking_mode>') ? sys : sys ? `${pfx}\n${sys}` : pfx;
|
|
20
26
|
}
|
|
21
|
-
const msgs = mergeAdjacentMessages([...
|
|
27
|
+
const msgs = mergeAdjacentMessages([...otherMsgs]);
|
|
22
28
|
const lastMsg = msgs[msgs.length - 1];
|
|
23
29
|
if (lastMsg && lastMsg.role === 'assistant' && getContentText(lastMsg) === '{')
|
|
24
30
|
msgs.pop();
|
|
25
31
|
const cwTools = tools ? convertToolsToCodeWhisperer(tools) : [];
|
|
26
32
|
const toolResultLimit = Math.floor(250000 * reductionFactor);
|
|
27
|
-
let history = buildHistory(msgs, resolved,
|
|
33
|
+
let history = buildHistory(msgs, resolved, toolResultLimit);
|
|
28
34
|
const historyLimit = Math.floor(850000 * reductionFactor);
|
|
29
35
|
history = truncateHistory(history, historyLimit);
|
|
36
|
+
history = injectSystemPrompt(history, sys, resolved);
|
|
30
37
|
const curMsg = msgs[msgs.length - 1];
|
|
31
38
|
if (!curMsg)
|
|
32
39
|
throw new Error('Empty');
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type KiroAuthMethod = 'idc' | 'desktop';
|
|
2
|
-
export type KiroRegion = 'us-east-1' | 'us-west-2';
|
|
2
|
+
export type KiroRegion = 'us-east-1' | 'us-east-2' | 'us-west-1' | 'us-west-2' | 'af-south-1' | 'ap-east-1' | 'ap-south-2' | 'ap-southeast-3' | 'ap-southeast-5' | 'ap-southeast-4' | 'ap-south-1' | 'ap-southeast-6' | 'ap-northeast-3' | 'ap-northeast-2' | 'ap-southeast-1' | 'ap-southeast-2' | 'ap-east-2' | 'ap-southeast-7' | 'ap-northeast-1' | 'ca-central-1' | 'ca-west-1' | 'eu-central-1' | 'eu-west-1' | 'eu-west-2' | 'eu-south-1' | 'eu-west-3' | 'eu-south-2' | 'eu-north-1' | 'eu-central-2' | 'il-central-1' | 'mx-central-1' | 'me-south-1' | 'me-central-1' | 'sa-east-1';
|
|
3
3
|
export interface KiroAuthDetails {
|
|
4
4
|
refresh: string;
|
|
5
5
|
access: string;
|