@zhafron/opencode-kiro-auth 1.4.11 → 1.5.0
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.d.ts +0 -1
- package/dist/constants.js +0 -9
- package/dist/core/account/account-selector.d.ts +21 -0
- package/dist/core/account/account-selector.js +64 -0
- package/dist/core/account/usage-tracker.d.ts +17 -0
- package/dist/core/account/usage-tracker.js +39 -0
- package/dist/core/auth/auth-handler.d.ts +15 -0
- package/dist/core/auth/auth-handler.js +33 -0
- package/dist/core/auth/idc-auth-method.d.ts +17 -0
- package/dist/core/auth/idc-auth-method.js +194 -0
- package/dist/core/auth/token-refresher.d.ts +22 -0
- package/dist/core/auth/token-refresher.js +53 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +9 -0
- package/dist/core/request/error-handler.d.ts +29 -0
- package/dist/core/request/error-handler.js +113 -0
- package/dist/core/request/request-handler.d.ts +25 -0
- package/dist/core/request/request-handler.js +180 -0
- package/dist/core/request/response-handler.d.ts +5 -0
- package/dist/core/request/response-handler.js +61 -0
- package/dist/core/request/retry-strategy.d.ts +20 -0
- package/dist/core/request/retry-strategy.js +32 -0
- package/dist/infrastructure/database/account-cache.d.ts +14 -0
- package/dist/infrastructure/database/account-cache.js +44 -0
- package/dist/infrastructure/database/account-repository.d.ts +12 -0
- package/dist/infrastructure/database/account-repository.js +64 -0
- package/dist/infrastructure/index.d.ts +7 -0
- package/dist/infrastructure/index.js +7 -0
- package/dist/infrastructure/transformers/event-stream-parser.d.ts +7 -0
- package/dist/infrastructure/transformers/event-stream-parser.js +115 -0
- package/dist/infrastructure/transformers/history-builder.d.ts +5 -0
- package/dist/infrastructure/transformers/history-builder.js +171 -0
- package/dist/infrastructure/transformers/message-transformer.d.ts +6 -0
- package/dist/infrastructure/transformers/message-transformer.js +102 -0
- package/dist/infrastructure/transformers/tool-call-parser.d.ts +4 -0
- package/dist/infrastructure/transformers/tool-call-parser.js +45 -0
- package/dist/infrastructure/transformers/tool-transformer.d.ts +2 -0
- package/dist/infrastructure/transformers/tool-transformer.js +19 -0
- package/dist/kiro/auth.d.ts +0 -1
- package/dist/kiro/auth.js +0 -7
- package/dist/plugin/accounts.d.ts +0 -1
- package/dist/plugin/accounts.js +4 -4
- package/dist/plugin/cli.d.ts +2 -1
- package/dist/plugin/cli.js +38 -2
- package/dist/plugin/models.d.ts +0 -2
- package/dist/plugin/models.js +0 -6
- package/dist/plugin/request.d.ts +0 -2
- package/dist/plugin/request.js +5 -282
- package/dist/plugin/response.d.ts +2 -5
- package/dist/plugin/response.js +3 -161
- package/dist/plugin/storage/migrations.d.ts +2 -0
- package/dist/plugin/storage/migrations.js +109 -0
- package/dist/plugin/storage/sqlite.js +5 -56
- package/dist/plugin/streaming/index.d.ts +2 -0
- package/dist/plugin/streaming/index.js +2 -0
- package/dist/plugin/streaming/openai-converter.d.ts +2 -0
- package/dist/plugin/streaming/openai-converter.js +68 -0
- package/dist/plugin/streaming/stream-parser.d.ts +5 -0
- package/dist/plugin/streaming/stream-parser.js +136 -0
- package/dist/plugin/streaming/stream-state.d.ts +5 -0
- package/dist/plugin/streaming/stream-state.js +59 -0
- package/dist/plugin/streaming/stream-transformer.d.ts +1 -0
- package/dist/plugin/{streaming.js → streaming/stream-transformer.js} +6 -268
- package/dist/plugin/streaming/types.d.ts +25 -0
- package/dist/plugin/streaming/types.js +2 -0
- package/dist/plugin/sync/kiro-cli-parser.d.ts +8 -0
- package/dist/plugin/sync/kiro-cli-parser.js +72 -0
- package/dist/plugin/sync/kiro-cli.js +1 -73
- package/dist/plugin/types.d.ts +0 -13
- package/dist/plugin.d.ts +6 -6
- package/dist/plugin.js +16 -512
- package/package.json +11 -3
- package/dist/plugin/storage/migration.d.ts +0 -1
- package/dist/plugin/storage/migration.js +0 -54
- package/dist/plugin/streaming.d.ts +0 -3
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { KIRO_CONSTANTS } from '../../constants.js';
|
|
2
|
+
import { convertImagesToKiroFormat, extractAllImages, extractTextFromParts } from '../../plugin/image-handler.js';
|
|
3
|
+
import { getContentText, sanitizeHistory, truncate } from './message-transformer.js';
|
|
4
|
+
import { deduplicateToolResults } from './tool-transformer.js';
|
|
5
|
+
export function buildHistory(msgs, resolved, system, toolResultLimit) {
|
|
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
|
+
for (let i = 0; i < msgs.length - 1; i++) {
|
|
38
|
+
const m = msgs[i];
|
|
39
|
+
if (!m)
|
|
40
|
+
continue;
|
|
41
|
+
if (m.role === 'user') {
|
|
42
|
+
const uim = { content: '', modelId: resolved, origin: KIRO_CONSTANTS.ORIGIN_AI_EDITOR };
|
|
43
|
+
const trs = [];
|
|
44
|
+
if (Array.isArray(m.content)) {
|
|
45
|
+
uim.content = extractTextFromParts(m.content);
|
|
46
|
+
for (const p of m.content) {
|
|
47
|
+
if (p.type === 'tool_result') {
|
|
48
|
+
trs.push({
|
|
49
|
+
content: [{ text: truncate(getContentText(p.content || p), toolResultLimit) }],
|
|
50
|
+
status: 'success',
|
|
51
|
+
toolUseId: p.tool_use_id
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const unifiedImages = extractAllImages(m.content);
|
|
56
|
+
if (unifiedImages.length > 0) {
|
|
57
|
+
uim.images = convertImagesToKiroFormat(unifiedImages);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
uim.content = getContentText(m);
|
|
62
|
+
}
|
|
63
|
+
if (trs.length)
|
|
64
|
+
uim.userInputMessageContext = { toolResults: deduplicateToolResults(trs) };
|
|
65
|
+
const prev = history[history.length - 1];
|
|
66
|
+
if (prev && prev.userInputMessage)
|
|
67
|
+
history.push({ assistantResponseMessage: { content: 'Continue' } });
|
|
68
|
+
history.push({ userInputMessage: uim });
|
|
69
|
+
}
|
|
70
|
+
else if (m.role === 'tool') {
|
|
71
|
+
const trs = [];
|
|
72
|
+
if (m.tool_results) {
|
|
73
|
+
for (const tr of m.tool_results)
|
|
74
|
+
trs.push({
|
|
75
|
+
content: [{ text: truncate(getContentText(tr), toolResultLimit) }],
|
|
76
|
+
status: 'success',
|
|
77
|
+
toolUseId: tr.tool_call_id
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
trs.push({
|
|
82
|
+
content: [{ text: truncate(getContentText(m), toolResultLimit) }],
|
|
83
|
+
status: 'success',
|
|
84
|
+
toolUseId: m.tool_call_id
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const prev = history[history.length - 1];
|
|
88
|
+
if (prev && prev.userInputMessage)
|
|
89
|
+
history.push({ assistantResponseMessage: { content: 'Continue' } });
|
|
90
|
+
history.push({
|
|
91
|
+
userInputMessage: {
|
|
92
|
+
content: 'Tool results provided.',
|
|
93
|
+
modelId: resolved,
|
|
94
|
+
origin: KIRO_CONSTANTS.ORIGIN_AI_EDITOR,
|
|
95
|
+
userInputMessageContext: { toolResults: deduplicateToolResults(trs) }
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else if (m.role === 'assistant') {
|
|
100
|
+
const arm = { content: '' };
|
|
101
|
+
const tus = [];
|
|
102
|
+
let th = '';
|
|
103
|
+
if (Array.isArray(m.content)) {
|
|
104
|
+
for (const p of m.content) {
|
|
105
|
+
if (p.type === 'text')
|
|
106
|
+
arm.content += p.text || '';
|
|
107
|
+
else if (p.type === 'thinking')
|
|
108
|
+
th += p.thinking || p.text || '';
|
|
109
|
+
else if (p.type === 'tool_use')
|
|
110
|
+
tus.push({ input: p.input, name: p.name, toolUseId: p.id });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else
|
|
114
|
+
arm.content = getContentText(m);
|
|
115
|
+
if (m.tool_calls && Array.isArray(m.tool_calls)) {
|
|
116
|
+
for (const tc of m.tool_calls) {
|
|
117
|
+
tus.push({
|
|
118
|
+
input: typeof tc.function?.arguments === 'string'
|
|
119
|
+
? JSON.parse(tc.function.arguments)
|
|
120
|
+
: tc.function?.arguments,
|
|
121
|
+
name: tc.function?.name,
|
|
122
|
+
toolUseId: tc.id
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (th)
|
|
127
|
+
arm.content = arm.content
|
|
128
|
+
? `<thinking>${th}</thinking>\n\n${arm.content}`
|
|
129
|
+
: `<thinking>${th}</thinking>`;
|
|
130
|
+
if (tus.length)
|
|
131
|
+
arm.toolUses = tus;
|
|
132
|
+
if (!arm.content && !arm.toolUses) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
history.push({ assistantResponseMessage: arm });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return history;
|
|
139
|
+
}
|
|
140
|
+
export function truncateHistory(history, historyLimit) {
|
|
141
|
+
let sanitized = sanitizeHistory(history);
|
|
142
|
+
let historySize = JSON.stringify(sanitized).length;
|
|
143
|
+
while (historySize > historyLimit && sanitized.length > 2) {
|
|
144
|
+
sanitized.shift();
|
|
145
|
+
while (sanitized.length > 0) {
|
|
146
|
+
const first = sanitized[0];
|
|
147
|
+
if (first && first.userInputMessage)
|
|
148
|
+
break;
|
|
149
|
+
sanitized.shift();
|
|
150
|
+
}
|
|
151
|
+
sanitized = sanitizeHistory(sanitized);
|
|
152
|
+
historySize = JSON.stringify(sanitized).length;
|
|
153
|
+
}
|
|
154
|
+
return sanitized;
|
|
155
|
+
}
|
|
156
|
+
export function historyHasToolCalling(history) {
|
|
157
|
+
return history.some((h) => h.assistantResponseMessage?.toolUses ||
|
|
158
|
+
h.userInputMessage?.userInputMessageContext?.toolResults);
|
|
159
|
+
}
|
|
160
|
+
export function extractToolNamesFromHistory(history) {
|
|
161
|
+
const toolNames = new Set();
|
|
162
|
+
for (const h of history) {
|
|
163
|
+
if (h.assistantResponseMessage?.toolUses) {
|
|
164
|
+
for (const tu of h.assistantResponseMessage.toolUses) {
|
|
165
|
+
if (tu.name)
|
|
166
|
+
toolNames.add(tu.name);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return toolNames;
|
|
171
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CodeWhispererMessage } from '../../plugin/types';
|
|
2
|
+
export declare function sanitizeHistory(history: CodeWhispererMessage[]): CodeWhispererMessage[];
|
|
3
|
+
export declare function findOriginalToolCall(msgs: any[], toolUseId: string): any | null;
|
|
4
|
+
export declare function mergeAdjacentMessages(msgs: any[]): any[];
|
|
5
|
+
export declare function getContentText(m: any): string;
|
|
6
|
+
export declare function truncate(s: string, max: number): string;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export function sanitizeHistory(history) {
|
|
2
|
+
const result = [];
|
|
3
|
+
for (let i = 0; i < history.length; i++) {
|
|
4
|
+
const m = history[i];
|
|
5
|
+
if (!m)
|
|
6
|
+
continue;
|
|
7
|
+
if (m.assistantResponseMessage?.toolUses) {
|
|
8
|
+
const next = history[i + 1];
|
|
9
|
+
if (next?.userInputMessage?.userInputMessageContext?.toolResults) {
|
|
10
|
+
result.push(m);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
else if (m.userInputMessage?.userInputMessageContext?.toolResults) {
|
|
14
|
+
const prev = result[result.length - 1];
|
|
15
|
+
if (prev?.assistantResponseMessage?.toolUses) {
|
|
16
|
+
result.push(m);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
result.push(m);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (result.length > 0) {
|
|
24
|
+
const first = result[0];
|
|
25
|
+
if (!first ||
|
|
26
|
+
!first.userInputMessage ||
|
|
27
|
+
first.userInputMessage.userInputMessageContext?.toolResults) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
export function findOriginalToolCall(msgs, toolUseId) {
|
|
34
|
+
for (const m of msgs) {
|
|
35
|
+
if (m.role === 'assistant') {
|
|
36
|
+
if (m.tool_calls) {
|
|
37
|
+
for (const tc of m.tool_calls)
|
|
38
|
+
if (tc.id === toolUseId)
|
|
39
|
+
return tc;
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(m.content)) {
|
|
42
|
+
for (const p of m.content)
|
|
43
|
+
if (p.type === 'tool_use' && p.id === toolUseId)
|
|
44
|
+
return p;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
export function mergeAdjacentMessages(msgs) {
|
|
51
|
+
const merged = [];
|
|
52
|
+
for (const m of msgs) {
|
|
53
|
+
if (!merged.length)
|
|
54
|
+
merged.push({ ...m });
|
|
55
|
+
else {
|
|
56
|
+
const last = merged[merged.length - 1];
|
|
57
|
+
if (last && m.role === last.role) {
|
|
58
|
+
if (Array.isArray(last.content) && Array.isArray(m.content))
|
|
59
|
+
last.content.push(...m.content);
|
|
60
|
+
else if (typeof last.content === 'string' && typeof m.content === 'string')
|
|
61
|
+
last.content += '\n' + m.content;
|
|
62
|
+
else if (Array.isArray(last.content) && typeof m.content === 'string')
|
|
63
|
+
last.content.push({ type: 'text', text: m.content });
|
|
64
|
+
else if (typeof last.content === 'string' && Array.isArray(m.content))
|
|
65
|
+
last.content = [{ type: 'text', text: last.content }, ...m.content];
|
|
66
|
+
if (m.tool_calls) {
|
|
67
|
+
if (!last.tool_calls)
|
|
68
|
+
last.tool_calls = [];
|
|
69
|
+
last.tool_calls.push(...m.tool_calls);
|
|
70
|
+
}
|
|
71
|
+
if (m.role === 'tool') {
|
|
72
|
+
if (!last.tool_results)
|
|
73
|
+
last.tool_results = [{ content: last.content, tool_call_id: last.tool_call_id }];
|
|
74
|
+
last.tool_results.push({ content: m.content, tool_call_id: m.tool_call_id });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
merged.push({ ...m });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return merged;
|
|
82
|
+
}
|
|
83
|
+
export function getContentText(m) {
|
|
84
|
+
if (!m)
|
|
85
|
+
return '';
|
|
86
|
+
if (typeof m === 'string')
|
|
87
|
+
return m;
|
|
88
|
+
if (typeof m.content === 'string')
|
|
89
|
+
return m.content;
|
|
90
|
+
if (Array.isArray(m.content))
|
|
91
|
+
return m.content
|
|
92
|
+
.filter((p) => p.type === 'text')
|
|
93
|
+
.map((p) => p.text || '')
|
|
94
|
+
.join('');
|
|
95
|
+
return m.text || '';
|
|
96
|
+
}
|
|
97
|
+
export function truncate(s, max) {
|
|
98
|
+
if (s.length <= max)
|
|
99
|
+
return s;
|
|
100
|
+
const half = Math.floor(max / 2);
|
|
101
|
+
return s.substring(0, half) + '\n... [TRUNCATED] ...\n' + s.substring(s.length - half);
|
|
102
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ToolCall } from '../../plugin/types';
|
|
2
|
+
export declare function parseBracketToolCalls(text: string): ToolCall[];
|
|
3
|
+
export declare function deduplicateToolCalls(toolCalls: ToolCall[]): ToolCall[];
|
|
4
|
+
export declare function cleanToolCallsFromText(text: string, toolCalls: ToolCall[]): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function parseBracketToolCalls(text) {
|
|
2
|
+
const toolCalls = [];
|
|
3
|
+
const pattern = /\[Called\s+(\w+)\s+with\s+args:\s*(\{[^}]*(?:\{[^}]*\}[^}]*)*\})\]/gs;
|
|
4
|
+
let match;
|
|
5
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
6
|
+
const funcName = match[1];
|
|
7
|
+
const argsStr = match[2];
|
|
8
|
+
if (!funcName || !argsStr)
|
|
9
|
+
continue;
|
|
10
|
+
try {
|
|
11
|
+
const args = JSON.parse(argsStr);
|
|
12
|
+
toolCalls.push({
|
|
13
|
+
toolUseId: `tool_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
14
|
+
name: funcName,
|
|
15
|
+
input: args
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return toolCalls;
|
|
23
|
+
}
|
|
24
|
+
export function deduplicateToolCalls(toolCalls) {
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
const unique = [];
|
|
27
|
+
for (const tc of toolCalls) {
|
|
28
|
+
if (!seen.has(tc.toolUseId)) {
|
|
29
|
+
seen.add(tc.toolUseId);
|
|
30
|
+
unique.push(tc);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return unique;
|
|
34
|
+
}
|
|
35
|
+
export function cleanToolCallsFromText(text, toolCalls) {
|
|
36
|
+
let cleaned = text;
|
|
37
|
+
for (const tc of toolCalls) {
|
|
38
|
+
const funcName = tc.name;
|
|
39
|
+
const escapedName = funcName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
40
|
+
const pattern = new RegExp(`\\[Called\\s+${escapedName}\\s+with\\s+args:\\s*\\{[^}]*(?:\\{[^}]*\\}[^}]*)*\\}\\]`, 'gs');
|
|
41
|
+
cleaned = cleaned.replace(pattern, '');
|
|
42
|
+
}
|
|
43
|
+
cleaned = cleaned.replace(/\s+/g, ' ').trim();
|
|
44
|
+
return cleaned;
|
|
45
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function convertToolsToCodeWhisperer(tools) {
|
|
2
|
+
return tools.map((t) => ({
|
|
3
|
+
toolSpecification: {
|
|
4
|
+
name: t.name || t.function?.name,
|
|
5
|
+
description: (t.description || t.function?.description || '').substring(0, 9216),
|
|
6
|
+
inputSchema: { json: t.input_schema || t.function?.parameters || {} }
|
|
7
|
+
}
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
export function deduplicateToolResults(trs) {
|
|
11
|
+
const u = [], s = new Set();
|
|
12
|
+
for (const t of trs) {
|
|
13
|
+
if (!s.has(t.toolUseId)) {
|
|
14
|
+
s.add(t.toolUseId);
|
|
15
|
+
u.push(t);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return u;
|
|
19
|
+
}
|
package/dist/kiro/auth.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { KiroAuthDetails, RefreshParts } from '../plugin/types';
|
|
2
2
|
export declare function decodeRefreshToken(refresh: string): RefreshParts;
|
|
3
3
|
export declare function accessTokenExpired(auth: KiroAuthDetails, bufferMs?: number): boolean;
|
|
4
|
-
export declare function validateAuthDetails(auth: KiroAuthDetails): boolean;
|
|
5
4
|
export declare function encodeRefreshToken(parts: RefreshParts): string;
|
package/dist/kiro/auth.js
CHANGED
|
@@ -15,13 +15,6 @@ export function accessTokenExpired(auth, bufferMs = 120000) {
|
|
|
15
15
|
return true;
|
|
16
16
|
return Date.now() >= auth.expires - bufferMs;
|
|
17
17
|
}
|
|
18
|
-
export function validateAuthDetails(auth) {
|
|
19
|
-
if (!auth.refresh)
|
|
20
|
-
return false;
|
|
21
|
-
if (auth.authMethod === 'idc')
|
|
22
|
-
return !!auth.clientId && !!auth.clientSecret;
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
18
|
export function encodeRefreshToken(parts) {
|
|
26
19
|
if (parts.authMethod === 'idc') {
|
|
27
20
|
if (!parts.clientId || !parts.clientSecret)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AccountSelectionStrategy, KiroAuthDetails, ManagedAccount } from './types';
|
|
2
|
-
export declare function generateAccountId(): string;
|
|
3
2
|
export declare function createDeterministicAccountId(email: string, method: string, clientId?: string, profileArn?: string): string;
|
|
4
3
|
export declare class AccountManager {
|
|
5
4
|
private accounts;
|
package/dist/plugin/accounts.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { createHash
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
2
|
import { decodeRefreshToken, encodeRefreshToken } from '../kiro/auth';
|
|
3
3
|
import { isPermanentError } from './health';
|
|
4
4
|
import * as logger from './logger';
|
|
5
5
|
import { kiroDb } from './storage/sqlite';
|
|
6
6
|
import { writeToKiroCli } from './sync/kiro-cli';
|
|
7
|
-
export function generateAccountId() {
|
|
8
|
-
return randomBytes(16).toString('hex');
|
|
9
|
-
}
|
|
10
7
|
export function createDeterministicAccountId(email, method, clientId, profileArn) {
|
|
11
8
|
return createHash('sha256')
|
|
12
9
|
.update(`${email}:${method}:${clientId || ''}:${profileArn || ''}`)
|
|
@@ -128,6 +125,9 @@ export class AccountManager {
|
|
|
128
125
|
a.email = meta.email;
|
|
129
126
|
if (!isPermanentError(a.unhealthyReason)) {
|
|
130
127
|
a.failCount = 0;
|
|
128
|
+
a.isHealthy = true;
|
|
129
|
+
delete a.unhealthyReason;
|
|
130
|
+
delete a.recoveryTime;
|
|
131
131
|
}
|
|
132
132
|
kiroDb.upsertAccount(a).catch(() => { });
|
|
133
133
|
}
|
package/dist/plugin/cli.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare function promptAddAnotherAccount(currentCount: number): Promise<boolean>;
|
|
2
|
-
export
|
|
2
|
+
export declare function promptDeleteAccount(accounts: ExistingAccountInfo[]): Promise<number | null>;
|
|
3
|
+
export type LoginMode = 'add' | 'fresh' | 'delete';
|
|
3
4
|
export interface ExistingAccountInfo {
|
|
4
5
|
email?: string;
|
|
5
6
|
index: number;
|
package/dist/plugin/cli.js
CHANGED
|
@@ -11,6 +11,39 @@ export async function promptAddAnotherAccount(currentCount) {
|
|
|
11
11
|
rl.close();
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
export async function promptDeleteAccount(accounts) {
|
|
15
|
+
const rl = createInterface({ input, output });
|
|
16
|
+
try {
|
|
17
|
+
console.log(`\nSelect account to delete:`);
|
|
18
|
+
for (const acc of accounts) {
|
|
19
|
+
const label = acc.email || `Account ${acc.index + 1}`;
|
|
20
|
+
console.log(` ${acc.index + 1}. ${label}`);
|
|
21
|
+
}
|
|
22
|
+
console.log(` 0. Cancel`);
|
|
23
|
+
console.log('');
|
|
24
|
+
while (true) {
|
|
25
|
+
const answer = await rl.question('Enter account number: ');
|
|
26
|
+
const num = parseInt(answer.trim(), 10);
|
|
27
|
+
if (num === 0) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (num >= 1 && num <= accounts.length) {
|
|
31
|
+
const selected = accounts[num - 1];
|
|
32
|
+
const label = selected?.email || `Account ${num}`;
|
|
33
|
+
const confirm = await rl.question(`Delete "${label}"? (y/n): `);
|
|
34
|
+
const normalized = confirm.trim().toLowerCase();
|
|
35
|
+
if (normalized === 'y' || normalized === 'yes') {
|
|
36
|
+
return selected?.index ?? null;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
console.log(`Please enter a number between 0 and ${accounts.length}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
rl.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
14
47
|
export async function promptLoginMode(existingAccounts) {
|
|
15
48
|
const rl = createInterface({ input, output });
|
|
16
49
|
try {
|
|
@@ -21,7 +54,7 @@ export async function promptLoginMode(existingAccounts) {
|
|
|
21
54
|
}
|
|
22
55
|
console.log('');
|
|
23
56
|
while (true) {
|
|
24
|
-
const answer = await rl.question('(a)dd new account(s)
|
|
57
|
+
const answer = await rl.question('(a)dd new account(s), (f)resh start, or (d)elete account? [a/f/d]: ');
|
|
25
58
|
const normalized = answer.trim().toLowerCase();
|
|
26
59
|
if (normalized === 'a' || normalized === 'add') {
|
|
27
60
|
return 'add';
|
|
@@ -29,7 +62,10 @@ export async function promptLoginMode(existingAccounts) {
|
|
|
29
62
|
if (normalized === 'f' || normalized === 'fresh') {
|
|
30
63
|
return 'fresh';
|
|
31
64
|
}
|
|
32
|
-
|
|
65
|
+
if (normalized === 'd' || normalized === 'delete') {
|
|
66
|
+
return 'delete';
|
|
67
|
+
}
|
|
68
|
+
console.log("Please enter 'a' to add accounts, 'f' to start fresh, or 'd' to delete account.");
|
|
33
69
|
}
|
|
34
70
|
}
|
|
35
71
|
finally {
|
package/dist/plugin/models.d.ts
CHANGED
package/dist/plugin/models.js
CHANGED
package/dist/plugin/request.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import type { KiroAuthDetails, PreparedRequest } from './types';
|
|
2
2
|
export declare function transformToCodeWhisperer(url: string, body: any, model: string, auth: KiroAuthDetails, think?: boolean, budget?: number, reductionFactor?: number): PreparedRequest;
|
|
3
|
-
export declare function mergeAdjacentMessages(msgs: any[]): any[];
|
|
4
|
-
export declare function convertToolsToCodeWhisperer(tools: any[]): any[];
|